Class: SessionsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary collapse

Methods included from SessionsHelper

#sessions_current_user, #sessions_current_user=, #sessions_sign_in, #sessions_sign_out, #sessions_signed_in?

Instance Method Details

#createObject

POST /sessions



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

def create
  user = User.find_by(email: params[:session][:email].downcase)
  if user && user.authenticate(params[:session][:password])
     user
    redirect_to root_path
  else
    @page_title = 'Sign in'
    flash.now[:error] = 'Unrecognised email and password combination.'
    render 'new'
  end
end

#destroyObject

DELETE /signout



23
24
25
26
# File 'app/controllers/sessions_controller.rb', line 23

def destroy
  sessions_sign_out
  redirect_to root_url
end

#newObject

GET /signin



4
5
6
7
# File 'app/controllers/sessions_controller.rb', line 4

def new
  @page_title = 'Sign in'
  @user = User.new
end