public
Fork of hassox/merb-auth
Description: Merbful Authentication.. In Slice Form
Homepage:
Clone URL: git://github.com/bond/merb-auth.git
Added support for user-roles
  - added role-field to schemas
  - added admin? and admin_required methods

For more info, see ticket at lighthouseapp/feather: 
http://feather.lighthouseapp.com/projects/10532/tickets/21-support-for-non-admin
-users-roles#ticket-21-4
Daniel Bond (author)
Sat Jul 19 19:21:04 -0700 2008
commit  22381302ea7b1ca783f7c6509ee2024af0782f80
tree    2045a99f0bf8477166a9f7a773d8a12ef2f8403d
parent  925b8710a4fe5144eadb53bd016b315378a29797
...
3
4
5
 
6
7
8
...
3
4
5
6
7
8
9
0
@@ -3,6 +3,7 @@ class AddMaUser < ActiveRecord::Migration
0
     create_table "<%= table_name %>", :force => true do |t|
0
       t.column :login,                      :string
0
       t.column :email,                      :string
0
+      t.column :role,                       :string, :limit => 40
0
       t.column :crypted_password,           :string, :limit => 40
0
       t.column :salt,                       :string, :limit => 40
0
       t.column :created_at,                 :datetime
...
4
5
6
 
7
8
9
...
4
5
6
7
8
9
10
0
@@ -4,6 +4,7 @@ migration 1, :create_ma_users_table do
0
       column :id,                         Integer,  :serial   => true
0
       column :login,                      String,   :nullable? => false
0
       column :email,                      String,   :nullable? => false
0
+      column :role,                       String
0
       column :created_at,                 DateTime
0
       column :updated_at,                 DateTime
0
       column :activated_at,               DateTime
...
42
43
44
 
45
46
47
...
42
43
44
45
46
47
48
0
@@ -42,6 +42,7 @@ module MerbAuth
0
             property :id,                         Integer,  :serial   => true
0
             property :login,                      String,   :nullable => false, :length => 3..40, :unique => true
0
             property :email,                      String,   :nullable => false, :unique => true
0
+            property :role,                       String
0
             property :created_at,                 DateTime
0
             property :updated_at,                 DateTime
0
             property :activated_at,               DateTime
...
35
36
37
 
 
 
 
 
38
39
40
...
53
54
55
 
 
 
 
 
 
 
 
 
 
 
 
56
57
58
...
35
36
37
38
39
40
41
42
43
44
45
...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
0
@@ -35,6 +35,11 @@ module MerbAuth
0
         def authorized?
0
           logged_in?
0
         end
0
+        
0
+        def admin?
0
+          return false unless(logged_in?)
0
+          @current_ma_user.role == 'admin'
0
+        end
0
 
0
         # Filter method to enforce a login requirement.
0
         #
0
@@ -53,6 +58,18 @@ module MerbAuth
0
         def login_required
0
           authorized? || throw(:halt, :access_denied)
0
         end
0
+        
0
+        # Filter method to enforce a login with admin role
0
+        #
0
+        # To require admin for all actions, use this in your controllers:
0
+        #
0
+        # before_filter :admin_required
0
+        #
0
+        # See also login_required method for more info on usage.
0
+        #
0
+        def admin_required
0
+          admin? || throw(:halt, :access_denied)
0
+        end
0
 
0
         # Redirect as appropriate when an access request fails.
0
         #

Comments