devise-2fa 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.hound.yml +2 -0
  4. data/.ruby-style.yml +1248 -0
  5. data/.travis.yml +28 -0
  6. data/Gemfile +25 -0
  7. data/LICENSE +21 -0
  8. data/README.md +130 -0
  9. data/Rakefile +41 -0
  10. data/app/controllers/devise/credentials_controller.rb +100 -0
  11. data/app/controllers/devise/tokens_controller.rb +99 -0
  12. data/app/views/devise/credentials/refresh.html.erb +20 -0
  13. data/app/views/devise/credentials/show.html.erb +23 -0
  14. data/app/views/devise/tokens/_token_secret.html.erb +19 -0
  15. data/app/views/devise/tokens/_trusted_devices.html.erb +10 -0
  16. data/app/views/devise/tokens/recovery.html.erb +21 -0
  17. data/app/views/devise/tokens/recovery_codes.text.erb +3 -0
  18. data/app/views/devise/tokens/show.html.erb +19 -0
  19. data/config/locales/en.yml +57 -0
  20. data/devise-2fa.gemspec +27 -0
  21. data/lib/devise-2fa.rb +74 -0
  22. data/lib/devise-2fa/version.rb +5 -0
  23. data/lib/devise_two_factorable/controllers/helpers.rb +136 -0
  24. data/lib/devise_two_factorable/controllers/url_helpers.rb +30 -0
  25. data/lib/devise_two_factorable/engine.rb +22 -0
  26. data/lib/devise_two_factorable/helpers.rb +136 -0
  27. data/lib/devise_two_factorable/hooks.rb +11 -0
  28. data/lib/devise_two_factorable/hooks/sessions.rb +49 -0
  29. data/lib/devise_two_factorable/mapping.rb +12 -0
  30. data/lib/devise_two_factorable/models/two_factorable.rb +131 -0
  31. data/lib/devise_two_factorable/routes.rb +26 -0
  32. data/lib/devise_two_factorable/two_factorable.rb +131 -0
  33. data/lib/generators/active_record/devise_two_factor_generator.rb +32 -0
  34. data/lib/generators/active_record/templates/migration.rb +27 -0
  35. data/lib/generators/devise_two_factor/devise_two_factor_generator.rb +16 -0
  36. data/lib/generators/devise_two_factor/install_generator.rb +52 -0
  37. data/lib/generators/devise_two_factor/views_generator.rb +19 -0
  38. data/lib/generators/mongoid/devise_two_factor_generator.rb +34 -0
  39. data/test/dummy/README.rdoc +261 -0
  40. data/test/dummy/Rakefile +7 -0
  41. data/test/dummy/app/assets/javascripts/application.js +13 -0
  42. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  43. data/test/dummy/app/controllers/application_controller.rb +4 -0
  44. data/test/dummy/app/controllers/posts_controller.rb +83 -0
  45. data/test/dummy/app/helpers/application_helper.rb +2 -0
  46. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  47. data/test/dummy/app/mailers/.gitkeep +0 -0
  48. data/test/dummy/app/models/post.rb +2 -0
  49. data/test/dummy/app/models/user.rb +20 -0
  50. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/test/dummy/app/views/posts/_form.html.erb +25 -0
  52. data/test/dummy/app/views/posts/edit.html.erb +6 -0
  53. data/test/dummy/app/views/posts/index.html.erb +25 -0
  54. data/test/dummy/app/views/posts/new.html.erb +5 -0
  55. data/test/dummy/app/views/posts/show.html.erb +15 -0
  56. data/test/dummy/config.ru +4 -0
  57. data/test/dummy/config/application.rb +67 -0
  58. data/test/dummy/config/boot.rb +10 -0
  59. data/test/dummy/config/database.yml +25 -0
  60. data/test/dummy/config/environment.rb +5 -0
  61. data/test/dummy/config/environments/development.rb +37 -0
  62. data/test/dummy/config/environments/production.rb +73 -0
  63. data/test/dummy/config/environments/test.rb +36 -0
  64. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  65. data/test/dummy/config/initializers/devise.rb +251 -0
  66. data/test/dummy/config/initializers/inflections.rb +15 -0
  67. data/test/dummy/config/initializers/mime_types.rb +5 -0
  68. data/test/dummy/config/initializers/secret_token.rb +8 -0
  69. data/test/dummy/config/initializers/session_store.rb +8 -0
  70. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  71. data/test/dummy/config/locales/en.yml +5 -0
  72. data/test/dummy/config/routes.rb +6 -0
  73. data/test/dummy/db/migrate/20130125101430_create_users.rb +9 -0
  74. data/test/dummy/db/migrate/20130131092406_add_devise_to_users.rb +52 -0
  75. data/test/dummy/db/migrate/20130131142320_create_posts.rb +10 -0
  76. data/test/dummy/db/migrate/20130131160351_devise_otp_add_to_users.rb +28 -0
  77. data/test/dummy/lib/assets/.gitkeep +0 -0
  78. data/test/dummy/public/404.html +26 -0
  79. data/test/dummy/public/422.html +26 -0
  80. data/test/dummy/public/500.html +25 -0
  81. data/test/dummy/public/favicon.ico +0 -0
  82. data/test/dummy/script/rails +6 -0
  83. data/test/integration/persistence_test.rb +63 -0
  84. data/test/integration/refresh_test.rb +103 -0
  85. data/test/integration/sign_in_test.rb +85 -0
  86. data/test/integration/token_test.rb +30 -0
  87. data/test/integration_tests_helper.rb +64 -0
  88. data/test/model_tests_helper.rb +20 -0
  89. data/test/models/two_factorable_test.rb +120 -0
  90. data/test/orm/active_record.rb +4 -0
  91. data/test/orm/mongoid.rb +13 -0
  92. data/test/support/mongoid.yml +6 -0
  93. data/test/support/symmetric_encryption.yml +70 -0
  94. data/test/test_helper.rb +18 -0
  95. metadata +269 -0
