merb_auth_slice_multisite 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/README.textile +147 -0
  2. data/VERSION.yml +4 -0
  3. data/app/controllers/application.rb +5 -0
  4. data/app/controllers/exceptions.rb +33 -0
  5. data/app/controllers/passwords.rb +29 -0
  6. data/app/controllers/sessions.rb +56 -0
  7. data/app/helpers/application_helper.rb +64 -0
  8. data/app/mailers/send_password_mailer.rb +11 -0
  9. data/app/mailers/views/send_password_mailer/send_password.text.erb +3 -0
  10. data/app/models/site.rb +26 -0
  11. data/app/views/exceptions/unauthenticated.html.erb +61 -0
  12. data/app/views/layout/merb_auth_slice_multisite.html.erb +16 -0
  13. data/config/database.yml +33 -0
  14. data/config/dependencies.rb +33 -0
  15. data/config/init.rb +84 -0
  16. data/config/router.rb +5 -0
  17. data/lib/merb-auth-more/strategies/multisite/multisite_password_form.rb +77 -0
  18. data/lib/merb-auth-remember-me/mixins/authenticated_user.rb +97 -0
  19. data/lib/merb-auth-remember-me/mixins/authenticated_user/dm_authenticated_user.rb +17 -0
  20. data/lib/merb-auth-remember-me/strategies/remember_me.rb +55 -0
  21. data/lib/merb_auth_slice_multisite.rb +107 -0
  22. data/lib/merb_auth_slice_multisite/merbtasks.rb +103 -0
  23. data/lib/merb_auth_slice_multisite/mixins/user_belongs_to_site.rb +63 -0
  24. data/lib/merb_auth_slice_multisite/mixins/user_belongs_to_site/dm_user_belongs_to_site.rb +28 -0
  25. data/lib/merb_auth_slice_multisite/slicetasks.rb +18 -0
  26. data/lib/merb_auth_slice_multisite/spectasks.rb +54 -0
  27. data/public/javascripts/master.js +0 -0
  28. data/public/stylesheets/master.css +2 -0
  29. data/spec/mailers/send_password_mailer_spec.rb +47 -0
  30. data/spec/mixins/authenticated_user_spec.rb +33 -0
  31. data/spec/mixins/user_belongs_to_site_spec.rb +56 -0
  32. data/spec/models/site_spec.rb +56 -0
  33. data/spec/spec_helper.rb +101 -0
  34. data/spec/strategies/remember_me_spec.rb +62 -0
  35. data/stubs/app/controllers/sessions.rb +19 -0
  36. data/stubs/app/views/exceptions/unauthenticated.html.erb +61 -0
  37. metadata +91 -0
