forked from External/greenlight
correctly handle failed login
This commit is contained in:
parent
f0ab2924db
commit
d9c5d37810
|
@ -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
|
||||
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
<% unless flash.empty? %>
|
||||
<%= render "shared/error_banner" do %>
|
||||
<% flash.each do |key, value| %>
|
||||
<%= content_tag :div, value, class: "flash #{key} d-inline" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<div class="background landing-section">
|
||||
<div class="d-flex align-items-center" style="height: 100%;">
|
||||
<div class="container text-center">
|
||||
|
|
Loading…
Reference in New Issue