### Home Classes Methods

### In Files

- lib/ramaze/helper/user.rb

### Parent

BlankSlate

### Methods

- ::new
- #_logged_in?
- #_login
- #_logout
- #_persistence
- #_persistence=
- #_would_login?
- #method_missing

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::AppGraph
- Ramaze::Bin
- Ramaze::Bin::Console
- Ramaze::Bin::Create
- Ramaze::Bin::Helper
- Ramaze::Bin::Restart
- Ramaze::Bin::Runner
- Ramaze::Bin::Start
- Ramaze::Bin::Status
- Ramaze::Bin::Stop
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Array
- Ramaze::CoreExtensions::Binding
- Ramaze::CoreExtensions::Kernel
- Ramaze::CoreExtensions::Numeric
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::Proc
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Dictionary
- Ramaze::Fiber
- Ramaze::Files
- Ramaze::GemSetup
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Disqus
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Ultraviolet
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Analogger
- Ramaze::Logger::Growl
- Ramaze::Logger::Informer
- Ramaze::Logger::Knotify
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logger::Xosd
- Ramaze::Logging
- Ramaze::MiddlewareCompiler
- Ramaze::Plugin
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::Struct
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- Fiber
- FiberError
- MainController
- Object
- OrderedSet
- Thread

No matching classes.

# 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

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

### Public Class Methods

new(model, callback) click to toggle source

    # File lib/ramaze/helper/user.rb, line 170
    def initialize(model, callback)
      @_model, @_callback = model, callback
      @_user = nil
      _login
    end

### Public Instance Methods

_logged_in?() click to toggle source

@return [true false] whether the current user is logged in. @api internal @see Ramaze::Helper::User#logged_in? @author manveru

    # File lib/ramaze/helper/user.rb, line 224
    def _logged_in?
      !!_user
    end

_login(creds = nil) click to toggle source

@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

@see Ramaze::Helper::User#user_login @author manveru

    # File lib/ramaze/helper/user.rb, line 183
    def _login(creds = nil)
      if creds
        if @_user = _would_login?(creds)
          Current.session.resid!
          self._persistence = {:credentials => creds}
        end
      elsif persistence = self._persistence
        @_user = _would_login?(persistence[:credentials])
      end
    end

_logout() click to toggle source

@api internal @see Ramaze::Helper::User#user_logout @author manveru

    # File lib/ramaze/helper/user.rb, line 215
    def _logout
      (_persistence || {}).clear
      Current.request.env['ramaze.helper.user'] = nil
    end

_persistence() click to toggle source

    # File lib/ramaze/helper/user.rb, line 232
    def _persistence
      Current.session[:USER]
    end

_persistence=(obj) click to toggle source

    # File lib/ramaze/helper/user.rb, line 228
    def _persistence=(obj)
      Current.session[:USER] = obj
    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 199
    def _would_login?(creds)
      return unless creds

      if c = @_callback
        c.call(creds)
      elsif _model.respond_to?(:authenticate)
        _model.authenticate(creds)
      else
        Log.warn("Helper::User has no callback and there is no %p::authenticate" % _model)
        nil
      end
    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 238
    def method_missing(meth, *args, &block)
      return unless _user
      _user.send(meth, *args, &block)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.