parent
237cb41ab4
commit
ba192f12e3
@ -0,0 +1,28 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::TwoFactorAuthsController < ApplicationController
|
||||||
|
layout 'auth'
|
||||||
|
|
||||||
|
before_action :authenticate_user!
|
||||||
|
|
||||||
|
def show
|
||||||
|
return unless current_user.otp_required_for_login
|
||||||
|
|
||||||
|
@qrcode = RQRCode::QRCode.new(current_user.otp_provisioning_uri(current_user.email, issuer: Rails.configuration.x.local_domain))
|
||||||
|
end
|
||||||
|
|
||||||
|
def enable
|
||||||
|
current_user.otp_required_for_login = true
|
||||||
|
current_user.otp_secret = User.generate_otp_secret
|
||||||
|
current_user.save!
|
||||||
|
|
||||||
|
redirect_to settings_two_factor_auth_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def disable
|
||||||
|
current_user.otp_required_for_login = false
|
||||||
|
current_user.save!
|
||||||
|
|
||||||
|
redirect_to settings_two_factor_auth_path
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,17 @@
|
|||||||
|
- content_for :page_title do
|
||||||
|
= t('settings.two_factor_auth')
|
||||||
|
|
||||||
|
- if current_user.otp_required_for_login
|
||||||
|
%p= t('two_factor_auth.instructions_html')
|
||||||
|
|
||||||
|
.qr-code= raw @qrcode.as_svg(padding: 0, module_size: 5)
|
||||||
|
|
||||||
|
.simple_form
|
||||||
|
= link_to t('two_factor_auth.disable'), disable_settings_two_factor_auth_path, data: { method: 'POST' }, class: 'block-button'
|
||||||
|
- else
|
||||||
|
%p= t('two_factor_auth.description_html')
|
||||||
|
|
||||||
|
.simple_form
|
||||||
|
= link_to t('two_factor_auth.enable'), enable_settings_two_factor_auth_path, data: { method: 'POST' }, class: 'block-button'
|
||||||
|
|
||||||
|
.form-footer= render "settings/shared/links"
|
@ -1,4 +1,4 @@
|
|||||||
# Be sure to restart your server when you modify this file.
|
# Be sure to restart your server when you modify this file.
|
||||||
|
|
||||||
# Configure sensitive parameters which will be filtered from the log file.
|
# Configure sensitive parameters which will be filtered from the log file.
|
||||||
Rails.application.config.filter_parameters += [:password, :private_key, :public_key]
|
Rails.application.config.filter_parameters += [:password, :private_key, :public_key, :otp_attempt]
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
class AddDeviseTwoFactorToUsers < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
add_column :users, :encrypted_otp_secret, :string
|
||||||
|
add_column :users, :encrypted_otp_secret_iv, :string
|
||||||
|
add_column :users, :encrypted_otp_secret_salt, :string
|
||||||
|
add_column :users, :consumed_timestep, :integer
|
||||||
|
add_column :users, :otp_required_for_login, :boolean
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue