Merge pull request #866 from farhatahmad/signin-bug

GRN2-xx: Fixed signin bug that prevent specific users from signing in
This commit is contained in:
Richard Alam 2019-11-14 14:27:04 -05:00 committed by GitHub
commit c92c8ad1ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -121,7 +121,7 @@ Metrics/ClassLength:
# Limit lines to 80 characters.
Metrics/LineLength:
Max: 120
Max: 130
# Avoid methods longer than 10 lines of code.
Metrics/MethodLength:

View File

@ -63,17 +63,22 @@ class SessionsController < ApplicationController
def create
logger.info "Support: #{session_params[:email]} is attempting to login."
user = User.include_deleted.find_by(email: session_params[:email], provider: @user_domain)
user = User.include_deleted.find_by(email: session_params[:email])
# Check user with that email exists
return redirect_to(signin_path, alert: I18n.t("invalid_credentials")) unless user
is_super_admin = user.has_role? :super_admin
# Scope user to domain if the user is not a super admin
user = User.include_deleted.find_by(email: session_params[:email], provider: @user_domain) unless is_super_admin
# Check correct password was entered
return redirect_to(signin_path, alert: I18n.t("invalid_credentials")) unless user.try(:authenticate,
session_params[:password])
# Check that the user is not deleted
return redirect_to root_path, flash: { alert: I18n.t("registration.banned.fail") } if user.deleted?
unless user.has_role? :super_admin
unless is_super_admin
# Check that the user is a Greenlight account
return redirect_to(root_path, alert: I18n.t("invalid_login_method")) unless user.greenlight_account?
# Check that the user has verified their account