Class: UserSessionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- UserSessionsController
- 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
- #create ⇒ Object
-
#destroy ⇒ Object
Logout.
-
#new ⇒ Object
/login.
Methods included from Zena::App
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/user_sessions_controller.rb', line 15 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 redirect_after_login 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 login_path end end end |
#destroy ⇒ Object
Logout
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/user_sessions_controller.rb', line 32 def destroy port = request.port == 80 ? '' : ":#{request.port}" if @user_session = UserSession.find @user_session.destroy reset_session if current_site.ssl_on_auth # SSH only when authenticated host = current_site.host http = 'http' else # Keep current host and port settings host = host_with_port http = host =~ /:/ ? 'https' : 'http' end #flash.now[:notice] = _("Successfully logged out.") redirect_to "#{http}://#{host}#{params[:redirect] || home_path(:prefix => prefix)}" else redirect_to "http://#{host}#{home_path(:prefix => prefix)}" end end |
#new ⇒ Object
/login
10 11 12 13 |
# File 'app/controllers/user_sessions_controller.rb', line 10 def new @node = visitor.site.root_node render_and_cache :mode => '+login' end |