@@ -0,0 +1,101 @@
1
+ require 'rubygems'
2
+ require 'merb-core'
3
+ require 'merb-slices'
4
+ require 'spec'
5
+ require 'dm-core'
6
+ require 'dm-validations'
7
+
8
+ # Add merb_auth_slice_multisite.rb to the search path
9
+ Merb::Plugins.config[:merb_slices][:auto_register] = true
10
+ Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'merb_auth_slice_multisite.rb')
11
+
12
+ # Require merb_auth_slice_multisite.rb explicitly so any dependencies are loaded
13
+ require Merb::Plugins.config[:merb_slices][:search_path]
14
+
15
+ # Using Merb.root below makes sure that the correct root is set for
16
+ # - testing standalone, without being installed as a gem and no host application
17
+ # - testing from within the host application; its root will be used
18
+ Merb.start_environment(
19
+ :testing => true,
20
+ :adapter => 'runner',
21
+ :environment => ENV['MERB_ENV'] || 'test',
22
+ :session_store => 'memory'
23
+ )
24
+
25
+ module Merb
26
+ module Test
27
+ module SliceHelper
28
+
29
+ # The absolute path to the current slice
30
+ def current_slice_root
31
+ @current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
32
+ end
33
+
34
+ # Whether the specs are being run from a host application or standalone
35
+ def standalone?
36
+ Merb.root == ::MerbAuthSliceMultisite.root
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+
43
+ class Merb::Mailer
44
+ self.delivery_method = :test_send
45
+ end
46
+
47
+ Spec::Runner.configure do |config|
48
+ config.include(Merb::Test::ViewHelper)
49
+ config.include(Merb::Test::RouteHelper)
50
+ config.include(Merb::Test::ControllerHelper)
51
+ config.include(Merb::Test::SliceHelper)
52
+
53
+ config.before(:all) do
54
+ DataMapper.auto_migrate! if Merb.orm == :datamapper
55
+ end
56
+ end
57
+
58
+ # You can add your own helpers here
59
+ #
60
+ Merb::Test.add_helpers do
61
+ def mount_slice
62
+ Merb::Router.prepare { add_slice(:MerbAuthSliceMultisite, "merb_auth_slice_multisite") } if standalone?
63
+ end
64
+
65
+ def dismount_slice
66
+ Merb::Router.reset! if standalone?
67
+ end
68
+ end
69
+
70
+ # =============================================================================
71
+ # SITE STUFF
72
+ # =============================================================================
73
+ def valid_site_attributes(options = {})
74
+ {
75
+ :subdomain => 'example'
76
+ }.merge(options)
77
+ end
78
+
79
+ def valid_second_site_attributes(options = {})
80
+ {
81
+ :subdomain => 'example2',
82
+ :active => true
83
+ }.merge(options)
84
+ end
85
+
86
+ def valid_third_site_attributes(options = {})
87
+ {
88
+ :subdomain => 'example3',
89
+ :active => true
90
+ }.merge(options)
91
+ end
92
+
93
+ # =============================================================================
94
+ # USER STUFF - see init.rb for where this gets spoofed
95
+ # =============================================================================
96
+ def valid_user_attributes(options = {})
97
+ { :login => 'fred',
98
+ :email => 'fred@example.com',
99
+ :site_id => 1
100
+ }.merge(options)
101
+ end
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Remember me strategy" do
4
+ def do_valid_login
5
+ put("/login", {:remember_me => "1", :pass_auth => true})
6
+ end
7
+
8
+ def do_valid_login_without_remember_me
9
+ put("/login", {:pass_auth => true})
10
+ end
11
+
12
+ def do_invalid_login
13
+ put("/login", { :pass_auth => false})
14
+ end
15
+
16
+ def do_home_with_auth_token
17
+ get("/", { :pass_auth => true} ) do |controller|
18
+ controller.request.cookies[:auth_token] = "auth_token_string"
19
+ end
20
+ end
21
+
22
+ before :each do
23
+ @user = mock(Merb::Authentication.user_class, :remember_me => true)
24
+ User.stub!(:first).and_return(@user)
25
+ @user.stub!(:remember_token?).and_return(true)
26
+ @user.stub!(:remember_token).and_return(Time.now + 1.week)
27
+ @user.stub!(:remember_token_expires_at).and_return(Time.now)
28
+ @user.stub!(:forget_me).and_return(true)
29
+ end
30
+
31
+ it "should save remember_token and remember_token_expires_at if remember_me == '1'" do
32
+ Merb::Authentication.user_class.should_receive(:first).and_return(@user)
33
+ @user.should_receive(:remember_me)
34
+ @user.remember_token.should_not be_nil
35
+ @user.remember_token_expires_at.should_not be_nil
36
+ do_valid_login.should redirect_to('/')
37
+ end
38
+
39
+ it "should not remember me unless remember_me == '1'" do
40
+ Merb::Authentication.user_class.should_receive(:first).and_return(true)
41
+ @user.should_not_receive(:remember_me)
42
+ do_valid_login_without_remember_me.should redirect_to('/')
43
+ end
44
+
45
+ it "should log in automatically if auth_token exists" do
46
+ Merb::Authentication.user_class.should_receive(:first).and_return(@user)
47
+ do_home_with_auth_token.should be_successful
48
+ end
49
+
50
+ it "should raise unauthenticated if auth_token doesn't exist" do
51
+ lambda do
52
+ do_invalid_login
53
+ end.should raise_error(Merb::Controller::Unauthenticated, "Could not log in")
54
+ end
55
+
56
+ it "should clear auth_token after loging out" do
57
+ delete('/logout') do |controller|
58
+ controller.cookies.should_receive(:delete).with(:auth_token)
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,19 @@
1
+ class MerbAuthSliceMultisite::Sessions < MerbAuthSliceMultisite::Application
2
+
3
+ after :redirect_after_login, :only => :update, :if => lambda{ !(300..399).include?(status) }
4
+ after :redirect_after_logout, :only => :destroy
5
+
6
+ private
7
+ # @overwritable
8
+ def redirect_after_login
9
+ message[:notice] = "Authenticated Successfully"
10
+ redirect_back_or "/", :message => message, :ignore => [slice_url(:login), slice_url(:logout)]
11
+ end
12
+
13
+ # @overwritable
14
+ def redirect_after_logout
15
+ message[:notice] = "Logged Out"
16
+ redirect "/", :message => message
17
+ end
18
+
19
+ end
@@ -0,0 +1,61 @@
1
+ <% @login_param = Merb::Authentication::Strategies::Multisite::Base.login_param %>
2
+ <% @password_param = Merb::Authentication::Strategies::Multisite::Base.password_param %>
3
+ <% @site_id_param = Merb::Authentication::Strategies::Multisite::Base.site_id_param %>
4
+ <%
5
+ # make @current_site value. application.rb does not get call
6
+ # because the authentication is protected at the rack level - which is better,
7
+ # but it means I have to add the following duplicate line of code as far as I know.
8
+ @current_site = Site.first(:subdomain => request.first_subdomain)
9
+ %>
10
+
11
+ <%= error_messages_for session.authentication %>
12
+ <form action="<%= slice_url(:merb_auth_slice_multisite, :perform_login) %>" method="post" id="loginForm">
13
+ <h3>Login</h3>
14
+ <input type="hidden" name="<%= @site_id_param.to_s %>" value="<%= @current_site.id %>" id="<%= @site_id_param.to_s %>">
15
+ <input type="hidden" name="_method" value="PUT" />
16
+
17
+ <div id="loginFields" class="fields">
18
+ <div id="loginElements" class="elements">
19
+ <label for="<%= @login_param.to_s %>"><%= @login_param.to_s.capitalize %>:</label>
20
+ <div id="loginElement" class="element">
21
+ <input type="text" name="<%= @login_param.to_s %>" value="" id="<%= @login_param.to_s %>">
22
+ </div>
23
+ </div>
24
+ <div id="passwordElements" class="elements">
25
+ <label for="<%= @password_param.to_s %>"><%= @password_param.to_s.capitalize %>:</label>
26
+ <div id="passwordElement" class="element">
27
+ <input type="password" name="<%= @password_param.to_s %>" value="" id="<%= @password_param.to_s %>">
28
+ </div>
29
+ </div>
30
+ <div id="remember_meElements" class="elements">
31
+ <div id="remember_meElement" class="element">
32
+ <input type="checkbox" name="remember_me" value="1" id="remember_me" /> <label for="remember_me">Remember me</label>
33
+ </div>
34
+ </div>
35
+ <div id="loginActions" class="actions">
36
+ <div id="loginAction" class="action">
37
+ <input type="submit" name="loginSubmit" value="Log In" id="loginSubmit" />
38
+ </div>
39
+ <div id="forgotToggleAction" class="action">
40
+ <a href="#" id="forgotToggle">Forgot password</a>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </form>
45
+
46
+ <form action="<%= slice_url(:merb_auth_slice_multisite, :send_password) %>" method="post" id="forgotForm">
47
+ <input type="hidden" name="<%= @site_id_param.to_s %>" value="<%= @current_site.id %>" id="<%= @site_id_param.to_s %>">
48
+ <div id="forgotFields" class="fields">
49
+ <div id="forgotLoginElements" class="elements">
50
+ <label for="<%= @login_param.to_s %>"><%= @login_param.to_s.capitalize %>:</label>
51
+ <div id="forgotLoginElement" class="element">
52
+ <input type="text" class="text" name="<%= @login_param.to_s %>" id="<%= @login_param.to_s %>" />
53
+ </div>
54
+ </div>
55
+ <div id="forgotLoginActions" class="actions">
56
+ <div id="forgotLoginAction" class="action">
57
+ <input type="submit" name="forgotLoginSubmit" value="Reset Password" id="forgotLoginSubmit" />
58
+ </div>
59
+ </div>
60
+ </div>
61
+ </form>
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb_auth_slice_multisite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.6
5
+ platform: ruby
6
+ authors:
7
+ - scottmotte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-09 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: scott@scottmotte.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.textile
26
+ - VERSION.yml
27
+ - lib/merb-auth-more/strategies/multisite/multisite_password_form.rb
28
+ - lib/merb-auth-remember-me/mixins/authenticated_user/dm_authenticated_user.rb
29
+ - lib/merb-auth-remember-me/mixins/authenticated_user.rb
30
+ - lib/merb-auth-remember-me/strategies/remember_me.rb
31
+ - lib/merb_auth_slice_multisite/merbtasks.rb
32
+ - lib/merb_auth_slice_multisite/mixins/user_belongs_to_site/dm_user_belongs_to_site.rb
33
+ - lib/merb_auth_slice_multisite/mixins/user_belongs_to_site.rb
34
+ - lib/merb_auth_slice_multisite/slicetasks.rb
35
+ - lib/merb_auth_slice_multisite/spectasks.rb
36
+ - lib/merb_auth_slice_multisite.rb
37
+ - spec/mailers/send_password_mailer_spec.rb
38
+ - spec/mixins/authenticated_user_spec.rb
39
+ - spec/mixins/user_belongs_to_site_spec.rb
40
+ - spec/models/site_spec.rb
41
+ - spec/spec_helper.rb
42
+ - spec/strategies/remember_me_spec.rb
43
+ - app/controllers/application.rb
44
+ - app/controllers/exceptions.rb
45
+ - app/controllers/passwords.rb
46
+ - app/controllers/sessions.rb
47
+ - app/helpers/application_helper.rb
48
+ - app/mailers/send_password_mailer.rb
49
+ - app/mailers/views/send_password_mailer/send_password.text.erb
50
+ - app/models/site.rb
51
+ - app/views/exceptions/unauthenticated.html.erb
52
+ - app/views/layout/merb_auth_slice_multisite.html.erb
53
+ - config/database.yml
54
+ - config/dependencies.rb
55
+ - config/init.rb
56
+ - config/router.rb
57
+ - public/javascripts/master.js
58
+ - public/stylesheets/master.css
59
+ - stubs/app/controllers/sessions.rb
60
+ - stubs/app/views/exceptions/unauthenticated.html.erb
61
+ has_rdoc: true
62
+ homepage: http://github.com/scottmotte/merb_auth_slice_multisite
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --inline-source
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: add multisite/subdomain functionality to your merb app on top of merb-auth
90
+ test_files: []
91
+