Class: Kwipper::SessionsController

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

Constant Summary

Constants inherited from Controller

Controller::ROUTES

Constants included from RendersViews

RendersViews::VIEWS_PATH, RendersViews::VIEW_EXT

Instance Attribute Summary

Attributes inherited from Controller

#action, #app, #request, #response

Instance Method Summary collapse

Methods inherited from Controller

add_routes, #home, #initialize, #process

Methods included from RendersViews

#render

Constructor Details

This class inherits a constructor from Kwipper::Controller

Instance Method Details

#createObject



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

def create
  @user = User.authenticate params['username'], params['password']

  if @user
    Session.create({
      'id'         => response.session_cookie_value,
      'user_id'    => @user.id,
      'created_at' => Time.now.httpdate
    })

    redirect '/users'
  else
    redirect '/users/login', :bad_request
  end
end

#destroyObject



24
25
26
27
28
29
30
# File 'app/controllers/sessions_controller.rb', line 24

def destroy
  if current_session
    current_session.destroy
    response.remove_session_cookie
  end
  redirect '/'
end