correctly handle failed login

This commit is contained in:
Joshua Arts
2018-06-28 09:35:36 -04:00
parent f0ab2924db
commit d9c5d37810
2 changed files with 14 additions and 1 deletions

View File

@ -1,6 +1,9 @@
# frozen_string_literal: true
class SessionsController < ApplicationController
LOGIN_FAILED = "Login failed due to invalid credentials. Are you sure you typed them correctly?"
# GET /users/login
def new
end
@ -14,8 +17,10 @@ class SessionsController < ApplicationController
# POST /users/login
def create
user = User.find_by(email: session_params[:email])
if user.&authenticate(session_params[:password])
if user&.authenticate(session_params[:password])
login(user)
else
redirect_to root_path, notice: LOGIN_FAILED
end
end