Parent

Class Index [+]

Quicksearch

Ramaze::Helper::UserHelper::Wrapper

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.

Attributes

_model[RW]
_callback[RW]
_user[RW]

Public Class Methods

new(model, callback) click to toggle source
     # File lib/ramaze/helper/user.rb, line 195
195:         def initialize(model, callback)
196:           @_model, @_callback = model, callback
197:           @_user = nil
198:           _login
199:         end

Public Instance Methods

_logged_in?() click to toggle source

@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
_login(creds = nil) click to toggle source

@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
_logout() click to toggle source

@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
_persistence() click to toggle source
     # File lib/ramaze/helper/user.rb, line 268
268:         def _persistence
269:           Current.session[:USER]
270:         end
_persistence=(obj) click to toggle source
     # File lib/ramaze/helper/user.rb, line 264
264:         def _persistence=(obj)
265:           Current.session[:USER] = obj
266:         end
_would_login?(creds) click to toggle source

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
method_missing(meth, *args, &block) click to toggle source

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.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.