main
1# frozen_string_literal: true
2
3module My
4 class MfasController < ApplicationController
5 def show
6 redirect_to current_user.mfa.setup? ? edit_my_mfa_path : new_my_mfa_path
7 end
8
9 def new
10 return redirect_to edit_my_mfa_path if current_user.mfa.setup?
11
12 current_user.mfa.build_secret
13 end
14
15 def create
16 current_user.update!(params.require(:user).permit(:mfa_secret))
17 redirect_to my_dashboard_path, notice: t('.success')
18 end
19
20 def edit; end
21
22 def test
23 secure_params = params.require(:user).permit(:mfa_secret, :code)
24 current_user.mfa_secret = secure_params[:mfa_secret]
25 @valid = current_user.mfa.authenticate(secure_params[:code])
26 render status: :ok, layout: nil
27 end
28
29 def destroy
30 if current_user.mfa.disable!(params[:user][:code])
31 redirect_to my_dashboard_path, notice: t('.success')
32 else
33 redirect_to edit_my_mfa_path, error: t('.error')
34 end
35 end
36 end
37end