songtianlun
286ca3419f
- Change the render method to include a status of :unprocessable_entity when the email/password combination is invalid. - This change improves the API response for invalid login attempts, allowing clients to better handle errors.
26 lines
705 B
Ruby
26 lines
705 B
Ruby
class SessionsController < ApplicationController
|
|
include SessionsHelper
|
|
def new
|
|
end
|
|
|
|
def create
|
|
user = User.find_by(email: params[:session][:email].downcase)
|
|
# if user && user.authenticate(params[:session][:password])
|
|
if user&.authenticate(params[:session][:password])
|
|
forwarding_url = session[:forwarding_url]
|
|
reset_session
|
|
params[:session][:remember_me] == "1" ? remember(user) : forget(user)
|
|
log_in user
|
|
redirect_to forwarding_url || user
|
|
else
|
|
flash.now[:danger] = "Invalid email/password combination"
|
|
render "new", status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
log_out if logged_in?
|
|
redirect_to root_url
|
|
end
|
|
end
|