login-control 0.0.10 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/login_control_module.rb +7 -4
- data/lib/login_control_view_helper.rb +9 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ea0f78366e9c6df5f607dcf3801d2e84fb4fe96d8f1a82f3ef255475882a230
|
4
|
+
data.tar.gz: de45c02638f0e0dc61ea957c0b10e8bf629a49e3052ae230c8cefe2781a0a01e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18264367c3b418af8ae901fbe7afe173b31da25af42fd5ec2ba43493e56f4321ed890fe60fe5fa9277c7b3c9a820fe22f731ed940a172e03dbee3eaadad4266a
|
7
|
+
data.tar.gz: d6191a82cd30050ab721a541a116b9a6649686b3dd9ac62bf2073a91d37af3b724da9b10a190f804ba61fa526b81665587e21bf6cd8ed77a719957c02e05f76d
|
data/lib/login_control_module.rb
CHANGED
@@ -3,7 +3,7 @@ module LoginControlModule
|
|
3
3
|
# check if captcha is to validate (does not store a cookie)
|
4
4
|
def captcha_validation?(scope: :global, login_name: nil)
|
5
5
|
rec = rc_record(scope, login_name)
|
6
|
-
logger.info "
|
6
|
+
logger.info "LoginControlModule => get captcha #{rec&.validate_captcha ? '' : 'NOT '}requested from record LoginControl.#{rec&.id}" if debug_request_control
|
7
7
|
rec ? rec.validate_captcha : true
|
8
8
|
end
|
9
9
|
|
@@ -15,7 +15,7 @@ module LoginControlModule
|
|
15
15
|
rec.last_attempt = DateTime.now
|
16
16
|
rec.attempts = 1
|
17
17
|
rec.save!
|
18
|
-
logger.info "
|
18
|
+
logger.info "LoginControlModule.notice_successful_request => #{rec.sign_in_success}. successful request noticed" if debug_request_control
|
19
19
|
end
|
20
20
|
|
21
21
|
# stores cookie, counts up attempts
|
@@ -25,7 +25,7 @@ module LoginControlModule
|
|
25
25
|
rec.attempts = rec.attempts.to_i + 1
|
26
26
|
rec.last_attempt = DateTime.now
|
27
27
|
rec.save!
|
28
|
-
logger.info "
|
28
|
+
logger.info "LoginControlModule.notice_request_attempt => #{rec.attempts}. request attempt noticed" if debug_request_control
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
@@ -38,6 +38,7 @@ module LoginControlModule
|
|
38
38
|
rc_record(scope, login_name, id: id)
|
39
39
|
else
|
40
40
|
id = SecureRandom.hex(20)
|
41
|
+
logger.info "LoginControlModule.find_or_build_rc_record => created cookie by id: «#{id}»" if debug_request_control
|
41
42
|
cookies.encrypted.permanent[:login_control] = id
|
42
43
|
LoginControl.new(session_id: id, scope: scope, login_name: login_name)
|
43
44
|
end
|
@@ -46,7 +47,9 @@ module LoginControlModule
|
|
46
47
|
# read cookie «login_control»
|
47
48
|
def rc_record(scope, login_name, id: cookies.encrypted.permanent[:login_control])
|
48
49
|
if id
|
49
|
-
LoginControl.find_by(session_id: id, scope: scope, login_name: login_name)
|
50
|
+
lc = LoginControl.find_by(session_id: id, scope: scope, login_name: login_name)
|
51
|
+
logger.info "LoginControlModule.rc_record => #{lc ? '' : 'NOT '}found by session_id: «#{id}» #{lc ? ", record-id: #{lc.id}" : ''}" if debug_request_control
|
52
|
+
lc
|
50
53
|
else
|
51
54
|
nil
|
52
55
|
end
|
@@ -8,38 +8,38 @@ module LoginControlViewHelper
|
|
8
8
|
rc_id = cookies.encrypted.permanent[:login_control]
|
9
9
|
captcha_requested = true
|
10
10
|
if request.host == 'localhost'
|
11
|
-
logger.info '
|
11
|
+
logger.info 'LoginControlViewHelper.captcha_tag? => no captcha because of localhost' if debug
|
12
12
|
captcha_requested = false
|
13
13
|
elsif !rc_id.present?
|
14
|
-
logger.info '
|
14
|
+
logger.info 'LoginControlViewHelper.captcha_tag? => captcha because no cookie stored yet' if debug
|
15
15
|
captcha_requested = true
|
16
16
|
else
|
17
|
-
logger.info '
|
17
|
+
logger.info 'LoginControlViewHelper.captcha_tag? => cookie found ...' if debug
|
18
18
|
rec = LoginControl.find_by(session_id: rc_id, scope: scope, login_name: login_name)
|
19
19
|
if !rec
|
20
|
-
logger.info '
|
20
|
+
logger.info 'LoginControlViewHelper.captcha_tag? => captcha required because no record found(!)' if debug
|
21
21
|
true
|
22
22
|
else
|
23
|
-
logger.info '
|
23
|
+
logger.info 'LoginControlViewHelper.captcha_tag? => record found ...' if debug
|
24
24
|
|
25
25
|
attempts_allowed = (Rails.configuration.x.login_control.attempts_allowed || 10)
|
26
26
|
retry_after_seconds = (Rails.configuration.x.login_control.retry_after_seconds || 30)
|
27
|
-
logger.info "
|
27
|
+
logger.info "LoginControlViewHelper.captcha_tag? => #{rec.attempts.to_i}. attempt (config.x.attempts_allowed: #{attempts_allowed})" if debug
|
28
28
|
|
29
29
|
if rec.attempts == 1
|
30
30
|
captcha_requested = false
|
31
|
-
logger.info "
|
31
|
+
logger.info "LoginControlViewHelper.captcha_tag? => captcha NOT requested: because first attempt after successful login" if debug
|
32
32
|
elsif rec.attempts.to_i <= attempts_allowed
|
33
33
|
secs = Time.now - (rec.last_attempt || Time.now)
|
34
34
|
if secs >= retry_after_seconds.to_f
|
35
35
|
captcha_requested = false
|
36
|
-
logger.info "
|
36
|
+
logger.info "LoginControlViewHelper.captcha_tag? => captcha #{captcha_requested ? '' : 'NOT '}requested: config.x.retry_after_seconds(#{retry_after_seconds}) >= secs(#{secs})" if debug
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
41
41
|
rec.update!(validate_captcha: captcha_requested)
|
42
|
-
logger.info "
|
42
|
+
logger.info "LoginControlViewHelper.captcha_tag? => set captcha #{captcha_requested ? '' : 'NOT '}requested to record LoginControl.#{rec.id}" if debug
|
43
43
|
captcha_requested
|
44
44
|
end
|
45
45
|
end
|