authcan_easyroller 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +40 -31
- data/VERSION +1 -1
- data/authcan_easyroller.gemspec +6 -5
- data/examples/ability.rb +41 -0
- data/examples/application.html.erb +40 -0
- data/examples/main.css +41 -0
- data/lib/authcan_easyroller.rb +2 -2
- metadata +6 -5
- data/example/ability.rb +0 -41
- data/example/application.html.erb +0 -40
- data/example/main.css +0 -41
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -60,9 +60,18 @@ planned enhancements so you can get a feel of where this project will go.
|
|
60
60
|
|
61
61
|
== Installation/Setup
|
62
62
|
|
63
|
-
|
63
|
+
Assuming you already have Rails 3 installed, installation is very simple; just install the gem and
|
64
|
+
it's dependencies!
|
64
65
|
|
65
|
-
gem install
|
66
|
+
gem install authlogic cancan easy_roles authcan_easyroller
|
67
|
+
|
68
|
+
Next, add the dependencies to your <tt>Gemfile</tt>:
|
69
|
+
|
70
|
+
|
71
|
+
gem "authlogic"
|
72
|
+
gem "cancan"
|
73
|
+
gem "easy_roles"
|
74
|
+
gem "authcan_easyroller"
|
66
75
|
|
67
76
|
Next, create a migration for the users:
|
68
77
|
|
@@ -70,36 +79,36 @@ Next, create a migration for the users:
|
|
70
79
|
|
71
80
|
Then, copy the following contents into that file making any changes you see fit:
|
72
81
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
82
|
+
class CreateUsers < ActiveRecord::Migration
|
83
|
+
def self.up
|
84
|
+
create_table :users do |t|
|
85
|
+
# Necessary Columns - These are required for AuthcanEasyroller to function properly
|
86
|
+
t.string :email, :null => false
|
87
|
+
t.string :crypted_password, :null => false
|
88
|
+
t.string :password_salt, :null => false
|
89
|
+
t.string :persistence_token, :null => false
|
90
|
+
t.string :single_access_token, :null => false
|
91
|
+
t.string :perishable_token, :null => false
|
92
|
+
t.integer :roles_mask, :null => false, :default => 0
|
84
93
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
94
|
+
# Magic Columns - You may leave any of the following out if you wish
|
95
|
+
t.integer :login_count, :null => false, :default => 0
|
96
|
+
t.integer :failed_login_count, :null => false, :default => 0
|
97
|
+
t.datetime :last_request_at
|
98
|
+
t.datetime :current_login_at
|
99
|
+
t.datetime :last_login_at
|
100
|
+
t.string :current_login_ip
|
101
|
+
t.string :last_login_ip
|
93
102
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
+
# Timestamp Columns - You should have these on every database table you create
|
104
|
+
t.timestamps
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.down
|
109
|
+
drop_table :users
|
110
|
+
end
|
111
|
+
end
|
103
112
|
|
104
113
|
Once saved, migrate your database by running
|
105
114
|
|
@@ -214,4 +223,4 @@ I would like to thank the creators of Authlogic, CanCan and Easy Roles for the e
|
|
214
223
|
into these plugins. Adding them together was relatively straightforward and easy and I hope that they
|
215
224
|
realize how much time this saves other developers!
|
216
225
|
|
217
|
-
Copyright (c) 2010 Topher Fangio
|
226
|
+
Copyright (c) 2009-2010 Topher Fangio
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/authcan_easyroller.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{authcan_easyroller}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Topher Fangio"]
|
@@ -37,9 +37,9 @@ Gem::Specification.new do |s|
|
|
37
37
|
"app/views/users/show.html.erb",
|
38
38
|
"authcan_easyroller.gemspec",
|
39
39
|
"config/routes.rb",
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
40
|
+
"examples/ability.rb",
|
41
|
+
"examples/application.html.erb",
|
42
|
+
"examples/main.css",
|
43
43
|
"lib/authcan_easyroller.rb",
|
44
44
|
"test/helper.rb",
|
45
45
|
"test/test_authcan_easyroller.rb"
|
@@ -51,7 +51,8 @@ Gem::Specification.new do |s|
|
|
51
51
|
s.summary = %q{Rails 3 engine for user authentication/authorization utilizing Authlogic, CanCan and EasyRoles}
|
52
52
|
s.test_files = [
|
53
53
|
"test/helper.rb",
|
54
|
-
"test/test_authcan_easyroller.rb"
|
54
|
+
"test/test_authcan_easyroller.rb",
|
55
|
+
"examples/ability.rb"
|
55
56
|
]
|
56
57
|
|
57
58
|
if s.respond_to? :specification_version then
|
data/examples/ability.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class Ability
|
2
|
+
include CanCan::Ability
|
3
|
+
|
4
|
+
def initialize(current_user)
|
5
|
+
can :read, :all
|
6
|
+
can :manage, UserSession
|
7
|
+
|
8
|
+
if current_user
|
9
|
+
# Abilities for someone with an account (does not necessarily have a "user" role)
|
10
|
+
can [:update, :destroy], User do |user|
|
11
|
+
user == current_user
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# User role abilities
|
16
|
+
if current_user.is_user?
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# Moderator role abilities
|
21
|
+
if current_user.is_moderator?
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# Admin role abilities
|
26
|
+
if current_user.is_admin?
|
27
|
+
can :manage, :all
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# Developer role abilities
|
32
|
+
if current_user.is_developer?
|
33
|
+
can :manage, :all
|
34
|
+
end
|
35
|
+
else
|
36
|
+
can :create, User
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<script src="http://www.google.com/jsapi"></script>
|
4
|
+
<script>google.load("jquery", "1.4");</script>
|
5
|
+
|
6
|
+
<%= stylesheet_link_tag 'main' %>
|
7
|
+
</head>
|
8
|
+
|
9
|
+
<body>
|
10
|
+
<div id='navigation'>
|
11
|
+
<%= link_to "Users", users_path %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div id='userland'>
|
15
|
+
<% if current_user %>
|
16
|
+
Welcome <%= current_user.email %>!
|
17
|
+
|
18
|
+
<%= link_to "My Account", user_path(current_user) %>
|
19
|
+
<%= link_separator %>
|
20
|
+
<%= link_to "Logout", '/user_sessions/destroy' %>
|
21
|
+
<% else %>
|
22
|
+
You are not currently
|
23
|
+
<%= link_to "logged in", new_user_session_path %>.
|
24
|
+
<% end %>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div id='flashes'>
|
28
|
+
<%= raw "<h5 class='flash error'>#{flash[:error]}</h5>" unless flash[:error].blank? %>
|
29
|
+
<%= raw "<h5 class='flash notice'>#{flash[:notice]}</h5>" unless flash[:notice].blank? %>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<div id='content'>
|
33
|
+
<%= yield %>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id='copyright'>
|
37
|
+
Copyright © 2010, MyCompany. All rights reserved.
|
38
|
+
</div>
|
39
|
+
</body>
|
40
|
+
</html>
|
data/examples/main.css
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#navigation {
|
2
|
+
float: left;
|
3
|
+
margin-bottom: 10px;
|
4
|
+
}
|
5
|
+
|
6
|
+
#userland {
|
7
|
+
float: right;
|
8
|
+
margin-bottom: 10px;
|
9
|
+
}
|
10
|
+
|
11
|
+
#flashes {
|
12
|
+
clear: both;
|
13
|
+
}
|
14
|
+
|
15
|
+
#content {
|
16
|
+
margin: 10px;
|
17
|
+
}
|
18
|
+
|
19
|
+
#copyright {
|
20
|
+
text-align: center;
|
21
|
+
}
|
22
|
+
|
23
|
+
.flash {
|
24
|
+
border: 1px solid #000000;
|
25
|
+
padding: 10px;
|
26
|
+
}
|
27
|
+
|
28
|
+
.flash.error {
|
29
|
+
}
|
30
|
+
|
31
|
+
.flash.notice {
|
32
|
+
}
|
33
|
+
|
34
|
+
label {
|
35
|
+
font-weight: bold;
|
36
|
+
}
|
37
|
+
|
38
|
+
input[type=text],input[type=password],select,textarea {
|
39
|
+
clear: both;
|
40
|
+
display: block;
|
41
|
+
}
|
data/lib/authcan_easyroller.rb
CHANGED
@@ -13,8 +13,8 @@ module AuthcanEasyroller
|
|
13
13
|
#
|
14
14
|
# Bug here: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3928
|
15
15
|
#
|
16
|
-
app.config.filter_parameters << :password
|
17
|
-
app.config.filter_parameters << :password_confirmation
|
16
|
+
# app.config.filter_parameters << :password
|
17
|
+
# app.config.filter_parameters << :password_confirmation
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Topher Fangio
|
@@ -59,9 +59,9 @@ files:
|
|
59
59
|
- app/views/users/show.html.erb
|
60
60
|
- authcan_easyroller.gemspec
|
61
61
|
- config/routes.rb
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
62
|
+
- examples/ability.rb
|
63
|
+
- examples/application.html.erb
|
64
|
+
- examples/main.css
|
65
65
|
- lib/authcan_easyroller.rb
|
66
66
|
- test/helper.rb
|
67
67
|
- test/test_authcan_easyroller.rb
|
@@ -98,3 +98,4 @@ summary: Rails 3 engine for user authentication/authorization utilizing Authlogi
|
|
98
98
|
test_files:
|
99
99
|
- test/helper.rb
|
100
100
|
- test/test_authcan_easyroller.rb
|
101
|
+
- examples/ability.rb
|
data/example/ability.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
class Ability
|
2
|
-
include CanCan::Ability
|
3
|
-
|
4
|
-
def initialize(current_user)
|
5
|
-
can :read, :all
|
6
|
-
can :manage, UserSession
|
7
|
-
|
8
|
-
if current_user
|
9
|
-
# Abilities for someone with an account (does not necessarily have a "user" role)
|
10
|
-
can [:update, :destroy], User do |user|
|
11
|
-
user == current_user
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
# User role abilities
|
16
|
-
if current_user.is_user?
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
# Moderator role abilities
|
21
|
-
if current_user.is_moderator?
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
# Admin role abilities
|
26
|
-
if current_user.is_admin?
|
27
|
-
can :manage, :all
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
# Developer role abilities
|
32
|
-
if current_user.is_developer?
|
33
|
-
can :manage, :all
|
34
|
-
end
|
35
|
-
else
|
36
|
-
can :create, User
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<script src="http://www.google.com/jsapi"></script>
|
4
|
-
<script>google.load("jquery", "1.4");</script>
|
5
|
-
|
6
|
-
<%= stylesheet_link_tag 'main' %>
|
7
|
-
</head>
|
8
|
-
|
9
|
-
<body>
|
10
|
-
<div id='navigation'>
|
11
|
-
<%= link_to "Users", users_path %>
|
12
|
-
</div>
|
13
|
-
|
14
|
-
<div id='userland'>
|
15
|
-
<% if current_user %>
|
16
|
-
Welcome <%= current_user.email %>!
|
17
|
-
|
18
|
-
<%= link_to "My Account", user_path(current_user) %>
|
19
|
-
<%= link_separator %>
|
20
|
-
<%= link_to "Logout", '/user_sessions/destroy' %>
|
21
|
-
<% else %>
|
22
|
-
You are not currently
|
23
|
-
<%= link_to "logged in", new_user_session_path %>.
|
24
|
-
<% end %>
|
25
|
-
</div>
|
26
|
-
|
27
|
-
<div id='flashes'>
|
28
|
-
<%= raw "<h5 class='flash error'>#{flash[:error]}</h5>" unless flash[:error].blank? %>
|
29
|
-
<%= raw "<h5 class='flash notice'>#{flash[:notice]}</h5>" unless flash[:notice].blank? %>
|
30
|
-
</div>
|
31
|
-
|
32
|
-
<div id='content'>
|
33
|
-
<%= yield %>
|
34
|
-
</div>
|
35
|
-
|
36
|
-
<div id='copyright'>
|
37
|
-
Copyright © 2010, MyCompany. All rights reserved.
|
38
|
-
</div>
|
39
|
-
</body>
|
40
|
-
</html>
|
data/example/main.css
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#navigation {
|
2
|
-
float: left;
|
3
|
-
margin-bottom: 10px;
|
4
|
-
}
|
5
|
-
|
6
|
-
#userland {
|
7
|
-
float: right;
|
8
|
-
margin-bottom: 10px;
|
9
|
-
}
|
10
|
-
|
11
|
-
#flashes {
|
12
|
-
clear: both;
|
13
|
-
}
|
14
|
-
|
15
|
-
#content {
|
16
|
-
margin: 10px;
|
17
|
-
}
|
18
|
-
|
19
|
-
#copyright {
|
20
|
-
text-align: center;
|
21
|
-
}
|
22
|
-
|
23
|
-
.flash {
|
24
|
-
border: 1px solid #000000;
|
25
|
-
padding: 10px;
|
26
|
-
}
|
27
|
-
|
28
|
-
.flash.error {
|
29
|
-
}
|
30
|
-
|
31
|
-
.flash.notice {
|
32
|
-
}
|
33
|
-
|
34
|
-
label {
|
35
|
-
font-weight: bold;
|
36
|
-
}
|
37
|
-
|
38
|
-
input[type=text],input[type=password],select,textarea {
|
39
|
-
clear: both;
|
40
|
-
display: block;
|
41
|
-
}
|