From ba192f12e381842c90df0fab2fcb1a23cae97fc4 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 27 Jan 2017 20:28:46 +0100 Subject: Added optional two-factor authentication --- .../settings/two_factor_auths_controller.rb | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/controllers/settings/two_factor_auths_controller.rb (limited to 'app/controllers/settings') diff --git a/app/controllers/settings/two_factor_auths_controller.rb b/app/controllers/settings/two_factor_auths_controller.rb new file mode 100644 index 000000000..66a82aab7 --- /dev/null +++ b/app/controllers/settings/two_factor_auths_controller.rb @@ -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 -- cgit