<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/merbful_authentication/controller/sessions_base.rb</filename>
    </added>
    <added>
      <filename>lib/merbful_authentication/controller/users_base.rb</filename>
    </added>
    <added>
      <filename>lib/merbful_authentication/slicetasks.rb</filename>
    </added>
    <added>
      <filename>spec/controllers/plugins/test_plugin.rb</filename>
    </added>
    <added>
      <filename>stubs/app/controllers/application.rb</filename>
    </added>
    <added>
      <filename>stubs/app/controllers/main.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -2,29 +2,6 @@ class MerbfulAuthentication::Sessions &lt; MerbfulAuthentication::Application
   
   skip_before :login_required
   
-  def new
-    render
-  end
 
-  def create
-    self.current_ma_user = MA[:user].authenticate(params[:email], params[:password])
-    if logged_in?
-      if params[:remember_me] == &quot;1&quot;
-        self.current_ma_user.remember_me
-        expires = Time.parse(self.current_ma_user.remember_token_expires_at.to_s)
-        cookies[:auth_token] = { :value =&gt; self.current_ma_user.remember_token , :expires =&gt; expires }
-      end
-      redirect_back_or_default('/')
-    else
-      render :new
-    end
-  end
-
-  def destroy
-    self.current_ma_user.forget_me if logged_in?
-    cookies.delete :auth_token
-    session.delete
-    redirect_back_or_default('/')
-  end
   
 end
\ No newline at end of file</diff>
      <filename>app/controllers/sessions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,39 +1,2 @@
 class MerbfulAuthentication::Users &lt; MerbfulAuthentication::Application
