.github
app
chewy
controllers
activitypub
admin
api
auth
concerns
oauth
settings
exports
two_factor_authentication
confirmations_controller.rb
recovery_codes_controller.rb
applications_controller.rb
deletes_controller.rb
exports_controller.rb
follower_domains_controller.rb
imports_controller.rb
migrations_controller.rb
notifications_controller.rb
preferences_controller.rb
profiles_controller.rb
sessions_controller.rb
two_factor_authentications_controller.rb
well_known
about_controller.rb
account_follow_controller.rb
account_unfollow_controller.rb
accounts_controller.rb
application_controller.rb
authorize_follows_controller.rb
emojis_controller.rb
follower_accounts_controller.rb
following_accounts_controller.rb
home_controller.rb
intents_controller.rb
invites_controller.rb
manifests_controller.rb
media_controller.rb
media_proxy_controller.rb
remote_follow_controller.rb
shares_controller.rb
statuses_controller.rb
stream_entries_controller.rb
tags_controller.rb
helpers
javascript
lib
mailers
models
policies
presenters
serializers
services
validators
views
workers
bin
config
db
docs
lib
log
nanobox
public
spec
streaming
vendor
.babelrc
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.nanobox
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.yml
.foreman
.gitattributes
.gitignore
.haml-lint.yml
.nanoignore
.nvmrc
.postcssrc.yml
.profile
.rspec
.rubocop.yml
.ruby-version
.scss-lint.yml
.slugignore
.travis.yml
.yarnclean
Aptfile
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
LICENSE
Procfile
Procfile.dev
README.md
Rakefile
Vagrantfile
app.json
boxfile.yml
config.ru
docker-compose.yml
jest.config.js
package.json
scalingo.json
yarn.lock
49 lines
1.4 KiB
Ruby
49 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Settings
|
|
module TwoFactorAuthentication
|
|
class ConfirmationsController < ApplicationController
|
|
layout 'admin'
|
|
|
|
before_action :authenticate_user!
|
|
before_action :ensure_otp_secret
|
|
|
|
def new
|
|
prepare_two_factor_form
|
|
end
|
|
|
|
def create
|
|
if current_user.validate_and_consume_otp!(confirmation_params[:code])
|
|
flash[:notice] = I18n.t('two_factor_authentication.enabled_success')
|
|
|
|
current_user.otp_required_for_login = true
|
|
@recovery_codes = current_user.generate_otp_backup_codes!
|
|
current_user.save!
|
|
|
|
render 'settings/two_factor_authentication/recovery_codes/index'
|
|
else
|
|
flash.now[:alert] = I18n.t('two_factor_authentication.wrong_code')
|
|
prepare_two_factor_form
|
|
render :new
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def confirmation_params
|
|
params.require(:form_two_factor_confirmation).permit(:code)
|
|
end
|
|
|
|
def prepare_two_factor_form
|
|
@confirmation = Form::TwoFactorConfirmation.new
|
|
@provision_url = current_user.otp_provisioning_uri(current_user.email, issuer: Rails.configuration.x.local_domain)
|
|
@qrcode = RQRCode::QRCode.new(@provision_url)
|
|
end
|
|
|
|
def ensure_otp_secret
|
|
redirect_to settings_two_factor_authentication_path unless current_user.otp_secret
|
|
end
|
|
end
|
|
end
|
|
end
|