Module: Ramaze::Helper::Auth
- Defined in:
- lib/ramaze/helper/auth.rb
Overview
A simple way to do authentication. Please have a look at the docs for the check_auth method for detailed information
Constant Summary collapse
- AUTH_ELEMENT =
The default Element to use (if any)
'Page'
Class Method Summary collapse
-
.included(klass) ⇒ Object
add Helper::Aspect and Helper::Stack on inclusion of Helper::Auth.
Instance Method Summary collapse
-
#login ⇒ Object
action for login, takes a password ( ?password=passwort or /login/passwort or via a form ) if no password given, shows a simple form to input it.
-
#logout ⇒ Object
clear the session and redirect to the index action of the mapping of the current controller.
Class Method Details
.included(klass) ⇒ Object
add Helper::Aspect and Helper::Stack on inclusion of Helper::Auth
16 17 18 |
# File 'lib/ramaze/helper/auth.rb', line 16 def self.included(klass) klass.send(:helper, :aspect, :stack) end |
Instance Method Details
#login ⇒ Object
action for login, takes a password ( ?password=passwort or /login/passwort or via a form ) if no password given, shows a simple form to input it.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ramaze/helper/auth.rb', line 28 def login username, password = request[:username, :password] if check_auth(username, password) session[:logged_in] = true session[:username] = username inside_stack? ? answer : redirect_referrer else if defined? AUTH_ELEMENT and AUTH_ELEMENT.to_s.split.any? open_element = "<#{AUTH_ELEMENT}>" close_element = "</#{AUTH_ELEMENT}>" end %{ #{open_element} <form method="POST" action="#{Rs(:login)}"> <ul style="list-style:none;"> <li>Username: <input type="text" name="username" /></li> <li>Password: <input type="password" name="password" /></li> <li><input type="submit" /></li> </ul> </form> #{close_element} } end end |
#logout ⇒ Object
clear the session and redirect to the index action of the mapping of the current controller.
56 57 58 59 |
# File 'lib/ramaze/helper/auth.rb', line 56 def logout session.clear redirect_referer end |