Class LoginController
In: app/controllers/login_controller.rb
Parent: ApplicationController

************************************************************************/

  • SOLUNAS BOOKING ENGINE */
  • ====================== */
  • */
  • Copyright © 2006 by Marc Isemann */
  • sourceforge.net/projects/solunas */
  • */
  • This program is free software. You can redistribute it and/or modify */
  • it under the terms of the GNU General Public License as published by */
  • the Free Software Foundation; either version 2 of the License. */

************************************************************************/

Methods

index   login   logout  

Public Instance methods

[Source]

    # File app/controllers/login_controller.rb, line 20
20:   def index
21:     render(:action => login)
22:   end

Display the login form and wait for user to enter a name and password. We then validate these, adding the user object to the session if they authorize.

[Source]

    # File app/controllers/login_controller.rb, line 28
28:   def login
29:     if request.get?
30:       session[:user_id] = nil
31:       @user = User.new
32:     else
33:       @user = User.new(params[:user])
34:       logged_in_user = @user.try_to_login
35: 
36:       if logged_in_user
37:         session[:user_id] = logged_in_user.id
38:         session[:admin] = logged_in_user.admin
39:         redirect_to(:action => "index", :controller => "user_admin")
40:       else
41:         flash[:notice] = "Invalid user/password combination".t
42:       end
43:     end
44:   end

Log out by clearing the user entry in the session. We then redirect to the login action.

[Source]

    # File app/controllers/login_controller.rb, line 48
48:   def logout
49:     session[:user_id] = nil
50:     flash[:notice] = "Logged out".t
51:     redirect_to(:action => "login")
52:   end

[Validate]