Class: Bagboy::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/bagboy/sessions_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#initialize

Constructor Details

This class inherits a constructor from Bagboy::ApplicationController

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/bagboy/sessions_controller.rb', line 10

def create
  user = Bagboy::User.find_by_email(params[:email])
  if user && user.authenticate(params[:password])
    session[:user_id] = user.id
    redirect_to root_url, flash: {success: 'You have successfuly logged in!'}
  else
    flash.now.alert = 'Invalid email or password'
    render "new"
  end
end

#destroyObject



21
22
23
24
# File 'app/controllers/bagboy/sessions_controller.rb', line 21

def destroy
  session[:user_id] = nil
  redirect_to root_url, flash: { success: 'You have successfuly logged out!'}
end

#newObject



6
7
8
# File 'app/controllers/bagboy/sessions_controller.rb', line 6

def new
  render 'new'
end