-  provides :xml
-  
-  skip_before :login_required
-
-  def new
-    only_provides :html
-    @ivar = MA[:user].new(params[:user] || {})
-    set_ivar
-    display @ivar
-  end
-  
-  def create
-    cookies.delete :auth_token
-    
-    @ivar = MA[:user].new(params[:user])
-    set_ivar
-    if @ivar.save
-      redirect_back_or_default('/')
-    else
-      render :new
-    end
-  end
-  
-  def activate
-    self.current_ma_user = MA[:user].find_with_conditions(:activation_code =&gt; params[:activation_code])
-    if logged_in? &amp;&amp; !current_ma_user.activated?
-      Merb.logger.info &quot;Activated #{current_ma_user}&quot;
-      current_ma_user.activate
-    end
-    redirect_back_or_default('/')
-  end
-  
-  private
-  def set_ivar
-    instance_variable_set(&quot;@#{MA[:single_user_name]}&quot;, @ivar)
-  end
-  
 end
\ No newline at end of file</diff>
      <filename>app/controllers/users.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,4 +4,4 @@ Your account has been created.
 
 Visit this url to activate your account:
 
-  &lt;%= url(MA[:routes][:activate], :activation_code =&gt; @ivar.activation_code) %&gt;
\ No newline at end of file
+  &lt;%= url(MA[:routes][:user][:activate], :activation_code =&gt; @ivar.activation_code) %&gt;
\ No newline at end of file</diff>
      <filename>app/mailers/views/user_mailer/signup.text.erb</filename>
    </modified>
    <modified>
      <diff>@@ -4,19 +4,18 @@ if defined?(Merb::Plugins)
   require 'merb-mailer'
   require 'merb_helpers'
   
-  require File.join(File.dirname(__FILE__), &quot;merbful_authentication&quot;, &quot;initializer&quot;)
+  load File.join(File.dirname(__FILE__), &quot;merbful_authentication&quot;, &quot;initializer.rb&quot;)
   
   Dir[File.dirname(__FILE__) / &quot;merbful_authentication&quot; / &quot;controller&quot; / &quot;**&quot; / &quot;*.rb&quot;].each do |f|
-    require f
+    load f
   end
   
   adapter_path = File.join( File.dirname(__FILE__), &quot;merbful_authentication&quot;, &quot;adapters&quot;)
+  load File.join(adapter_path,  &quot;common.rb&quot;)
   
   MA = MerbfulAuthentication
   MA.register_adapter :datamapper, &quot;#{adapter_path}/datamapper&quot;
   MA.register_adapter :activerecord, &quot;#{adapter_path}/activerecord&quot;
-
-  require File.join(adapter_path,  &quot;common&quot;)
   
   Merb::Plugins.add_rakefiles &quot;merbful_authentication/merbtasks&quot;
 
@@ -35,6 +34,11 @@ if defined?(Merb::Plugins)
   
   # All Slice code is expected to be namespaced inside a module
   module MerbfulAuthentication
+
+
+    def self.plugins
+      @@plugins ||= {}
+    end
     
     # Slice metadata
     self.description = &quot;MerbfulAuthentication is a Merb slice that provides authentication&quot;
@@ -47,12 +51,19 @@ if defined?(Merb::Plugins)
     # Loads the model class into MerbfulAuthentication[:user] for use elsewhere.
     def self.loaded
       MA.load_adapter!
-      Merb::Controller.send(:include, MA::ControllerMixin)
+      
+      Merb::Controller.send(:include, MA::Controller::Helpers)
+      # sends the methoods to the controllers as an include so that other mixins can
+      # overwrite them
+      MA::Users.send(     :include, MA::Controller::UsersBase)
+      MA::Sessions.send(  :include, MA::Controller::SessionsBase)
+      
       Merb::Controller.class_eval do
         alias_method :&quot;current_#{MA[:single_user_name]}&quot;, :current_ma_user
         alias_method :&quot;current_#{MA[:single_user_name]}=&quot;, :&quot;current_ma_user=&quot;
-      end
+      end      
       
+      MA.load_plugins!
     end
     
     # Initialization hook - runs before AfterAppLoads BootLoader
@@ -85,13 +96,13 @@ if defined?(Merb::Plugins)
       
       activation_name = (MA[:single_resource].to_s &lt;&lt; &quot;_activation&quot;).to_sym
       
-      MA[:routes] = {}
-      MA[:routes][:new]       = :&quot;new_#{single_model_name}&quot;
-      MA[:routes][:show]      = :&quot;#{single_model_name}&quot;
-      MA[:routes][:edit]      = :&quot;edit_#{single_model_name}&quot;
-      MA[:routes][:delete]    = :&quot;delete_#{single_model_name}&quot;
-      MA[:routes][:index]     = :&quot;#{plural_model_path}&quot;
-      MA[:routes][:activate]  = :&quot;#{single_model_name}_activation&quot;
+      MA[:routes] = {:user =&gt; {}}
+      MA[:routes][:user][:new]       = :&quot;new_#{single_model_name}&quot;
+      MA[:routes][:user][:show]      = :&quot;#{single_model_name}&quot;
+      MA[:routes][:user][:edit]      = :&quot;edit_#{single_model_name}&quot;
+      MA[:routes][:user][:delete]    = :&quot;delete_#{single_model_name}&quot;
+      MA[:routes][:user][:index]     = :&quot;#{plural_model_path}&quot;
+      MA[:routes][:user][:activate]  = :&quot;#{single_model_name}_activation&quot;
           
       # Setup the model path
       scope.to(:controller =&gt; &quot;Users&quot;) do |c|</diff>
      <filename>lib/merbful_authentication.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,111 +1,113 @@
 module MerbfulAuthentication
-  module ControllerMixin
-    protected
-      # Returns true or false if the user is logged in.
-      # Preloads @current_user with the user model if they're logged in.
-      def logged_in?
-        !!current_ma_user
-      end
+  module Controller
+    module Helpers
+      protected
+        # Returns true or false if the user is logged in.
+        # Preloads @current_user with the user model if they're logged in.
+        def logged_in?
+          !!current_ma_user
+        end
     
-      # Accesses the current user from the session.  Set it to :false if login fails
-      # so that future calls do not hit the database.
-      def current_ma_user
-        @current_ma_user ||= (login_from_session || login_from_basic_auth || login_from_cookie || false)
-      end
+        # Accesses the current user from the session.  Set it to :false if login fails
+        # so that future calls do not hit the database.
+        def current_ma_user
+          @current_ma_user ||= (login_from_session || login_from_basic_auth || login_from_cookie || false)
+        end
     
-      # Store the given user in the session.
-      def current_ma_user=(new_user)
-        session[:user] = (!new_user || !new_user.kind_of?(User)) ? nil : new_user.id
-        @current_ma_user = new_user
-      end
+        # Store the given user in the session.
+        def current_ma_user=(new_user)
+          session[:user] = (!new_user || !new_user.kind_of?(User)) ? nil : new_user.id
+          @current_ma_user = new_user
+        end
     
-      # Check if the user is authorized
-      #
-      # Override this method in your controllers if you want to restrict access
-      # to only a few actions or if you want to check if the user
-      # has the correct rights.
-      #
-      # Example:
-      #
-      #  # only allow nonbobs
-      #  def authorized?
-      #    current_user.login != &quot;bob&quot;
-      #  end
-      def authorized?
-        logged_in?
-      end
+        # Check if the user is authorized
+        #
+        # Override this method in your controllers if you want to restrict access
+        # to only a few actions or if you want to check if the user
+        # has the correct rights.
+        #
+        # Example:
+        #
+        #  # only allow nonbobs
+        #  def authorized?
+        #    current_user.login != &quot;bob&quot;
+        #  end
+        def authorized?
+          logged_in?
+        end
 
-      # Filter method to enforce a login requirement.
-      #
-      # To require logins for all actions, use this in your controllers:
-      #
-      #   before_filter :login_required
-      #
-      # To require logins for specific actions, use this in your controllers:
-      #
-      #   before_filter :login_required, :only =&gt; [ :edit, :update ]
-      #
-      # To skip this in a subclassed controller:
-      #
-      #   skip_before_filter :login_required
-      #
-      def login_required
-        authorized? || throw(:halt, :access_denied)
-      end
+        # Filter method to enforce a login requirement.
+        #
+        # To require logins for all actions, use this in your controllers:
+        #
+        #   before_filter :login_required
+        #
+        # To require logins for specific actions, use this in your controllers:
+        #
+        #   before_filter :login_required, :only =&gt; [ :edit, :update ]
+        #
+        # To skip this in a subclassed controller:
+        #
+        #   skip_before_filter :login_required
+        #
+        def login_required
+          authorized? || throw(:halt, :access_denied)
+        end
 
-      # Redirect as appropriate when an access request fails.
-      #
-      # The default action is to redirect to the login screen.
-      #
-      # Override this method in your controllers if you want to have special
-      # behavior in case the user is not authorized
-      # to access the requested action.  For example, a popup window might
-      # simply close itself.
-      def access_denied
-        case content_type
-        when :html
-          store_location
-          redirect url(:login)
-        when :xml
-          basic_authentication.request
+        # Redirect as appropriate when an access request fails.
+        #
+        # The default action is to redirect to the login screen.
+        #
+        # Override this method in your controllers if you want to have special
+        # behavior in case the user is not authorized
+        # to access the requested action.  For example, a popup window might
+        # simply close itself.
+        def access_denied
+          case content_type
+          when :html
+            store_location
+            redirect url(:login)
+          when :xml
+            basic_authentication.request
+          end
         end
-      end
     
-      # Store the URI of the current request in the session.
-      #
-      # We can return to this location by calling #redirect_back_or_default.
-      def store_location
-        session[:return_to] = request.uri
-      end
+        # Store the URI of the current request in the session.
+        #
+        # We can return to this location by calling #redirect_back_or_default.
+        def store_location
+          session[:return_to] = request.uri
+        end
     
-      # Redirect to the URI stored by the most recent store_location call or
-      # to the passed default.
-      def redirect_back_or_default(default)
-        loc = session[:return_to] || default
-        session[:return_to] = nil
-        redirect loc
-      end
+        # Redirect to the URI stored by the most recent store_location call or
+        # to the passed default.
+        def redirect_back_or_default(default)
+          loc = session[:return_to] || default
+          session[:return_to] = nil
+          redirect loc
+        end
 
-      # Called from #current_user.  First attempt to login by the user id stored in the session.
-      def login_from_session
-        self.current_user = MA[:user].find_with_conditions(:id =&gt; session[:user]) if session[:user]
-      end
+        # Called from #current_user.  First attempt to login by the user id stored in the session.
+        def login_from_session
+          self.current_user = MA[:user].find_with_conditions(:id =&gt; session[:user]) if session[:user]
+        end
 
-      # Called from #current_user.  Now, attempt to login by basic authentication information.
-      def login_from_basic_auth
-        basic_authentication.authenticate do |email, password|
-          self.current_ma_user = MA[:user].authenticate(email, password)
+        # Called from #current_user.  Now, attempt to login by basic authentication information.
+        def login_from_basic_auth
+          basic_authentication.authenticate do |email, password|
+            self.current_ma_user = MA[:user].authenticate(email, password)
+          end
         end
-      end
 
-      # Called from #current_user.  Finaly, attempt to login by an expiring token in the cookie.
-      def login_from_cookie     
-        user = cookies[:auth_token] &amp;&amp; MA[:user].find_with_conditions(:remember_token =&gt; cookies[:auth_token])
-        if user &amp;&amp; user.remember_token?
-          user.remember_me
-          cookies[:auth_token] = { :value =&gt; user.remember_token, :expires =&gt; Time.parse(user.remember_token_expires_at.to_s) }
-          self.current_ma_user = user
+        # Called from #current_user.  Finaly, attempt to login by an expiring token in the cookie.
+        def login_from_cookie     
+          user = cookies[:auth_token] &amp;&amp; MA[:user].find_with_conditions(:remember_token =&gt; cookies[:auth_token])
+          if user &amp;&amp; user.remember_token?
+            user.remember_me
+            cookies[:auth_token] = { :value =&gt; user.remember_token, :expires =&gt; Time.parse(user.remember_token_expires_at.to_s) }
+            self.current_ma_user = user
+          end
         end
-      end
-  end # Controller
+    end # Helpers
+  end# Controllers
 end # MerbfulAuthentication
\ No newline at end of file</diff>
      <filename>lib/merbful_authentication/controller/controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -38,4 +38,11 @@ module MerbfulAuthentication
     end
   end
   
+  def self.load_plugins!
+    self.plugins.each do |label, file|
+      Merb.logger.info &quot;Loading MerbfulAuthentication Plugin - #{label}&quot;
+      load file
+    end
+  end
+  
 end
\ No newline at end of file</diff>
      <filename>lib/merbful_authentication/initializer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,9 +7,7 @@ namespace :slices do
     task :install =&gt; [:preflight, :setup_directories, :copy_assets, :migrate]
     
     desc &quot;Test for any dependencies&quot;
-    task :preflight do
-      # implement this to test for structural/code dependencies
-      # like certain directories or availability of other files
+    task :preflight do # see slicetasks.rb
     end
   
     desc &quot;Setup directories&quot;
@@ -25,6 +23,18 @@ namespace :slices do
         end
       end
     end
+    
+    desc &quot;Copy stub files to host application&quot;
+    task :stubs do
+      puts &quot;Copying stubs for MerbfulAuthentication - resolves any collisions&quot;
+      copied, preserved = MerbfulAuthentication.mirror_stubs!
+      puts &quot;- no files to copy&quot; if copied.empty? &amp;&amp; preserved.empty?
+      copied.each { |f| puts &quot;- copied #{f}&quot; }
+      preserved.each { |f| puts &quot;! preserved override as #{f}&quot; }
+    end
+    
+    desc &quot;Copy stub files and views to host application&quot;
+    task :patch =&gt; [ &quot;stubs&quot;, &quot;freeze:views&quot; ]
   
     desc &quot;Copy public assets to host application&quot;
     task :copy_assets do
@@ -36,8 +46,7 @@ namespace :slices do
     end
     
     desc &quot;Migrate the database&quot;
-    task :migrate do
-      # implement this to perform any database related setup steps
+    task :migrate do # see slicetasks.rb
     end
     
     desc &quot;Freeze MerbfulAuthentication into your app (only merbful_authentication/app)&quot; </diff>
      <filename>lib/merbful_authentication/merbtasks.rb</filename>
    </modified>
    <modified>
      <diff>@@ -107,6 +107,37 @@ describe MerbfulAuthentication do
     
   end
 
+  describe &quot;controller Plugin loading&quot; do
+        
+    def add_test_plugin!
+      MA.plugins[&quot;Tester&quot;] = File.join(File.dirname(__FILE__), &quot;controllers&quot;, &quot;plugins&quot;, &quot;test_plugin.rb&quot;)
+    end
+    
+    before(:each) do
+      reload_ma!
+    end
+        
+    after(:all) do
+      reload_ma!
+    end
+    
+    it &quot;should allow for registration&quot; do
+      defined?(MA::Controller::Tester).should be_nil
+      reload_ma!(&quot;User&quot;){  add_test_plugin!}
+      defined?(MA::Controller::Tester).should_not be_nil
+      MA::Users.should include(MA::Controller::Tester)
+    end
+    
+    it &quot;should overwrite the new method&quot; do
+      Object.class_eval(&quot;class User; include MerbfulAuthentication::Adapter::DataMapper; end&quot;)
+      controller = dispatch_to(MA::Users, :new)
+      controller.body.should_not == &quot;NEW TEST&quot;
+      reload_ma!(&quot;User&quot;){ add_test_plugin!}
+      controller = dispatch_to(MA::Users, :new)
+      controller.body.should == &quot;NEW TEST&quot;      
+    end
+  end
+
 end
 
 describe &quot;MerbfulAuthentication (module)&quot; do</diff>
      <filename>spec/merbful_authentication_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -76,4 +76,22 @@ Spec::Runner.configure do |config|
 end
 
 
+# GLobal helpers for merbful_authentication
+def reload_ma!(create_class = nil)
+  Object.class_eval do
+    remove_const(&quot;User&quot;) if defined?(User)
+    remove_const(&quot;MA&quot;) if defined?(MA)
+    remove_const(&quot;MerbfulAuthentication&quot;)
+  end
+  load File.join(File.dirname(__FILE__), &quot;..&quot;, &quot;lib&quot;, &quot;merbful_authentication.rb&quot;)
+  register_datamapper!
+  stub_orm_scope
+  yield if block_given?
+  MA.load_slice
+  MA[:user] = nil
+  MA.loaded
+  Object.class_eval(&quot;class #{create_class}; include MerbfulAuthentication::Adapter::DataMapper; end&quot;) unless create_class.nil?
+end
+
+
 </diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c0568444db81320e2dba08395a0477501c0c8c81</id>
    </parent>
  </parents>
  <author>
    <name>Daniel Neighman</name>
    <email>has.sox@gmail.com</email>
  </author>
  <url>http://github.com/hassox/merbful_authentication/commit/d0f8c6d881ca762486c3daabdd65fa824197082d</url>
  <id>d0f8c6d881ca762486c3daabdd65fa824197082d</id>
  <committed-date>2008-06-02T06:53:55-07:00</committed-date>
  <authored-date>2008-06-02T06:53:55-07:00</authored-date>
  <message>Adds specs and methods to support controller plugins</message>
  <tree>f69302b359e0c3b36f64eedd48b4af621c1c0f26</tree>
  <committer>
    <name>Daniel Neighman</name>
    <email>has.sox@gmail.com</email>
  </committer>
</commit>
