devise-authy 1.5.1 → 1.5.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
  SHA1:
3
- metadata.gz: 2d1a239f49125b1e63f5e269e371263dc3da1046
4
- data.tar.gz: 6d67001f8d3deeb8a7370768243cac7b5a92c894
3
+ metadata.gz: 8ae1f6fbc203862085abd304cc928dfee2fd2dda
4
+ data.tar.gz: ed576398d4d571f5dec9d4f646d4736a5cb688d2
5
5
  SHA512:
6
- metadata.gz: bc6c98a66a53d2260b0e040a324767e5729c16a0615b29a8e7e3702ce49e49428cdb74b20db01b7f25b5c8571fe2d16b21090597a58a8348e58e563c72b1d59c
7
- data.tar.gz: a34fa44e54df3c509104e6467c2af04ddad6d004dd47969b69004f307744f93dd59a5c25b865524af05f300d85840a98bcb1d8f398827e60d7fc3fdfd499af5f
6
+ metadata.gz: aff8716fb178b1bccf6c81a1cd8f0edca118cbd2e385ace47b27568d89f5b2d81f4b3f7ea7c8adcc15298267a332221da5bff0be102bb1b0425116d03653209e
7
+ data.tar.gz: 613afb26bd7b9056379892a2659577a9cd812196e3d2395375210d99882b3c0f0004e52cd84dd8fb7e9a00819803aa752d022ec1baff4cd548cffbc37885442e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.1
1
+ 1.5.2
@@ -7,7 +7,8 @@ class Devise::DeviseAuthyController < DeviseController
7
7
  ]
8
8
  prepend_before_filter :authenticate_scope!, :only => [
9
9
  :GET_enable_authy, :POST_enable_authy,
10
- :GET_verify_authy_installation, :POST_verify_authy_installation
10
+ :GET_verify_authy_installation, :POST_verify_authy_installation,
11
+ :POST_disable_authy
11
12
  ]
12
13
  include Devise::Controllers::Helpers
13
14
 
@@ -74,6 +75,20 @@ class Devise::DeviseAuthyController < DeviseController
74
75
  end
75
76
  end
76
77
 
78
+ # Disable 2FA
79
+ def POST_disable_authy
80
+ resource.authy_enabled = false
81
+ resource.authy_id = nil
82
+
83
+ if resource.save
84
+ set_flash_message(:notice, :disabled)
85
+ else
86
+ set_flash_message(:error, :not_disabled)
87
+ end
88
+
89
+ redirect_to root_path
90
+ end
91
+
77
92
  def GET_verify_authy_installation
78
93
  render :verify_authy_installation
79
94
  end
@@ -0,0 +1,12 @@
1
+ class DeviseAuthy::PasswordsController < Devise::PasswordsController
2
+ def sign_in(resource_or_scope, *args)
3
+ resource = args.last || resource_or_scope
4
+
5
+ if resource.with_authy_authentication?(request)
6
+ # Do nothing. Because we need verify the 2FA
7
+ true
8
+ else
9
+ super
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,10 @@
1
1
  <h1>Welcome#index</h1>
2
2
  <p>Find me in app/views/welcome/index.html.erb</p>
3
3
 
4
- <%= link_to "Enable authy", user_enable_authy_path %>
4
+ <% if current_user.authy_enabled %>
5
+ <%= link_to "Disable authy", user_disable_authy_path, :method => :post %>
6
+ <% else %>
7
+ <%= link_to "Enable authy", user_enable_authy_path %>
8
+ <% end %>
9
+
5
10
  <%= link_to "Logout", destroy_user_session_path, :method => :delete %>
@@ -34,4 +34,6 @@ AuthyDeviseDemo::Application.configure do
34
34
 
35
35
  # Expands the lines which load the assets
36
36
  config.assets.debug = true
37
+
38
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
37
39
  end
@@ -16,6 +16,8 @@ en:
16
16
  user:
17
17
  enabled: 'Two factor authentication was enabled'
18
18
  not_enabled: 'Something went wrong while enabling two factor authentication'
19
+ disabled: 'Two factor authentication was disabled'
20
+ not_disabled: 'Something went wrong while disabling two factor authentication'
19
21
  signed_in: 'Signed in with Authy successfully.'
20
22
  already_enabled: "Two factor authentication is already enabled."
21
23
  invalid_token: 'The entered token is invalid'
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: devise-authy 1.5.1 ruby lib
5
+ # stub: devise-authy 1.5.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "devise-authy"
9
- s.version = "1.5.1"
9
+ s.version = "1.5.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Authy Inc."]
14
- s.date = "2014-04-17"
14
+ s.date = "2014-06-10"
15
15
  s.description = "Authy plugin for Devise"
16
16
  s.email = "support@authy.com"
17
17
  s.extra_rdoc_files = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "app/assets/stylesheets/devise_authy.css",
32
32
  "app/assets/stylesheets/devise_authy.sass",
33
33
  "app/controllers/devise/devise_authy_controller.rb",
34
+ "app/controllers/devise_authy/passwords_controller.rb",
34
35
  "app/views/devise/enable_authy.html.erb",
