Module: LoginControlModule

Defined in:
lib/login_control_module.rb

Instance Method Summary collapse

Instance Method Details

#captcha_validation?(scope: :global, login_name: nil) ⇒ Boolean

check if captcha is to validate (does not store a cookie)

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/login_control_module.rb', line 4

def captcha_validation?(scope: :global, login_name: nil)
  rec = rc_record(scope, )
  if request.host == 'localhost'
    logger.info "LoginControlModule.captcha_validation? => captcha NOT requested because localhost" if debug_request_control
    false
  elsif Rails.env.development? || Rails.env == 'test'
    logger.info "LoginControlModule.captcha_validation? => captcha NOT requested because Rails.env #{Rails.env}" if debug_request_control
    false
  elsif rec
    logger.info "LoginControlModule.captcha_validation? => get captcha #{rec&.validate_captcha ? '' : 'NOT '}requested from record LoginControl.#{rec&.id}" if debug_request_control
    rec.validate_captcha
  else
    logger.info "LoginControlModule.captcha_validation? => get captcha requested (all other conditions failed)" if debug_request_control
    true
  end
end

#notice_login_attempt(scope: :global, login_name: nil) ⇒ Object

stores cookie, counts up attempts



34
35
36
37
38
39
40
# File 'lib/login_control_module.rb', line 34

def (scope: :global, login_name: nil)
  rec = find_or_build_rc_record(scope, )
  rec.attempts = rec.attempts.to_i + 1
  rec.last_attempt = DateTime.now
  rec.save!
  logger.info "LoginControlModule.notice_login_attempt => #{rec.attempts}. request attempt noticed" if debug_request_control
end

#notice_successful_login(scope: :global, login_name: nil) ⇒ Object

stores cookie, count-up sign_in_success, set attempts count to 1



23
24
25
26
27
28
29
30
# File 'lib/login_control_module.rb', line 23

def (scope: :global, login_name: nil)
  rec = find_or_build_rc_record(scope, )
  rec. = rec..to_i + 1
  rec.last_attempt = DateTime.now
  rec.attempts = 1
  rec.save!
  logger.info "LoginControlModule.notice_successful_login => #{rec.}. successful request noticed" if debug_request_control
end