-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2283 from 18F/stages/rc-2018-07-05
Deploy stages/rc-2018-07-05 to int
- Loading branch information
Showing
184 changed files
with
3,270 additions
and
751 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
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 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 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 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 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 @@ | ||
module AccountReset | ||
class CancelController < ApplicationController | ||
def cancel | ||
if AccountResetService.cancel_request(params[:token]) | ||
handle_success | ||
else | ||
handle_failure | ||
end | ||
redirect_to root_url | ||
end | ||
|
||
private | ||
|
||
def handle_success | ||
analytics.track_event(Analytics::ACCOUNT_RESET, event: :cancel, token_valid: true) | ||
sign_out if current_user | ||
flash[:success] = t('devise.two_factor_authentication.account_reset.successful_cancel') | ||
end | ||
|
||
def handle_failure | ||
return if params[:token].blank? | ||
analytics.track_event(Analytics::ACCOUNT_RESET, event: :cancel, token_valid: false) | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/controllers/account_reset/confirm_delete_account_controller.rb
This file contains 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,12 @@ | ||
module AccountReset | ||
class ConfirmDeleteAccountController < ApplicationController | ||
def show | ||
email = flash[:email] | ||
if email.blank? | ||
redirect_to root_url | ||
else | ||
render :show, locals: { email: email } | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/controllers/account_reset/confirm_request_controller.rb
This file contains 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,12 @@ | ||
module AccountReset | ||
class ConfirmRequestController < ApplicationController | ||
def show | ||
email = flash[:email] | ||
if email.blank? | ||
redirect_to root_url | ||
else | ||
render :show, locals: { email: email } | ||
end | ||
end | ||
end | ||
end |
48 changes: 48 additions & 0 deletions
48
app/controllers/account_reset/delete_account_controller.rb
This file contains 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,48 @@ | ||
module AccountReset | ||
class DeleteAccountController < ApplicationController | ||
before_action :check_feature_enabled | ||
before_action :prevent_parameter_leak, only: :show | ||
before_action :check_granted_token | ||
|
||
def show; end | ||
|
||
def delete | ||
analytics.track_event(Analytics::ACCOUNT_RESET, event: :delete, token_valid: true) | ||
email = reset_session_and_set_email | ||
UserMailer.account_reset_complete(email).deliver_later | ||
redirect_to account_reset_confirm_delete_account_url | ||
end | ||
|
||
private | ||
|
||
def check_feature_enabled | ||
redirect_to root_url unless FeatureManagement.account_reset_enabled? | ||
end | ||
|
||
def reset_session_and_set_email | ||
user = @account_reset_request.user | ||
email = user.email | ||
user.destroy! | ||
sign_out | ||
flash[:email] = email | ||
end | ||
|
||
def check_granted_token | ||
@account_reset_request = AccountResetRequest.from_valid_granted_token(session[:granted_token]) | ||
return if @account_reset_request | ||
analytics.track_event(Analytics::ACCOUNT_RESET, event: :delete, token_valid: false) | ||
redirect_to root_url | ||
end | ||
|
||
def prevent_parameter_leak | ||
token = params[:token] | ||
return if token.blank? | ||
if AccountResetRequest.find_by(granted_token: token)&.granted_token_valid? | ||
session[:granted_token] = token | ||
redirect_to url_for | ||
else | ||
redirect_to root_url | ||
end | ||
end | ||
end | ||
end |
This file contains 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 @@ | ||
module AccountReset | ||
class ReportFraudController < ApplicationController | ||
def update | ||
if AccountResetService.report_fraud(params[:token]) | ||
handle_success | ||
else | ||
handle_failure | ||
end | ||
redirect_to root_url | ||
end | ||
|
||
private | ||
|
||
def handle_success | ||
analytics.track_event(Analytics::ACCOUNT_RESET, event: :fraud, token_valid: true) | ||
sign_out if current_user | ||
flash[:success] = t('devise.two_factor_authentication.account_reset.successful_cancel') | ||
end | ||
|
||
def handle_failure | ||
return if params[:token].blank? | ||
analytics.track_event(Analytics::ACCOUNT_RESET, event: :fraud, token_valid: false) | ||
end | ||
end | ||
end |
This file contains 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,48 @@ | ||
module AccountReset | ||
class RequestController < ApplicationController | ||
include TwoFactorAuthenticatable | ||
|
||
before_action :check_account_reset_enabled | ||
before_action :confirm_two_factor_enabled | ||
|
||
def show; end | ||
|
||
def create | ||
analytics.track_event(Analytics::ACCOUNT_RESET, event: :request) | ||
create_request | ||
send_notifications | ||
reset_session_with_email | ||
redirect_to account_reset_confirm_request_url | ||
end | ||
|
||
private | ||
|
||
def check_account_reset_enabled | ||
redirect_to root_url unless FeatureManagement.account_reset_enabled? | ||
end | ||
|
||
def reset_session_with_email | ||
email = current_user.email | ||
sign_out | ||
flash[:email] = email | ||
end | ||
|
||
def send_notifications | ||
SmsAccountResetNotifierJob.perform_now( | ||
phone: current_user.phone, | ||
cancel_token: current_user.account_reset_request.request_token | ||
) | ||
UserMailer.account_reset_request(current_user).deliver_later | ||
end | ||
|
||
def create_request | ||
AccountResetService.new(current_user).create_request | ||
end | ||
|
||
def confirm_two_factor_enabled | ||
return if current_user.two_factor_enabled? | ||
|
||
redirect_to phone_setup_url | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
app/controllers/account_reset/send_notifications_controller.rb
This file contains 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,22 @@ | ||
module AccountReset | ||
class SendNotificationsController < ApplicationController | ||
before_action :authorize | ||
|
||
def update | ||
count = AccountResetService.grant_tokens_and_send_notifications | ||
analytics.track_event(Analytics::ACCOUNT_RESET, event: :notifications, count: count) | ||
render plain: 'ok' | ||
end | ||
|
||
private | ||
|
||
def authorize | ||
return if auth_token == Figaro.env.account_reset_auth_token | ||
head :unauthorized | ||
end | ||
|
||
def auth_token | ||
request.headers['X-API-AUTH-TOKEN'] | ||
end | ||
end | ||
end |
Oops, something went wrong.