-
Notifications
You must be signed in to change notification settings - Fork 166
LG-162 - Offer multiple 2FA options during account creation #2099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| module Users | ||
| class PhoneSetupController < ApplicationController | ||
| include UserAuthenticator | ||
| include PhoneConfirmation | ||
|
|
||
| before_action :authenticate_user | ||
| before_action :authorize_phone_setup | ||
|
|
||
| def index | ||
| @user_phone_form = UserPhoneForm.new(current_user) | ||
| @presenter = PhoneSetupPresenter.new(current_user.otp_delivery_preference) | ||
| analytics.track_event(Analytics::USER_REGISTRATION_PHONE_SETUP_VISIT) | ||
| end | ||
|
|
||
| def create | ||
| @user_phone_form = UserPhoneForm.new(current_user) | ||
| @presenter = PhoneSetupPresenter.new(current_user.otp_delivery_preference) | ||
| result = @user_phone_form.submit(user_phone_form_params) | ||
| analytics.track_event(Analytics::MULTI_FACTOR_AUTH_PHONE_SETUP, result.to_h) | ||
|
|
||
| if result.success? | ||
| prompt_to_confirm_phone(phone: @user_phone_form.phone) | ||
| else | ||
| render :index | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def authorize_phone_setup | ||
| if user_fully_authenticated? | ||
| redirect_to account_url | ||
| elsif current_user.two_factor_enabled? | ||
| redirect_to user_two_factor_authentication_url | ||
| end | ||
| end | ||
|
|
||
| def user_phone_form_params | ||
| params.require(:user_phone_form).permit( | ||
| :international_code, | ||
| :phone | ||
| ) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| class TwoFactorOptionsForm | ||
| include ActiveModel::Model | ||
|
|
||
| attr_reader :selection | ||
|
|
||
| validates :selection, inclusion: { in: %w[voice sms auth_app piv_cac] } | ||
|
|
||
| def initialize(user) | ||
| self.user = user | ||
| end | ||
|
|
||
| def submit(params) | ||
| self.selection = params[:selection] | ||
|
|
||
| success = valid? | ||
|
|
||
| update_otp_delivery_preference_for_user if success && user_needs_updating? | ||
|
|
||
| FormResponse.new(success: success, errors: errors.messages, extra: extra_analytics_attributes) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_accessor :user | ||
| attr_writer :selection | ||
|
|
||
| def extra_analytics_attributes | ||
| { | ||
| selection: selection, | ||
| } | ||
| end | ||
|
|
||
| def user_needs_updating? | ||
| return false unless %w[voice sms].include?(selection) | ||
| selection != user.otp_delivery_preference | ||
| end | ||
|
|
||
| def update_otp_delivery_preference_for_user | ||
| user_attributes = { otp_delivery_preference: selection } | ||
| UpdateUser.new(user: user, attributes: user_attributes).call | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
app/javascript/app/modules/international-phone-formatter.js
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| class PhoneSetupPresenter | ||
| include ActionView::Helpers::TranslationHelper | ||
|
|
||
| attr_reader :otp_delivery_preference | ||
|
|
||
| def initialize(otp_delivery_preference) | ||
| @otp_delivery_preference = otp_delivery_preference | ||
| end | ||
|
|
||
| def heading | ||
| t("titles.phone_setup.#{otp_delivery_preference}") | ||
| end | ||
|
|
||
| def label | ||
| t("devise.two_factor_authentication.phone_#{otp_delivery_preference}_label") | ||
| end | ||
|
|
||
| def info | ||
| t("devise.two_factor_authentication.phone_#{otp_delivery_preference}_info_html") | ||
| end | ||
|
|
||
| def image | ||
| "2FA-#{otp_delivery_preference}.svg" | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any specs covering this class