@@ -0,0 +1,36 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static asset server for tests with Cache-Control for performance
16
+ config.serve_static_assets = true
17
+ config.static_cache_control = 'public, max-age=3600'
18
+
19
+ # Show full error reports and disable caching
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Tell Action Mailer not to deliver emails to the real world.
30
+ # The :test delivery method accumulates sent emails in the
31
+ # ActionMailer::Base.deliveries array.
32
+ config.action_mailer.delivery_method = :test
33
+
34
+ # Print deprecation notices to the stderr
35
+ config.active_support.deprecation = :stderr
36
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,251 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth.
2
+ # Many of these configuration options can be set straight in your model.
3
+ Devise.setup do |config|
4
+ config.secret_key = '638da6a325f1de9038321504c4a06ef7f4f7f835331a63ba41b93732b3830d032b6a10b38afa67427e050b19f9717b1e7a45f650ac5631c53cc9dd85264fdfb0'
5
+
6
+ # ==> Mailer Configuration
7
+ # Configure the e-mail address which will be shown in Devise::Mailer,
8
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
9
+ config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
10
+
11
+ # Configure the class responsible to send e-mails.
12
+ # config.mailer = "Devise::Mailer"
13
+
14
+ # ==> ORM configuration
15
+ # Load and configure the ORM. Supports :active_record (default) and
16
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
17
+ # available as additional gems.
18
+ require 'devise/orm/active_record'
19
+
20
+ # ==> Configuration for any authentication mechanism
21
+ # Configure which keys are used when authenticating a user. The default is
22
+ # just :email. You can configure it to use [:username, :subdomain], so for
23
+ # authenticating a user, both parameters are required. Remember that those
24
+ # parameters are used only when authenticating and not when retrieving from
25
+ # session. If you need permissions, you should implement that in a before filter.
26
+ # You can also supply a hash where the value is a boolean determining whether
27
+ # or not authentication should be aborted when the value is not present.
28
+ # config.authentication_keys = [ :email ]
29
+
30
+ # Configure parameters from the request object used for authentication. Each entry
31
+ # given should be a request method and it will automatically be passed to the
32
+ # find_for_authentication method and considered in your model lookup. For instance,
33
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
34
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
35
+ # config.request_keys = []
36
+
37
+ # Configure which authentication keys should be case-insensitive.
38
+ # These keys will be downcased upon creating or modifying a user and when used
39
+ # to authenticate or find a user. Default is :email.
40
+ config.case_insensitive_keys = [:email]
41
+
42
+ # Configure which authentication keys should have whitespace stripped.
43
+ # These keys will have whitespace before and after removed upon creating or
44
+ # modifying a user and when used to authenticate or find a user. Default is :email.
45
+ config.strip_whitespace_keys = [:email]
46
+
47
+ # Tell if authentication through request.params is enabled. True by default.
48
+ # It can be set to an array that will enable params authentication only for the
49
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
50
+ # enable it only for database (email + password) authentication.
51
+ # config.params_authenticatable = true
52
+
53
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
54
+ # It can be set to an array that will enable http authentication only for the
55
+ # given strategies, for example, `config.http_authenticatable = [:token]` will
56
+ # enable it only for token authentication.
57
+ # config.http_authenticatable = false
58
+
59
+ # If http headers should be returned for AJAX requests. True by default.
60
+ # config.http_authenticatable_on_xhr = true
61
+
62
+ # The realm used in Http Basic Authentication. "Application" by default.
63
+ # config.http_authentication_realm = "Application"
64
+
65
+ # It will change confirmation, password recovery and other workflows
66
+ # to behave the same regardless if the e-mail provided was right or wrong.
67
+ # Does not affect registerable.
68
+ # config.paranoid = true
69
+
70
+ # By default Devise will store the user in session. You can skip storage for
71
+ # :http_auth and :token_auth by adding those symbols to the array below.
72
+ # Notice that if you are skipping storage for all authentication paths, you
73
+ # may want to disable generating routes to Devise's sessions controller by
74
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
75
+ config.skip_session_storage = [:http_auth]
76
+
77
+ # ==> Configuration for :database_authenticatable
78
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
79
+ # using other encryptors, it sets how many times you want the password re-encrypted.
80
+ #
81
+ # Limiting the stretches to just one in testing will increase the performance of
82
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
83
+ # a value less than 10 in other environments.
84
+ config.stretches = Rails.env.test? ? 1 : 10
85
+
86
+ # Setup a pepper to generate the encrypted password.
87
+ # config.pepper = "8586740d30581d9e81c8389ed1a8690d02bda3bb71fa883967a14a7523ba625bba72715ab3b97de565c04ac8da0dfe3c48fbaf451b03609b0b23c04eeed26335"
88
+
89
+ # ==> Configuration for :confirmable
90
+ # A period that the user is allowed to access the website even without
91
+ # confirming his account. For instance, if set to 2.days, the user will be
92
+ # able to access the website for two days without confirming his account,
93
+ # access will be blocked just in the third day. Default is 0.days, meaning
94
+ # the user cannot access the website without confirming his account.
95
+ # config.allow_unconfirmed_access_for = 2.days
96
+
97
+ # A period that the user is allowed to confirm their account before their
98
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
99
+ # their account within 3 days after the mail was sent, but on the fourth day
100
+ # their account can't be confirmed with the token any more.
101
+ # Default is nil, meaning there is no restriction on how long a user can take
102
+ # before confirming their account.
103
+ # config.confirm_within = 3.days
104
+
105
+ # If true, requires any email changes to be confirmed (exactly the same way as
106
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
107
+ # db field (see migrations). Until confirmed new email is stored in
108
+ # unconfirmed email column, and copied to email column on successful confirmation.
109
+ config.reconfirmable = true
110
+
111
+ # Defines which key will be used when confirming an account
112
+ # config.confirmation_keys = [ :email ]
113
+
114
+ # ==> Configuration for :rememberable
115
+ # The time the user will be remembered without asking for credentials again.
116
+ # config.remember_for = 2.weeks
117
+
118
+ # If true, extends the user's remember period when remembered via cookie.
119
+ # config.extend_remember_period = false
120
+
121
+ # Options to be passed to the created cookie. For instance, you can set
122
+ # :secure => true in order to force SSL only cookies.
123
+ # config.rememberable_options = {}
124
+
125
+ # ==> Configuration for :validatable
126
+ # Range for password length. Default is 8..128.
127
+ config.password_length = 8..128
128
+
129
+ # Email regex used to validate email formats. It simply asserts that
130
+ # an one (and only one) @ exists in the given string. This is mainly
131
+ # to give user feedback and not to assert the e-mail validity.
132
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
133
+
134
+ # ==> Configuration for :timeoutable
135
+ # The time you want to timeout the user session without activity. After this
136
+ # time the user will be asked for credentials again. Default is 30 minutes.
137
+ # config.timeout_in = 30.minutes
138
+
139
+ # If true, expires auth token on session timeout.
140
+ # config.expire_auth_token_on_timeout = false
141
+
142
+ # ==> Configuration for :lockable
143
+ # Defines which strategy will be used to lock an account.
144
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
145
+ # :none = No lock strategy. You should handle locking by yourself.
146
+ # config.lock_strategy = :failed_attempts
147
+
148
+ # Defines which key will be used when locking and unlocking an account
149
+ # config.unlock_keys = [ :email ]
150
+
151
+ # Defines which strategy will be used to unlock an account.
152
+ # :email = Sends an unlock link to the user email
153
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
154
+ # :both = Enables both strategies
155
+ # :none = No unlock strategy. You should handle unlocking by yourself.
156
+ # config.unlock_strategy = :both
157
+
158
+ # Number of authentication tries before locking an account if lock_strategy
159
+ # is failed attempts.
160
+ # config.maximum_attempts = 20
161
+
162
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
163
+ # config.unlock_in = 1.hour
164
+
165
+ # ==> Configuration for :recoverable
166
+ #
167
+ # Defines which key will be used when recovering the password for an account
168
+ # config.reset_password_keys = [ :email ]
169
+
170
+ # Time interval you can reset your password with a reset password key.
171
+ # Don't put a too small interval or your users won't have the time to
172
+ # change their passwords.
173
+ config.reset_password_within = 6.hours
174
+
175
+ # ==> Configuration for :encryptable
176
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
177
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
178
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
179
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
180
+ # REST_AUTH_SITE_KEY to pepper)
181
+ # config.encryptor = :sha512
182
+
183
+ # ==> Configuration for :token_authenticatable
184
+ # Defines name of the authentication token params key
185
+ # config.token_authentication_key = :auth_token
186
+
187
+ # ==> Scopes configuration
188
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
189
+ # "users/sessions/new". It's turned off by default because it's slower if you
190
+ # are using only default views.
191
+ # config.scoped_views = false
192
+
193
+ # Configure the default scope given to Warden. By default it's the first
194
+ # devise role declared in your routes (usually :user).
195
+ # config.default_scope = :user
196
+
197
+ # Set this configuration to false if you want /users/sign_out to sign out
198
+ # only the current scope. By default, Devise signs out all scopes.
199
+ # config.sign_out_all_scopes = true
200
+
201
+ # ==> Navigation configuration
202
+ # Lists the formats that should be treated as navigational. Formats like
203
+ # :html, should redirect to the sign in page when the user does not have
204
+ # access, but formats like :xml or :json, should return 401.
205
+ #
206
+ # If you have any extra navigational formats, like :iphone or :mobile, you
207
+ # should add them to the navigational formats lists.
208
+ #
209
+ # The "*/*" below is required to match Internet Explorer requests.
210
+ # config.navigational_formats = ["*/*", :html]
211
+
212
+ # The default HTTP method used to sign out a resource. Default is :delete.
213
+ config.sign_out_via = :delete
214
+
215
+ # ==> OmniAuth
216
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
217
+ # up on your models and hooks.
218
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
219
+
220
+ # ==> Warden configuration
221
+ # If you want to use other strategies, that are not supported by Devise, or
222
+ # change the failure app, you can configure them inside the config.warden block.
223
+ #
224
+ # config.warden do |manager|
225
+ # manager.intercept_401 = false
226
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
227
+ # end
228
+
229
+ # ==> Mountable engine configurations
230
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
231
+ # is mountable, there are some extra configurations to be taken into account.
232
+ # The following options are available, assuming the engine is mounted as:
233
+ #
234
+ # mount MyEngine, at: "/my_engine"
235
+ #
236
+ # The router that invoked `devise_for`, in the example above, would be:
237
+ # config.router_name = :my_engine
238
+ #
239
+ # When using omniauth, Devise cannot automatically set Omniauth path,
240
+ # so you need to do it manually. For the users scope, it would be:
241
+ # config.omniauth_path_prefix = "/my_engine/users/auth"
242
+
243
+ # ==> Devise TwoFactor Extension
244
+ # Configure extension for devise
245
+
246
+ # How long should the user have to enter their token. To change the default, uncomment and change the below:
247
+ # config.otp_authentication_timeout = 3.minutes
248
+
249
+ # Change time drift settings for valid token values. To change the default, uncomment and change the below:
250
+ # config.otp_authentication_time_drift = 3
251
+ end
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '7854ba4c663086c191afbc2e05384503b5529fa2c8e51417539db1cbe7c68e8490e9d57a1d908d4e82816a522edb97f71a8de9233272a5598534a38ef1b08697'
8
+ Dummy::Application.config.secret_key_base = '7854ba4c663086c191afbc2e05384503b5529fa2c8e51417539db1cbe7c68e8490e9d57a1d908d4e82816a522edb97f71a8de9233272a5598534a38ef1b08697'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,6 @@
1
+ Dummy::Application.routes.draw do
2
+ devise_for :users
3
+
4
+ resources :posts
5
+ root to: 'posts#index'
6
+ end
@@ -0,0 +1,9 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ class AddDeviseToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ change_table(:users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, null: false, default: ''
6
+ t.string :encrypted_password, null: false, default: ''
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, default: 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ ## Confirmable
23
+ # t.string :confirmation_token
24
+ # t.datetime :confirmed_at
25
+ # t.datetime :confirmation_sent_at
26
+ # t.string :unconfirmed_email # Only if using reconfirmable
27
+
28
+ ## Lockable
29
+ t.integer :failed_attempts, default: 0 # Only if lock strategy is :failed_attempts
30
+ t.string :unlock_token # Only if unlock strategy is :email or :both
31
+ t.datetime :locked_at
32
+
33
+ ## Token authenticatable
34
+ t.string :authentication_token
35
+
36
+ # Uncomment below if timestamps were not included in your original model.
37
+ # t.timestamps
38
+ end
39
+
40
+ add_index :users, :email, unique: true
41
+ add_index :users, :reset_password_token, unique: true
42
+ # add_index :users, :confirmation_token, :unique => true
43
+ add_index :users, :unlock_token, unique: true
44
+ add_index :users, :authentication_token, unique: true
45
+ end
46
+
47
+ def self.down
48
+ # By default, we don't want to make any assumption about how to roll back a migration when your
49
+ # model already existed. Please edit below which fields you would like to remove in this migration.
50
+ raise ActiveRecord::IrreversibleMigration
51
+ end
52
+ end
@@ -0,0 +1,10 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ class DeviseTwoFactorAddToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :users do |t|
4
+ t.string :otp_auth_secret
5
+ t.string :otp_recovery_secret
6
+ t.boolean :otp_enabled, default: false, null: false
7
+ t.boolean :otp_mandatory, default: false, null: false
8
+ t.datetime :otp_enabled_on
9
+ t.integer :otp_time_drift, default: 0, null: false
10
+ t.integer :otp_failed_attempts, default: 0, null: false
11
+ t.integer :otp_recovery_counter, default: 0, null: false
12
+ t.string :otp_persistence_seed
13
+
14
+ t.string :otp_session_challenge
15
+ t.datetime :otp_challenge_expires
16
+ end
17
+
18
+ add_index :users, :otp_session_challenge, unique: true
19
+ add_index :users, :otp_challenge_expires
20
+ end
21
+
22
+ def self.down
23
+ change_table :users do |t|
24
+ t.remove :otp_auth_secret, :otp_recovery_secret, :otp_enabled, :otp_mandatory, :otp_enabled_on, :otp_session_challenge,
25
+ :otp_challenge_expires, :otp_time_drift, :otp_failed_attempts, :otp_recovery_counter, :otp_persistence_seed
26
+ end
27
+ end
28
+ end