Class: SessionsController

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

Constant Summary

Constants included from ControllerCallbacks

ControllerCallbacks::METHODS

Instance Attribute Summary

Attributes inherited from ControllerBase

#params, #req, #res

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #ensure_login, #ensure_logout, #logged_in?, #login, #logout

Methods inherited from ControllerBase

#form_authenticity_token, #initialize, #invoke_action, #link_to, protect_from_forgery, #root_url

Methods included from ControllerCallbacks

#before_action

Constructor Details

This class inherits a constructor from ControllerBase

Instance Method Details

#createObject



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

def create
  username = session_params[:username]
  password = session_params[:password]

  @user = User.find_by_credentials(username, password)
  if @user
    (@user)
    redirect_to root_url
  else
    flash.now[:errors] = ['invalid username/password']
    render :new
  end
end

#destroyObject



22
23
24
25
# File 'lib/scaffold/app/controllers/sessions_controller.rb', line 22

def destroy
  logout
  redirect_to new_sessions_url
end

#newObject



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

def new
  @user = User.new
end