You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
class SessionsController < ApplicationController
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
user = User.find_by(email: params[:email])
|
|
|
|
if user && user.authenticate(params[:password])
|
|
|
|
session[:user_id] = user.id
|
|
|
|
redirect_to user, notice: "Welcome back, #{user.name}!"
|
|
|
|
else
|
|
|
|
flash.now[:alert] = "Invalid email/password combination!"
|
|
|
|
render :new, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
session[:user_id] = nil
|
|
|
|
redirect_to movies_url, status: :see_other, notice: "You're now signed out!"
|
|
|
|
end
|
|
|
|
end
|