login-control 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/login_control_module.rb +13 -12
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8a0041b25da378a40ee536b9689846301d6b13eb062f2001fae995a78540094
4
- data.tar.gz: b40069097f5b5d8e3bf2025ae63a1b3e88c4adb8a1e07c2771aa389aba4a8941
3
+ metadata.gz: ce0349a1a1a35c95a6e7c8a785381d5980f7210b843ffe02affb38550f569324
4
+ data.tar.gz: '03418d27ae73c03534f53e20d6a5720a7d178b25720df4580caded35fc147b19'
5
5
  SHA512:
6
- metadata.gz: 130e57bb3dc647f3785c3e1dc295e1ecc57f50359579cc516ca2b1b1ce80adc152200071bd0394e20508910b91e575769b37a076e56cec23f9c6860867a66c76
7
- data.tar.gz: 7fa194e79c11dc09897c99412d26d3b9c16f902349e931d1f8f27ce2404262f060ed115e0cc9a4f0ab2f44b7db3d6a1afaf766f888a8c24287b973f9812828bb
6
+ metadata.gz: d1bd1d46ae7502dbf3ef87dd0e322a7e79e4319b6066c2885a9ad1e5025c1ebfd00329d1f1b357cea86e36dcb55a97434d8406c6387879b4c079907fcb08116f
7
+ data.tar.gz: 3de764c9fd8a9474afdec5548f407d8bab24d55fd47b9c1364c0271d4bc6251831d33c47505f0f1a70561ef30e43320e4150d272f7839c674c269c66b3265705
data/README.md CHANGED
@@ -16,7 +16,7 @@ On localhost captcha is never required.
16
16
 
17
17
  ## Installation
18
18
 
19
- `gem 'request-control'`
19
+ `gem 'login-control'`
20
20
 
21
21
  run
22
22
  ```
@@ -50,10 +50,10 @@ class SessionsController < Devise::SessionsController
50
50
  include LoginControlModule
51
51
 
52
52
  def create
53
- notice_request_attempt
53
+ notice_login_attempt
54
54
  if (captcha_validation? ? verify_hcaptcha(secret_key: ...) : true) && credentials-matched
55
55
  super
56
- notice_successful_request
56
+ notice_successful_login
57
57
  else
58
58
  redirect_to login_path, alert: 'captcha failed'
59
59
  end
@@ -4,39 +4,39 @@ module LoginControlModule
4
4
  def captcha_validation?(scope: :global, login_name: nil)
5
5
  rec = rc_record(scope, login_name)
6
6
  if request.host == 'localhost'
7
- logger.info "LoginControlModule => get captcha NOT requested because localhost" if debug_request_control
7
+ logger.info "LoginControlModule.captcha_validation? => captcha NOT requested because localhost" if debug_request_control
8
8
  false
9
9
  elsif Rails.env.development? || Rails.env == 'test'
10
- logger.info "LoginControlModule => get captcha NOT requested because Rails.env #{Rails.env}" if debug_request_control
10
+ logger.info "LoginControlModule.captcha_validation? => captcha NOT requested because Rails.env #{Rails.env}" if debug_request_control
11
11
  false
12
12
  elsif rec
13
- logger.info "LoginControlModule => get captcha #{rec&.validate_captcha ? '' : 'NOT '}requested from record LoginControl.#{rec&.id}" if debug_request_control
13
+ logger.info "LoginControlModule.captcha_validation? => get captcha #{rec&.validate_captcha ? '' : 'NOT '}requested from record LoginControl.#{rec&.id}" if debug_request_control
14
14
  rec.validate_captcha
15
15
  else
16
- logger.info "LoginControlModule => get captcha requested (all other conditions failed)" if debug_request_control
16
+ logger.info "LoginControlModule.captcha_validation? => get captcha requested (all other conditions failed)" if debug_request_control
17
17
  true
18
18
  end
19
19
  end
20
20
 
21
21
  # stores cookie, count-up sign_in_success, set attempts count to 1
22
22
 
23
- def notice_successful_request(scope: :global, login_name: nil)
23
+ def notice_successful_login(scope: :global, login_name: nil)
24
24
  rec = find_or_build_rc_record(scope, login_name)
25
25
  rec.sign_in_success = rec.sign_in_success.to_i + 1
26
26
  rec.last_attempt = DateTime.now
27
27
  rec.attempts = 1
28
28
  rec.save!
29
- logger.info "LoginControlModule.notice_successful_request => #{rec.sign_in_success}. successful request noticed" if debug_request_control
29
+ logger.info "LoginControlModule.notice_successful_login => #{rec.sign_in_success}. successful request noticed" if debug_request_control
30
30
  end
31
31
 
32
32
  # stores cookie, counts up attempts
33
33
 
34
- def notice_request_attempt(scope: :global, login_name: nil)
34
+ def notice_login_attempt(scope: :global, login_name: nil)
35
35
  rec = find_or_build_rc_record(scope, login_name)
36
36
  rec.attempts = rec.attempts.to_i + 1
37
37
  rec.last_attempt = DateTime.now
38
38
  rec.save!
39
- logger.info "LoginControlModule.notice_request_attempt => #{rec.attempts}. request attempt noticed" if debug_request_control
39
+ logger.info "LoginControlModule.notice_login_attempt => #{rec.attempts}. request attempt noticed" if debug_request_control
40
40
  end
41
41
 
42
42
  private
@@ -45,14 +45,15 @@ module LoginControlModule
45
45
 
46
46
  def find_or_build_rc_record(scope, login_name)
47
47
  id = cookies.encrypted.permanent[:login_control]
48
- if id.present?
49
- rc_record(scope, login_name, id: id)
50
- else
48
+ res = nil
49
+ res = rc_record(scope, login_name, id: id) if id.present?
50
+ unless res
51
51
  id = SecureRandom.hex(20)
52
52
  logger.info "LoginControlModule.find_or_build_rc_record => created cookie by id: «#{id}»" if debug_request_control
53
53
  cookies.encrypted.permanent[:login_control] = id
54
- LoginControl.new(session_id: id, scope: scope, login_name: login_name, validate_captcha: true)
54
+ res = LoginControl.new(session_id: id, scope: scope, login_name: login_name, validate_captcha: true)
55
55
  end
56
+ res
56
57
  end
57
58
 
58
59
  # read cookie «login_control»
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: login-control
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-27 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Based on Login Attempts check if captcha is necessary. It stores a permanent
14
14
  cookie and uses a table for tracking login requests.
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  requirements: []
42
- rubygems_version: 3.3.17
42
+ rubygems_version: 3.4.12
43
43
  signing_key:
44
44
  specification_version: 4
45
45
  summary: Lib for simplifying and securing login.