Wrapper for the ever-present “user” in your application. It wraps around an arbitrary instance and worries about authentication and storing information about the user in the session.
In order to not interfere with the wrapped instance/model we start our methods with an underscore.
Patches and suggestions are highly appreciated.
@author manveru @api internal @see Ramaze::Helper::User#logged_in? @return [true false] whether the current user is logged in.
# File lib/ramaze/helper/user.rb, line 260 260: def _logged_in? 261: !!_user 262: end
@author manveru @see Ramaze::Helper::User#user_login @param [Hash] creds this hash will be stored in the session on
successful login
@return [Ramaze::Helper::User::Wrapper] wrapped return value from
model or callback
# File lib/ramaze/helper/user.rb, line 209 209: def _login(creds = nil) 210: if creds 211: if @_user = _would_login?(creds) 212: Current.session.resid! 213: self._persistence = {:credentials => creds} 214: end 215: elsif persistence = self._persistence 216: @_user = _would_login?(persistence[:credentials]) 217: end 218: end
@author manveru @api internal @see Ramaze::Helper::User#user_logout
# File lib/ramaze/helper/user.rb, line 249 249: def _logout 250: (_persistence || {}).clear 251: Current.request.env['ramaze.helper.user'] = nil 252: end
# File lib/ramaze/helper/user.rb, line 268 268: def _persistence 269: Current.session[:USER] 270: end
# File lib/ramaze/helper/user.rb, line 264 264: def _persistence=(obj) 265: Current.session[:USER] = obj 266: end
The callback should return an instance of the user, otherwise it should answer with nil.
This will not actually login, just check whether the credentials would result in a user.
# File lib/ramaze/helper/user.rb, line 227 227: def _would_login?(creds) 228: return unless creds 229: 230: if c = @_callback 231: c.call(creds) 232: elsif _model.respond_to?(:authenticate) 233: _model.authenticate(creds) 234: else 235: Log.warn( 236: "Helper::User has no callback and there is no %p::authenticate" % _model 237: ) 238: 239: nil 240: end 241: end
Refer everything not known THINK: This might be quite confusing... should we raise instead?
# File lib/ramaze/helper/user.rb, line 276 276: def method_missing(meth, *args, &block) 277: return unless _user 278: _user.send(meth, *args, &block) 279: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.