35
36
  "app/views/devise/enable_authy.html.haml",
36
37
  "app/views/devise/verify_authy.html.erb",
@@ -113,6 +114,7 @@ Gem::Specification.new do |s|
113
114
  "lib/devise-authy/controllers/helpers.rb",
114
115
  "lib/devise-authy/controllers/view_helpers.rb",
115
116
  "lib/devise-authy/hooks/authy_authenticatable.rb",
117
+ "lib/devise-authy/mapping.rb",
116
118
  "lib/devise-authy/models/authy_authenticatable.rb",
117
119
  "lib/devise-authy/rails.rb",
118
120
  "lib/devise-authy/routes.rb",
@@ -121,6 +123,7 @@ Gem::Specification.new do |s|
121
123
  "lib/generators/devise_authy/devise_authy_generator.rb",
122
124
  "lib/generators/devise_authy/install_generator.rb",
123
125
  "spec/controllers/devise_authy_controller_spec.rb",
126
+ "spec/controllers/passwords_controller_spec.rb",
124
127
  "spec/features/authy_authenticatable_spec.rb",
125
128
  "spec/generators_spec.rb",
126
129
  "spec/models/authy_authenticatable.rb",
@@ -1,6 +1,5 @@
1
1
  require 'active_support/concern'
2
2
  require 'active_support/core_ext/integer/time'
3
- require 'devise'
4
3
  require 'authy'
5
4
 
6
5
  module Devise
@@ -8,17 +7,23 @@ module Devise
8
7
  @@authy_remember_device = 1.month
9
8
  end
10
9
 
10
+ require 'devise'
11
+ require 'devise-authy/routes'
12
+ require 'devise-authy/rails'
13
+
11
14
  module DeviseAuthy
15
+ autoload :Mapping, 'devise-authy/mapping'
16
+
12
17
  module Controllers
18
+ autoload :Passwords, 'devise-authy/controllers/passwords'
13
19
  autoload :Helpers, 'devise-authy/controllers/helpers'
14
20
  end
21
+
15
22
  module Views
16
23
  autoload :Helpers, 'devise-authy/controllers/view_helpers'
17
24
  end
18
25
  end
19
26
 
20
- require 'devise-authy/routes'
21
- require 'devise-authy/rails'
22
27
  require 'devise-authy/models/authy_authenticatable'
23
28
 
24
29
  Devise.add_module :authy_authenticatable, :model => 'devise-authy/models/authy_authenticatable', :controller => :devise_authy, :route => :authy
@@ -61,9 +61,8 @@ module DeviseAuthy
61
61
 
62
62
  def verify_authy_path_for(resource_or_scope = nil)
63
63
  scope = Devise::Mapping.find_scope!(resource_or_scope)
64
- send("#{scope}_verify_authy_path")
64
+ send(:"#{scope}_verify_authy_path")
65
65
  end
66
66
  end
67
67
  end
68
- end
69
-
68
+ end
@@ -0,0 +1,14 @@
1
+ module DeviseAuthy
2
+ module Mapping
3
+ def self.included(base)
4
+ base.alias_method_chain :default_controllers, :authy_authenticatable
5
+ end
6
+
7
+ private
8
+ def default_controllers_with_authy_authenticatable(options)
9
+ options[:controllers] ||= {}
10
+ options[:controllers][:passwords] ||= "devise_authy/passwords"
11
+ default_controllers_without_authy_authenticatable(options)
12
+ end
13
+ end
14
+ end
@@ -6,6 +6,11 @@ module DeviseAuthy
6
6
  ActiveSupport.on_load(:action_view) do
7
7
  include DeviseAuthy::Views::Helpers
8
8
  end
9
+
10
+ # extend mapping with after_initialize because it's not reloaded
11
+ config.after_initialize do
12
+ Devise::Mapping.send :include, DeviseAuthy::Mapping
13
+ end
9
14
  end
10
15
  end
11
16
 
@@ -9,6 +9,8 @@ module ActionDispatch::Routing
9
9
  match "/#{mapping.path_names[:enable_authy]}", :controller => controllers[:devise_authy], :action => :GET_enable_authy, :as => :enable_authy, :via => :get
10
10
  match "/#{mapping.path_names[:enable_authy]}", :controller => controllers[:devise_authy], :action => :POST_enable_authy, :as => nil, :via => :post
11
11
 
12
+ match "/#{mapping.path_names[:disable_authy]}", :controller => controllers[:devise_authy], :action => :POST_disable_authy, :as => :disable_authy, :via => :post
13
+
12
14
  match "/#{mapping.path_names[:verify_authy_installation]}", :controller => controllers[:devise_authy], :action => :GET_verify_authy_installation, :as => :verify_authy_installation, :via => :get
13
15
  match "/#{mapping.path_names[:verify_authy_installation]}", :controller => controllers[:devise_authy], :action => :POST_verify_authy_installation, :as => nil, :via => :post
14
16
 
@@ -6,7 +6,7 @@ module ActiveRecord
6
6
  source_root File.expand_path("../templates", __FILE__)
7
7
 
8
8
  def copy_devise_migration
