Class: UserSessionsController

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

Overview

Create, destroy sessions by letting users login and logout. When the user does not login, he/she is considered to be the anonymous user.

Instance Method Summary collapse

Methods included from Zena::App

included

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/user_sessions_controller.rb', line 14

def create
  User.send(:with_scope, :find => {:conditions => ['site_id = ?', visitor.site.id]}) do
    @user_session = UserSession.new(:login=>params[:login], :password=>params[:password])
    if @user_session.save
      #flash.now[:notice] = _("Successfully logged in.")
      redirect_to  
    else
      flash[:notice] = _("Invalid login or password.")
      # FIXME: find a better way to lock without blocking the process.
      # Also lock longer and longer (exponentially).
      sleep(2)
      redirect_to 
    end
  end
end

#destroyObject



30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/user_sessions_controller.rb', line 30

def destroy
  if @user_session = UserSession.find
    @user_session.destroy
    reset_session
    #flash.now[:notice] = _("Successfully logged out.")
    redirect_to params[:redirect] || home_path(:prefix => prefix)
  else
    redirect_to home_path(:prefix => prefix)
  end
end

#newObject

/login



9
10
11
12
# File 'app/controllers/user_sessions_controller.rb', line 9

def new
  @node = visitor.site.root_node
  render_and_cache :mode => '+login'
end