scottmotte-merb-auth-slice-multisite 0.0.1 → 0.1.0

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 (4) hide show
  1. data/README.textile +117 -0
  2. data/VERSION.yml +2 -2
  3. metadata +3 -3
  4. data/README.rdoc +0 -7
data/README.textile ADDED
@@ -0,0 +1,117 @@
1
+ h1. MerbAuthSliceMultisite
2
+
3
+ This slice setups multisite capabilities in your merb application with an authentication check.
4
+
5
+ It works for subdomains (i.e. coolcars.yourapp.com) or for domains routed to your application via your server (i.e. coolcars.com).
6
+
7
+ It has a check to make a user to the site he's trying to login to. If the user does not match than authentication fails.
8
+
9
+ h2. Instructions for installation:
10
+
11
+ 0. Check out the video. <a href="http://scottmotte.github.com/merb-auth-slice-multisite/">How to install merb-auth-slice-multisite in your application.</a>
12
+
13
+ 1. Download the gem and install.
14
+ <pre><code># from your terminal
15
+ cd ~
16
+ mkdir sources
17
+ cd ~/sources
18
+ git clone git@github.com:scottmotte/merb-auth-slice-multisite.git
19
+ cd merb-auth-slice-multisite
20
+ sudo rake install
21
+ </code></pre>
22
+
23
+ 2. Setup your application to use the gem.* Add the following to the end of dependencies.rb.
24
+ <pre><code>dependency "merb-auth-slice-multisite", "0.2"</code></pre>
25
+
26
+ 3. Add in mixin. In your user model or in merb/merb-auth/setup.rb add the mixin
27
+ include Merb::Authentication::Mixins::UserBelongsToSite and then migrate your database.
28
+ <pre><code>
29
+ # in model
30
+ class User
31
+ include Merb::Authentication::Mixins::UserBelongsToSite
32
+ end
33
+
34
+ # or as I prefer in merb/merb-auth/setup.rb
35
+ Merb::Authentication.user_class.class_eval{
36
+ include Merb::Authentication::Mixins::SaltedUser
37
+ include Merb::Authentication::Mixins::ActivatedUser
38
+ include Merb::Authentication::Mixins::UserBelongsToSite # <-- this one
39
+ }
40
+ </code></pre>
41
+
42
+ _Don't forget to migrate your database schema with rake db:autoupgrade or rake db:automigrate_
43
+
44
+
45
+ 4. Setup @current_site value. I haven't worked out how to make it automatically accessible yet so for now I just paste the following into my app's application.rb file.
46
+ <pre><code>
47
+ before :get_site
48
+ def get_site
49
+ # uses @current_site to create pages under appropriate site like @current_site.pages.new
50
+ # if there is a subdomain then fetch from subdomain, otherwise fetch from domain
51
+ if request.first_subdomain != nil
52
+ @current_site = Site.first(:subdomain => request.first_subdomain)
53
+ else
54
+ @current_site = Site.first(:domain => request.domain)
55
+ end
56
+ end
57
+ </pre></code>
58
+
59
+ h2. Additional details:
60
+
61
+ Schema/Migrations. The mixin requires some fields to be in-place in your user model. Where needed include these in your migrations.
62
+ <pre><code># Relationships/Associations
63
+ belongs_to :site
64
+ property :site_id, Integer
65
+ validates_is_unique :login, :scope => :site_id
66
+ </code></pre>
67
+
68
+ Site model. You're probably wondering where the heck is the site model. It's in the slice. You can override it by running one of the rake tasks or you can create your own site.rb model and add additional fields. For example, if you have pages under a site, you might do something like:
69
+ <pre><code># site.rb
70
+ class Site
71
+ has n, :pages, :order => [:position.asc]
72
+ end
73
+ </code></pre>
74
+
75
+ @current_site. You can use @current_site in your controllers like so:
76
+ <pre><code>
77
+ class Pages < Application
78
+ # provides :xml, :yaml, :js
79
+
80
+ def index
81
+ @pages = @current_site.pages.all
82
+ display @pages
83
+ end
84
+
85
+ def show(id)
86
+ @page = @current_site.pages.get(id)
87
+ raise NotFound unless @page
88
+ display @page
89
+ end
90
+
91
+ end # Pages
92
+ </pre></code>
93
+
94
+
95
+ h2. Assumptions
96
+
97
+ * works for subdomains (i.e. coolcars.yourapp.com) or for domains routed to your application via your server (i.e. coolcars.com). see lines 40-55 in lib/merb-auth-slice-multisite.rb and lib/merb-auth-slice-multisite/mixins/user_belongs_to_site/dm_user_belongs_to_site.rb for details
98
+ * merb only
99
+ * merb-auth-core dependency
100
+ * merb-auth-more dependency
101
+ * *only supports datamapper so far* (help me extend it! fork the project and request me to pull)
102
+ * A site has n (has_many) users. A user belongs_to a site.
103
+ * You can have multiple users with the same username and password as long as they each belong_to a different site. For example, there can be an admin user with the credentials { :login => 'admin', :email => 'admin@example.org', :site_id => 1} and an admin user with the credentials { :login => 'admin', :email => 'admin@example.org', :site_id => 66}. As long as the site_id is different then it is ok. This allows more freedom when your users want to setup multiple sites.
104
+
105
+
106
+ h2. How does it work?
107
+
108
+ When logging in the "user" object found by merb-auth-core will be asked whether the user's site_id matches the id of the current_site. It user merb-auth's after_authentication method to do this.
109
+
110
+ The current_site is queried by using a model lookup off the request variable.
111
+
112
+
113
+ h2. Rake tasks
114
+
115
+ To see all available tasks for MerbAuthSliceMultisite run:
116
+
117
+ rake -T slices:merb-auth-slice-multisite
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 0
4
- :patch: 1
3
+ :minor: 1
4
+ :patch: 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scottmotte-merb-auth-slice-multisite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - scottmotte
@@ -20,10 +20,10 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README.rdoc
23
+ - README.textile
24
24
  - LICENSE
25
25
  files:
26
- - README.rdoc
26
+ - README.textile
27
27
  - VERSION.yml
28
28
  - lib/merb-auth-slice-multisite
29
29
  - lib/merb-auth-slice-multisite/merbtasks.rb
data/README.rdoc DELETED
@@ -1,7 +0,0 @@
1
- = merb-auth-slice-multisite
2
-
3
- Description goes here.
4
-
5
- == Copyright
6
-
7
- Copyright (c) 2009 scottmotte. See LICENSE for details.