-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsessions_controller.rb
30 lines (27 loc) · 925 Bytes
/
sessions_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class SessionsController < ApplicationController
before_action :redirect_if_authenticated, only: [:create, :new]
before_action :authenticate_user!, only: [:destroy]
def new
end
def create
@user = User.authenticate_by(email: params[:user][:email].downcase, password: params[:user][:password])
if @user
if @user.unconfirmed?
redirect_to new_confirmation_path, alert: "Incorrect email or password."
else
after_login_path = session[:user_return_to] || root_path
active_session = login @user
remember(active_session) if params[:user][:remember_me] == "1"
redirect_to after_login_path, notice: "Signed in."
end
else
flash.now[:alert] = "Incorrect email or password."
render :new, status: :unprocessable_entity
end
end
def destroy
forget_active_session
logout
redirect_to root_path, notice: "Signed out."
end
end