Module: MerbAuthSliceMultisite

Defined in:
lib/merb_auth_slice_multisite.rb

Overview

All Slice code is expected to be namespaced inside a module

Defined Under Namespace

Modules: ExceptionsMixin Classes: Application, Passwords, SendPasswordMailer, Sessions

Class Method Summary collapse

Class Method Details

.activateObject

Activation hook - runs after AfterAppLoads BootLoader



65
66
# File 'lib/merb_auth_slice_multisite.rb', line 65

def self.activate
end

.deactivateObject

Deactivation hook - triggered by Merb::Slices.deactivate(MerbAuthSliceMultisite)



69
70
# File 'lib/merb_auth_slice_multisite.rb', line 69

def self.deactivate
end

.initObject

Initialization hook - runs before AfterAppLoads BootLoader



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/merb_auth_slice_multisite.rb', line 40

def self.init
  require 'merb-auth-more/mixins/redirect_back'      
  unless MerbAuthSliceMultisite[:no_default_strategies]
    # Register the custom strategy so that this slice may utilize it
    # from http://github.com/wycats/merb/blob/784ac7d71780d1a7cfb9152ba4cb0
    # e18a990ab7a/merb-auth/merb-auth-more/lib/merb-auth-more.rb
    merb_auth_more_path = File.expand_path(File.dirname(__FILE__)) / "merb-auth-more" / "strategies" / "multisite"
    merb_auth_remember_me_path = File.expand_path(File.dirname(__FILE__)) / "merb-auth-remember-me" / "strategies"
    Merb::Authentication.register(:multisite_password_form, merb_auth_more_path / "multisite_password_form.rb")
    Merb::Authentication.register(:remember_me, merb_auth_remember_me_path / "remember_me.rb")
    # activate the strategies
    ::Merb::Authentication.activate!(:multisite_password_form)
    ::Merb::Authentication.activate!(:remember_me)
    
    Merb::Authentication.after_authentication do |user,request,params|
      if params[:remember_me] == "1" 
        user.remember_me
        request.cookies.set_cookie(:auth_token, user.remember_token, :expires => user.remember_token_expires_at.to_time)
      end
      user
    end # Merb::Authentication.after_authentication
  end
end

.loadedObject

Stub classes loaded hook - runs before LoadClasses BootLoader right after a slice’s classes have been loaded internally.



36
37
# File 'lib/merb_auth_slice_multisite.rb', line 36

def self.loaded
end

.setup_router(scope) ⇒ Object

Note:

prefix your named routes with :merb_auth_slice_multisite_ to avoid potential conflicts with global named routes.

Setup routes inside the host application

Parameters:

  • scope (Merb::Router::Behaviour)

    Routes will be added within this scope (namespace). In fact, any router behaviour is a valid namespace, so you can attach routes at any level of your router setup.



81
82
83
84
85
86
# File 'lib/merb_auth_slice_multisite.rb', line 81

def self.setup_router(scope)
  scope.match("/send_password", :method => :post).to(:controller => "passwords", :action => "send_password").name(:send_password)
  scope.match("/login", :method => :get ).to(:controller => "/exceptions", :action => "unauthenticated").name(:login)
  scope.match("/login", :method => :put ).to(:controller => "sessions", :action => "update").name(:perform_login)
  scope.match("/logout").to(:controller => "sessions", :action => "destroy").name(:logout)
end