public
Fork of mleung/feather
Description: The simplest blog that works. Make sure you check out the feather-plugins repo as well!
Clone URL: git://github.com/bond/feather.git
Added role support:
  - role-field in User-model (String / default Nil)
  - first user gets role "admin"
  - admin dashboard requires role "admin"
  - added admin? and admin_required -methods
Daniel Bond (author)
Wed Jul 16 21:24:43 -0700 2008
commit  6ce3a667d8add88cca0457300dbbcf3e13be29c5
tree    7d8a0f4d0c41f8168b63483f28fa923524fd3756
parent  25a0b3710ed0bafdfadd10ec29030f0aa76efc4f
...
13
14
15
16
 
17
18
19
20
 
21
22
23
...
13
14
15
 
16
17
18
19
 
20
21
22
23
0
@@ -13,11 +13,11 @@ module Admin
0
       # This checks to see if there are no users (such as when it's a fresh install) - if so, it creates a default user and redirects the user to login with those details
0
       def check_for_user
0
         if User.count == 0
0
- User.create({:login => "admin", :password => "password", :password_confirmation => "password", :name => 'blog owner', :email => "none@none", :time_zone => "Europe/London"})
0
+ User.create({:login => "admin", :password => "password", :password_confirmation => "password", :role => 'admin', :name => 'blog owner', :email => "none@none", :time_zone => "Europe/London"})
0
           # Display the newly created users details
0
           notify "No users found, so default user created: authenticate with login \"admin\", password \"password\", and then change your password."
0
         end
0
- login_required
0
+ admin_required
0
       end
0
   end
0
 end
...
16
17
18
 
19
20
21
...
16
17
18
19
20
21
22
0
@@ -16,6 +16,7 @@ class User
0
   property :email, String, :length => 255
0
   property :crypted_password, String
0
   property :salt, String
0
+ property :role, String
0
   property :remember_token_expires_at, DateTime
0
   property :remember_token, String
0
   property :time_zone, String
...
34
35
36
 
 
 
 
 
 
 
37
38
39
...
52
53
54
 
 
 
 
55
56
57
...
34
35
36
37
38
39
40
41
42
43
44
45
46
...
59
60
61
62
63
64
65
66
67
68
0
@@ -34,6 +34,13 @@ module AuthenticatedSystem
0
       def authorized?
0
         logged_in?
0
       end
0
+
0
+ def admin?
1
+ :false
0
+ if logged_in?
0
+ @current_user.role == "admin"
0
+ end
0
+ end
0
 
0
       # Filter method to enforce a login requirement.
0
       #
0
@@ -52,6 +59,10 @@ module AuthenticatedSystem
0
       def login_required
0
         authorized? || throw(:halt, :access_denied)
0
       end
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