Class: SessionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/templates/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/templates/sessions_controller.rb', line 5

def create
  user = User.where(email: params[:user][:email]).first if params[:user]
  if user && params[:user] && user.authenticate(params[:user][:password])
    flash.clear
    session[:user_id] = user.id
    
  else
    flash[:error] = "Invalid email / password combination"
    render :new
  end
end

#destroyObject



17
18
19
20
21
# File 'lib/templates/sessions_controller.rb', line 17

def destroy
  session[:user_id]
  flash[:success] = 'You have been logged out'
  redirect_to after_sign_out
end

#newObject



2
3
# File 'lib/templates/sessions_controller.rb', line 2

def new
end