24 lines
534 B
Ruby
24 lines
534 B
Ruby
|
class SessionsController < ApplicationController
|
||
|
def new
|
||
|
end
|
||
|
|
||
|
def create
|
||
|
user = User.find_by(email: params[:email].downcase)
|
||
|
if user && user.authenticate(params[:password])
|
||
|
session[:user_id] = user.id
|
||
|
flash[:notice] = "Logged in successfully."
|
||
|
redirect_to root_path
|
||
|
else
|
||
|
flash[:alert] = "Invalid email or password"
|
||
|
render :new
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def destroy
|
||
|
session[:user_id] = nil
|
||
|
reset_session
|
||
|
flash[:notice] = "Logged out successfully."
|
||
|
redirect_to root_path
|
||
|
end
|
||
|
end
|