Module: Ramaze::Helper::User
- Defined in:
- lib/ramaze/helper/user.rb
Overview
convert the examples into real examples with specs
This helper provides a convenience wrapper for handling authentication and persistence of users.
On every request, when you use the #user method for the first time, we confirm the authentication and store the returned object in the request.env, usually this will involve a request to your database.
On every request it checks authentication again and retrieves the model, we are not using a normal cache for this as it may lead to behaviour that is very hard to predict and debug.
You can however, add your own caching quite easily.
Defined Under Namespace
Classes: Wrapper
Constant Summary collapse
- RAMAZE_HELPER_USER =
Using this as key in request.env
'ramaze.helper.user'.freeze
Instance Method Summary collapse
-
#logged_in? ⇒ true false
Whether the user is logged in already.
-
#user ⇒ Ramaze::Helper::User::Wrapper
Use this method in your application, but do not use it in conditionals as it will never be nil or false.
-
#user_login(creds = request.params) ⇒ nil Hash
shortcut for user._login but default argument are request.params.
-
#user_logout ⇒ nil
shortcut for user._logout.
Instance Method Details
#logged_in? ⇒ true false
Returns whether the user is logged in already.
148 149 150 |
# File 'lib/ramaze/helper/user.rb', line 148 def logged_in? user._logged_in? end |
#user ⇒ Ramaze::Helper::User::Wrapper
Use this method in your application, but do not use it in conditionals as it will never be nil or false.
109 110 111 112 113 114 115 116 117 |
# File 'lib/ramaze/helper/user.rb', line 109 def user env = request.env found = env[RAMAZE_HELPER_USER] return found if found model, callback = ancestral_trait.values_at(:user_model, :user_callback) model ||= ::User env[RAMAZE_HELPER_USER] = Wrapper.new(model, callback) end |
#user_login(creds = request.params) ⇒ nil Hash
shortcut for user._login but default argument are request.params
128 129 130 |
# File 'lib/ramaze/helper/user.rb', line 128 def user_login(creds = request.params) user._login(creds) end |
#user_logout ⇒ nil
shortcut for user._logout
139 140 141 |
# File 'lib/ramaze/helper/user.rb', line 139 def user_logout user._logout end |