FIX: Show a nicer error if name/code missing for TOTP/Security Keys (#9124)

Meta: https://meta.discourse.org/t/improve-error-message-when-not-including-name-setting-up-totp/143339

* when the user creates a TOTP second factor method we want
to show them a nicer error if they forget to add a name
or the code from the app, instead of the param missing error
* also add a client-side check for this and for security key name,
no need to bother the server if we can help it
This commit is contained in:
Martin Brennan
2020-03-06 14:37:40 +10:00
committed by GitHub
parent 494379201d
commit 29ccdf5d35
8 changed files with 120 additions and 11 deletions

View File

@ -1211,8 +1211,12 @@ class UsersController < ApplicationController
end
def enable_second_factor_totp
params.require(:second_factor_token)
params.require(:name)
if params[:second_factor_token].blank?
return render json: failed_json.merge(error: I18n.t("login.missing_second_factor_code"))
end
if params[:name].blank?
return render json: failed_json.merge(error: I18n.t("login.missing_second_factor_name"))
end
auth_token = params[:second_factor_token]
totp_data = secure_session["staged-totp-#{current_user.id}"]