This commit is contained in:
aignatov-bio 2020-07-13 16:05:23 +02:00
parent 7d20bf6fea
commit c592954400
5 changed files with 33 additions and 21 deletions

View file

@ -102,10 +102,12 @@ class Users::SessionsController < Devise::SessionsController
sign_in(user)
generate_demo_project
flash[:notice] = t('devise.sessions.signed_in')
redirect_to root_path
else
flash.now[:alert] = t('Not correct recovery code')
flash[:alert] = t("devise.sessions.2fa_recovery.not_correct_code")
redirect_to new_user_session_path
end
redirect_to root_path
end
protected

View file

@ -676,7 +676,7 @@ class User < ApplicationRecord
otp_recovery_codes.each do |recovery_code|
if Devise::Encryptor.compare(self.class, recovery_code, code)
update(otp_recovery_codes: otp_recovery_codes.reject { |i| i == recovery_code })
update!(otp_recovery_codes: otp_recovery_codes.reject { |i| i == recovery_code })
return true
end
end

View file

@ -3,18 +3,19 @@
<div class="sign-in-container">
<div class="sign-in-form-wrapper">
<div class="center-block center-block-narrow">
<h1 class="log-in-title"><%=t "devise.sessions.2fa.title" %></h1>
<h1 class="log-in-title"><%= t "devise.sessions.2fa.title" %></h1>
<%= form_with url: users_authenticate_with_two_factor_url, local: true do %>
<div class="input-group sci-input-container">
<p><%= t "devise.sessions.2fa.description" %></p>
<p class="input-group sci-input-container">
<%= label :otp, t("devise.sessions.2fa.field") %>
<%= text_field_tag(:otp, '', { class: "form-control sci-input-field", placeholder: t("devise.sessions.2fa.placeholder") })%>
</div>
<%= text_field_tag(:otp, '', { class: "form-control sci-input-field" })%>
</p>
<div class="actions" style="margin-top: 10px; margin-bottom: 10px;">
<%= button_tag t("devise.sessions.new.submit"), type: :submit, class: "btn btn-primary log-in-button" %>
</div>
<p class="actions">
<%= button_tag t("devise.sessions.2fa.enter"), type: :submit, class: "btn btn-primary" %>
</p>
<%= link_to 'I have a bypass code', users_two_factor_recovery_path %>
<%= link_to t("devise.sessions.2fa.bypass_code_link"), users_two_factor_recovery_path %>
<% end %>
</div>
</div>

View file

@ -3,15 +3,16 @@
<div class="sign-in-container">
<div class="sign-in-form-wrapper">
<div class="center-block center-block-narrow">
<h1 class="log-in-title">2FA Bypass</h1>
<h1 class="log-in-title"><%= t "devise.sessions.2fa_recovery.title" %></h1>
<%= form_with url: users_authenticate_with_recovery_code_path, local: true do %>
<div class="input-group sci-input-container">
<%= label :recovery_code, 'Bypass code' %>
<p><%= t "devise.sessions.2fa_recovery.description" %></p>
<p class="input-group sci-input-container">
<%= label :recovery_code, t("devise.sessions.2fa_recovery.bypass_code") %>
<%= text_field_tag(:recovery_code, '', { class: "form-control sci-input-field" })%>
</div>
</p>
<div class="actions" style="margin-top: 10px; margin-bottom: 10px;">
<%= button_tag 'Enter', type: :submit, class: "btn btn-primary" %>
<div class="actions">
<%= button_tag t("devise.sessions.2fa_recovery.enter"), type: :submit, class: "btn btn-primary" %>
</div>
<% end %>
</div>

View file

@ -34,11 +34,19 @@ en:
remember_me: "Remember me"
submit: "Log in"
2fa:
title: "Two factor check"
field: "One time password"
placeholder: "Enter code"
error_message: "One Time Password is not correct."
title: "Two-factor authentication"
description: "Enter the one-time code found in your authenticator app to log in to SciNote."
field: "Authenticator code"
error_message: "One time code is not correct."
no_user_error: "Cannot find user!"
enter: "Enter"
bypass_code_link: "I have a bypass code"
2fa_recovery:
title: "2FA Bypass"
description: "Enter one of the bypass codes provided when you creted 2FA authentication. The code will no longer be valid after use."
bypass_code: "Bypass code"
enter: "Enter"
not_correct_code: "Not correct recovery code"
create:
team_name: "%{user}'s projects"
auth_token_create: