Skip to content

Commit

Permalink
chore: installed devise-two-factor gem
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellberg committed Apr 1, 2024
1 parent 037e425 commit da4d8f4
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gem "bootsnap", require: false
# gem "image_processing", "~> 1.2"

gem "devise", "~> 4.9", ">= 4.9.3"
gem "devise-two-factor", "~> 5.0.0"
gem "dry-initializer", "~> 3.1"
gem "meta-tags", "~> 2.20"
gem "public_uid", "~> 2.2"
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
devise-two-factor (5.0.0)
activesupport (~> 7.0)
devise (~> 4.0)
railties (~> 7.0)
rotp (~> 6.0)
docile (1.4.0)
drb (2.2.1)
dry-initializer (3.1.1)
Expand Down Expand Up @@ -265,6 +270,7 @@ GEM
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rotp (6.3.0)
rubocop (1.62.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
Expand Down Expand Up @@ -385,6 +391,7 @@ DEPENDENCIES
capybara
debug
devise (~> 4.9, >= 4.9.3)
devise-two-factor (~> 5.0.0)
dry-initializer (~> 3.1)
erb_lint
factory_bot_rails (~> 6.4.3)
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ class ApplicationController < ActionController::Base

before_action :authenticate_user!
before_action :ensure_onboarded, unless: :devise_controller?
before_action :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_in, keys: [:otp_attempt])
end

private

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class User < ApplicationRecord
# Include default devise modules.
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :confirmable, :lockable, :timeoutable, :trackable # , :omniauthable
devise :registerable, :recoverable, :rememberable, :validatable, :confirmable, :lockable, :timeoutable, :trackable, :two_factor_authenticatable # , :omniauthable

# Access the users personal account.
belongs_to :personal_account, class_name: "Account", optional: true, dependent: :destroy
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
config.warden do |manager|
manager.default_strategies(scope: :user).unshift :two_factor_authenticatable
end

# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20240401110029_add_devise_two_factor_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddDeviseTwoFactorToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :otp_secret, :string
add_column :users, :consumed_timestep, :integer
add_column :users, :otp_required_for_login, :boolean, default: false
add_column :users, :otp_backup_codes, :text
end
end
6 changes: 5 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/system/accounts/edit_acounts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EditAccountsTest < ApplicationSystemTestCase

sign_in(user)
visit edit_account_path
sleep 1
assert_selector("input[name='account[name]']")

# Fill the personal account setup form
fill_in "account[name]", with: "New name"
Expand Down

0 comments on commit da4d8f4

Please sign in to comment.