9
- migration_template "migration.rb", "db/migrate/devise_authy_add_to_#{table_name}"
9
+ migration_template "migration.rb", "db/migrate/devise_authy_add_to_#{table_name}.rb"
10
10
  end
11
11
  end
12
12
  end
@@ -119,6 +119,40 @@ describe Devise::DeviseAuthyController do
119
119
  end
120
120
  end
121
121
 
122
+ describe "POST #disable_authy" do
123
+ it "Should disable 2FA" do
124
+ sign_in @user
125
+ @user.authy_enabled = true
126
+ @user.save
127
+
128
+ post :POST_disable_authy
129
+ @user.reload
130
+ @user.authy_id.should be_nil
131
+ @user.authy_enabled.should be_false
132
+ flash.now[:notice].should == "Two factor authentication was disabled"
133
+ response.should redirect_to(root_url)
134
+ end
135
+
136
+ it "Should not disable 2FA" do
137
+ sign_in @user
138
+ @user.authy_enabled = true
139
+ @user.save
140
+
141
+ User.any_instance.stub(:save).and_return(false)
142
+
143
+ post :POST_disable_authy
144
+ @user.reload
145
+ @user.authy_id.should_not be_nil
146
+ @user.authy_enabled.should be_true
147
+ flash[:error].should == "Something went wrong while disabling two factor authentication"
148
+ end
149
+
150
+ it "Should redirect if user isn't authenticated" do
151
+ post :POST_disable_authy
152
+ response.should redirect_to(new_user_session_url)
153
+ end
154
+ end
155
+
122
156
  describe "GET #verify_authy_installation" do
123
157
  it "Should render the authy installation page" do
124
158
  sign_in @user
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe DeviseAuthy::PasswordsController do
4
+ include Devise::TestHelpers
5
+
6
+ before :each do
7
+ request.env["devise.mapping"] = Devise.mappings[:user]
8
+ end
9
+
10
+ context "when the user has authy enabled" do
11
+
12
+ describe "Reset password" do
13
+ it "Should redirect to verify token view" do
14
+ user = create_user(:authy_id => 1)
15
+ user.reset_password_token = User.reset_password_token
16
+ user.reset_password_sent_at = Time.now.utc
17
+ user.authy_enabled = true
18
+ user.save
19
+
20
+ put :update, :user => { :reset_password_token => user.reset_password_token, :password => "password", :password_confirmation => "password" }
21
+
22
+ user.reload
23
+ user.last_sign_in_at.should be_nil
24
+ response.should redirect_to(root_url)
25
+ end
26
+ end
27
+ end
28
+
29
+ context "when the user don't have 2FA" do
30
+ describe "Reset password" do
31
+ it "Should sign in the user" do
32
+ user = create_user
33
+ user.reset_password_token = User.reset_password_token
34
+ user.reset_password_sent_at = Time.now.utc
35
+ user.save
36
+
37
+ last_sign_in_at = user.last_sign_in_at
38
+
39
+ put :update, :user => { :reset_password_token => user.reset_password_token, :password => "password", :password_confirmation => "password" }
40
+ response.should redirect_to(root_url)
41
+
42
+ user.reload
43
+ user.last_sign_in_at.should_not be_nil
44
+ flash[:notice].should == "Your password was changed successfully. You are now signed in."
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- devise-authy (1.5.1)
4
+ devise-authy (1.5.2)
5
5
  authy
6
6
  devise
7
7
 
@@ -34,4 +34,6 @@ RailsApp::Application.configure do
34
34
 
35
35
  # Print deprecation notices to the stderr
36
36
  config.active_support.deprecation = :stderr
37
+
38
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
37
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise-authy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Authy Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -184,6 +184,7 @@ files:
184
184
  - app/assets/stylesheets/devise_authy.css
185
185
  - app/assets/stylesheets/devise_authy.sass
186
186
  - app/controllers/devise/devise_authy_controller.rb
187
+ - app/controllers/devise_authy/passwords_controller.rb
187
188
  - app/views/devise/enable_authy.html.erb
188
189
  - app/views/devise/enable_authy.html.haml
189
190
  - app/views/devise/verify_authy.html.erb
@@ -266,6 +267,7 @@ files:
266
267
  - lib/devise-authy/controllers/helpers.rb
267
268
  - lib/devise-authy/controllers/view_helpers.rb
268
269
  - lib/devise-authy/hooks/authy_authenticatable.rb
270
+ - lib/devise-authy/mapping.rb
269
271
  - lib/devise-authy/models/authy_authenticatable.rb
270
272
  - lib/devise-authy/rails.rb
271
273
  - lib/devise-authy/routes.rb
@@ -274,6 +276,7 @@ files:
274
276
  - lib/generators/devise_authy/devise_authy_generator.rb
275
277
  - lib/generators/devise_authy/install_generator.rb
276
278
  - spec/controllers/devise_authy_controller_spec.rb
279
+ - spec/controllers/passwords_controller_spec.rb
277
280
  - spec/features/authy_authenticatable_spec.rb
278
281
  - spec/generators_spec.rb
279
282
  - spec/models/authy_authenticatable.rb