2fa 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 581baafb237e2897facab0f9d6a21a5ce8ed2be2f0f32fd85d2b16de58d32e1c
4
- data.tar.gz: e9fa994ebf0cf2d2b6cd9b97859e28e90147e4fc3e62d47650855e2b27437dba
3
+ metadata.gz: 38c6ee1d02fd641ab961cd51780f30d11b4596c344a1a076fce5d0c1687a679b
4
+ data.tar.gz: 39087b415fb04ea9049cb5721e8e1117975f005de5411dddfd366d6e557aa789
5
5
  SHA512:
6
- metadata.gz: 2182301e7efb89cb639a00a4e8038854dc5d59d30996be2bb18c18f9279f3da1793da6a86fca6dd81bead89be94b69a71f09d1396479ca6abff26be6ff0aeeaf
7
- data.tar.gz: cb81b21b6a96dd7759e03779c1d067d3c0e28b31fe35e8732e99f7fbe5931699057954d085168573f388c89ba1bea950466ba03801806b7a5f3aeace65fcc8ad
6
+ metadata.gz: 5795911bb57902b834af94f9181b27e60401082a54d2b53b59db0ba4acaa4fab5b22e2030dc44c9952bd7a955f782797ce92e54c423c8178d9c6ce1a65f92dae
7
+ data.tar.gz: 03b4ca5e1a4128f5353083258af7a8b20e459f06270e4974488a004ef6721cf9bd0611573669faf477f68aece0d2ccd2635ab0040ef64c7cbe8e4e6fd49fec95
data/2fa-0.0.1.gem ADDED
Binary file
@@ -29,8 +29,12 @@ module TFA
29
29
  controller.redirect_to Engine.routes.url_helpers.tfa_verify_path(@tfa)
30
30
  end
31
31
 
32
- def if_tfa(&block)
33
- if params[:tfa_id] && Tfa.find_by(id: params[:tfa_id]).code.to_s == params[:code].to_s && !Tfa.find_by(id: params[:tfa_id]).used
32
+ def tfa_valid(expected_phone:nil)
33
+ params[:tfa_id] && Tfa.find_by(id: params[:tfa_id]).code.to_s == params[:code].to_s && !Tfa.find_by(id: params[:tfa_id]).used && (Tfa.find_by(id: params[:tfa_id]).phone == expected_phone || expected_phone == nil)
34
+ end
35
+
36
+ def if_tfa(expected_phone:nil, &block)
37
+ if tfa_valid(expected_phone: expected_phone)
34
38
  @tfa = Tfa.find_by(id: params[:tfa_id])
35
39
  @tfa.used = true
36
40
  @tfa.save
@@ -39,10 +43,8 @@ module TFA
39
43
  end
40
44
  end
41
45
 
42
- def no_tfa(&block)
43
- if !params[:tfa_id]
44
- block.call
45
- elsif Tfa.find_by(id: params[:tfa_id]).code.to_s != params[:code].to_s
46
+ def no_tfa(expected_phone:nil, &block)
47
+ if !tfa_valid(expected_phone: expected_phone)
46
48
  block.call
47
49
  end
48
50
  end
data/lib/TFA/version.rb CHANGED
@@ -2,7 +2,7 @@ module TFA
2
2
  @@version = {
3
3
  major: 0,
4
4
  minor: 0,
5
- patch: 1,
5
+ patch: 2,
6
6
  extra: [
7
7
  ]
8
8
  }
data/readme.md CHANGED
@@ -33,7 +33,7 @@ def create
33
33
  end
34
34
 
35
35
  helpers.if_tfa do
36
- @example = example.new(example_params)
36
+ @example = Example.new(example_params)
37
37
 
38
38
  respond_to do |format|
39
39
  if @example.save
@@ -49,14 +49,10 @@ end
49
49
  ```
50
50
  This is just a default scaffolded controller but with tfa auth.
51
51
 
52
- This isn't perfect as in theory someone could pass a different unused tfa by inspecting the form, so to prevent this, you can take in a `|tfa|` argument from the helper to verify that the tfa has the correct phone number.
52
+ This isn't perfect as in theory someone could pass a different unused tfa by inspecting the form, so to prevent this, you can pass a `expected_phone: ` argument to `no_tfa` or `if_tfa` to add that requirement.
53
53
  ```rb
54
- helpers.if_tfa do |tfa|
55
- if tfa.phone == @user.phone
56
- #...your code here
57
- else
58
- head 401
59
- end
54
+ helpers.if_tfa(expected_phone: @user.phone) do
55
+ #...
60
56
  end
61
57
  ```
62
58
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 2fa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-07 00:00:00.000000000 Z
11
+ date: 2022-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twilio-ruby
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - 2fa-0.0.1.gem
48
49
  - 2fa.gemspec
49
50
  - app/controllers/tfa/tfas_controller.rb
50
51
  - app/helpers/tfa/tfa_helper.rb