From 6d22462d7a3bebf63b2ea3e28aca4ba75fcac489 Mon Sep 17 00:00:00 2001 From: Logan Fick Date: Thu, 7 Jun 2018 20:31:11 -0400 Subject: Added TOTP field to login screen. --- app/controllers/sessions_controller.rb | 6 +++++- app/views/sessions/new.html.erb | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 784647c..8755730 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -21,6 +21,10 @@ class SessionsController < ApplicationController flash[:alert] = "Your account has been disabled!" elsif user.banned? flash[:alert] = "You are banned!" + elsif user.totp_enabled && !TOTP.verify?(user.totp_code, params[:totp_code]) + flash[:alert] = "You're doing it wrong!" + render action: 'new' + return else session[:user_id] = user.id flash[:notice] = "Logged in!" @@ -110,4 +114,4 @@ class SessionsController < ApplicationController redirect_to login_path end end -end \ No newline at end of file +end diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 0158f59..c7cac42 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -16,6 +16,14 @@ <%= link_to "Lost your password?", lost_password_users_path %> + + <%= label_tag :totp_code %> + <%= text_field_tag :totp_code, nil, placeholder: "123456", required: false %> + + + + Leave this field blank if you do not have 2FA enabled. +

<%= submit_tag "Log in", class: "btn blue" %>

<% end %> -- cgit v1.2.3