persistent_cookie_authentication_generator 0.0.1
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.
- data/MIT-LICENCE +20 -0
- data/USAGE +22 -0
- data/persistent_cookie_authentication_generator.rb +52 -0
- data/templates/identities.yml +18 -0
- data/templates/identity.rb +4 -0
- data/templates/login_cookie.rb +254 -0
- data/templates/login_cookies.yml +32 -0
- data/templates/migration.rb +42 -0
- data/templates/smtp_tls.rb +67 -0
- data/templates/user.rb +147 -0
- data/templates/user_change_password.rhtml +22 -0
- data/templates/user_controller.rb +302 -0
- data/templates/user_edit.rhtml +15 -0
- data/templates/user_environment.rb +9 -0
- data/templates/user_forgot_password.rhtml +9 -0
- data/templates/user_integration_test.rb +303 -0
- data/templates/user_login.rhtml +23 -0
- data/templates/user_notify.rb +55 -0
- data/templates/user_notify_change_password.rhtml +10 -0
- data/templates/user_notify_forgot_password.rhtml +8 -0
- data/templates/user_notify_signup.rhtml +10 -0
- data/templates/user_show.rhtml +15 -0
- data/templates/user_signup.rhtml +29 -0
- data/templates/user_system.rb +158 -0
- data/templates/user_test.rb +72 -0
- data/templates/users.yml +46 -0
- metadata +78 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
<h1>Edit</h1>
|
2
|
+
|
3
|
+
<% if flash[:notice] %><div class="notice"><%= flash[:notice] %></div><% end %>
|
4
|
+
|
5
|
+
<% form_for(:user, @user, :url => { :action => 'update' }) do |f| %>
|
6
|
+
<table>
|
7
|
+
<tr>
|
8
|
+
<td>Email</td>
|
9
|
+
<td><%= f.text_field(:email) %></td>
|
10
|
+
</tr>
|
11
|
+
</table>
|
12
|
+
|
13
|
+
<p><%= submit_tag 'Update Changes' %></p>
|
14
|
+
<% end %>
|
15
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<h1>Forgotten Password</h1>
|
2
|
+
|
3
|
+
<% if flash[:notice] %><div class="notice"><%= flash[:notice] %></div><% end %>
|
4
|
+
|
5
|
+
<% form_for(:user, :url => { :action => 'send_new_password' }) do |f| %>
|
6
|
+
<p>Please key in your email so that we can send you a new password</p>
|
7
|
+
<p><%= f.text_field(:email) %></p>
|
8
|
+
<p><%= submit_tag 'Send' %></p>
|
9
|
+
<% end %>
|
@@ -0,0 +1,303 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class UserControllerTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
fixtures :users, :identities, :login_cookies
|
6
|
+
|
7
|
+
|
8
|
+
def logs_in_as(person = nil)
|
9
|
+
if person != nil
|
10
|
+
@person = User.find(:first, :conditions => [ "login = ?", person ])
|
11
|
+
post "user/user_login", "user" => { :login => @person.login, :password => "atest" }
|
12
|
+
is_redirected_to "user/show"
|
13
|
+
assert_equal @person.identity.id, session["identity"]
|
14
|
+
assert_equal PRIVATE_STATE, session["state"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def is_redirected_to(template = nil)
|
21
|
+
if template != nil
|
22
|
+
session['return-to'] = nil
|
23
|
+
assert_response :redirect
|
24
|
+
follow_redirect!
|
25
|
+
assert_response :success
|
26
|
+
assert_template(template)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
def test_login_page
|
33
|
+
get "user/login"
|
34
|
+
assert_response :success
|
35
|
+
assert_template "user/login"
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
def test_valid_login
|
41
|
+
cookies[COOKIE_NAME] = nil
|
42
|
+
get "user/login"
|
43
|
+
post "user/user_login", "user" => { "login" => "bob", "password" => "atest" }
|
44
|
+
is_redirected_to "user/show"
|
45
|
+
assert_equal 1, session["identity"]
|
46
|
+
assert_equal PRIVATE_STATE, session["state"]
|
47
|
+
|
48
|
+
assert_match /bob%40([\d\w]+)%40([\d\w]+)/, cookies[COOKIE_NAME]
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
def test_valid_login_other_user
|
54
|
+
cookies[COOKIE_NAME] = "existingbob@1234567890@abcdefghij"
|
55
|
+
get "user/login"
|
56
|
+
post "user/user_login", "user" => { "login" => "bob", "password" => "atest" }
|
57
|
+
is_redirected_to "user/show"
|
58
|
+
assert_equal 1, session["identity"]
|
59
|
+
assert_equal PRIVATE_STATE, session["state"]
|
60
|
+
|
61
|
+
assert_match /bob%40([\d\w]+)%40([\d\w]+)/, cookies[COOKIE_NAME]
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
def test_valid_login_same_user
|
67
|
+
cookies[COOKIE_NAME] = "bob@seriesbob@tokenbob"
|
68
|
+
post "user/user_login", "user" => { "login" => "bob", "password" => "atest" }
|
69
|
+
is_redirected_to "user/show"
|
70
|
+
assert_equal 1, session["identity"]
|
71
|
+
assert_equal PRIVATE_STATE, session["state"]
|
72
|
+
|
73
|
+
assert_match /bob%40seriesbob%40[\w\d]+/, cookies[COOKIE_NAME]
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
def test_invalid_login
|
79
|
+
post "user/user_login", "user" => { "login" => "bob", "password" => "not_correct" }
|
80
|
+
is_redirected_to "user/login"
|
81
|
+
assert_equal 0, session["identity"]
|
82
|
+
assert_equal 0, session["state"]
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
def test_login_logoff
|
88
|
+
post "user/user_login", "user" => { "login" => "bob", "password" => "atest" }
|
89
|
+
is_redirected_to "user/show"
|
90
|
+
assert_equal 1, session["identity"]
|
91
|
+
assert_equal PRIVATE_STATE, session["state"]
|
92
|
+
|
93
|
+
get "user/logout"
|
94
|
+
is_redirected_to "user/login"
|
95
|
+
assert_equal 0, session["identity"]
|
96
|
+
assert_equal 0, session["state"]
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
def test_valid_signup
|
102
|
+
get "user/signup"
|
103
|
+
assert_response :success
|
104
|
+
assert_template "user/signup"
|
105
|
+
|
106
|
+
ActionMailer::Base.deliveries = Array.new
|
107
|
+
session['return-to'] = "/bogus/location"
|
108
|
+
|
109
|
+
post "user/user_signup", "user" => { "login" => "newbob", "password" => "newpassword", "password_confirmation" => "newpassword", "email" => "newbob@test.com" }
|
110
|
+
is_redirected_to "user/login"
|
111
|
+
|
112
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
113
|
+
mail = ActionMailer::Base.deliveries[0]
|
114
|
+
assert_equal "newbob@test.com", mail.to_addrs[0].to_s
|
115
|
+
assert_match /login:\s+\w+\n/, mail.encoded
|
116
|
+
assert_match /password:\s+\w+\n/, mail.encoded
|
117
|
+
key = /key=([\w\d]+)/.match(mail.encoded)[1]
|
118
|
+
|
119
|
+
user = User.find_by_email("newbob@test.com")
|
120
|
+
assert_not_nil user
|
121
|
+
assert_equal 0, user.verified
|
122
|
+
|
123
|
+
# Then a bogus key.
|
124
|
+
get "user/welcome", "user"=> { "id" => "#{user.id}" }, "key" => "boguskey"
|
125
|
+
user = User.find_by_email("newbob@test.com")
|
126
|
+
assert_equal 0, user.verified
|
127
|
+
|
128
|
+
# Now the real one.
|
129
|
+
get "user/welcome", "user"=> { "id" => "#{user.id}" }, "key" => "#{key}"
|
130
|
+
user = User.find_by_email("newbob@test.com")
|
131
|
+
assert_equal 1, user.verified
|
132
|
+
is_redirected_to "user/login"
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
def test_signup_bad_input
|
138
|
+
#login too long
|
139
|
+
do_test_signup "newbobnewbobnewbobnewbobnewbobnewbobnewbobnewbobnewbobnewbobnewbobnewbobnewbobnewbobnewbob", "newpassword", "newpassword", "bob@wahlao.com"
|
140
|
+
|
141
|
+
#login too short
|
142
|
+
do_test_signup "1", "newpassword", "newpassword", "bob@wahlao.com"
|
143
|
+
|
144
|
+
#login not unique
|
145
|
+
do_test_signup "bob", "newpassword", "newpassword", "bob@wahlao.com"
|
146
|
+
|
147
|
+
#login blank
|
148
|
+
do_test_signup "", "newpassword", "newpassword", "bob@wahlao.com"
|
149
|
+
|
150
|
+
#email blank
|
151
|
+
do_test_signup "newbob", "newpassword", "newpassword", ""
|
152
|
+
|
153
|
+
#email not unique
|
154
|
+
do_test_signup "newbob", "newpassword", "newpassword", "bob@test.com"
|
155
|
+
|
156
|
+
#password blank
|
157
|
+
do_test_signup "newbob", "", "", "bob@paypal.com"
|
158
|
+
|
159
|
+
#password not the same as confirmation
|
160
|
+
do_test_signup "newbob", "newpassword", "oldpassword", "bob@wahlao.com"
|
161
|
+
|
162
|
+
#password too long
|
163
|
+
do_test_signup "newbob", "passpasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspass", "passpasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspasspass", "bob@wahlao.com"
|
164
|
+
|
165
|
+
#password too short
|
166
|
+
do_test_signup "newbob", "p", "p", "bob@wahlao.com"
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
def do_test_signup(login, password, password_cfm, email)
|
173
|
+
identity_prevCount = Identity.count
|
174
|
+
post "user/user_signup", "school" => "", "user" => { "login" => login, "password" => password, "password_confirmation" => password_cfm, "email" => email }
|
175
|
+
is_redirected_to "user/signup"
|
176
|
+
assert_equal identity_prevCount, Identity.count
|
177
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
def test_valid_change_password
|
183
|
+
ActionMailer::Base.deliveries = Array.new
|
184
|
+
logs_in_as "bob"
|
185
|
+
get "user/change_password"
|
186
|
+
assert_response :success
|
187
|
+
assert_template "user/change_password"
|
188
|
+
|
189
|
+
post "user/update_password", "current_password" => "atest", "user" => { "password" => "changed_password", "password_confirmation" => "changed_password" }
|
190
|
+
is_redirected_to "user/show"
|
191
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
192
|
+
mail = ActionMailer::Base.deliveries[0]
|
193
|
+
assert_equal "bob@test.com", mail.to_addrs[0].to_s
|
194
|
+
assert_match /login:\s+\w+\n/, mail.encoded
|
195
|
+
assert_match /password:\s+\w+\n/, mail.encoded
|
196
|
+
|
197
|
+
post "user/user_login", "user" => { "login" => "bob", "password" => "changed_password" }
|
198
|
+
is_redirected_to "user/show"
|
199
|
+
assert_equal 1, session["identity"]
|
200
|
+
assert_equal PRIVATE_STATE, session["state"]
|
201
|
+
|
202
|
+
post "user/update_password", "current_password" => "changed_password", "user" => { "password" => "atest", "password_confirmation" => "atest" }
|
203
|
+
get "user/logout"
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
def do_change_password(old_password, new_password, new_password_cfm)
|
209
|
+
ActionMailer::Base.deliveries = Array.new
|
210
|
+
logs_in_as "bob"
|
211
|
+
|
212
|
+
post "user/update_password", "current_password" => old_password, "user" => { "password" => new_password, "password_confirmation" => new_password_cfm }
|
213
|
+
is_redirected_to "user/change_password"
|
214
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
def test_change_password
|
220
|
+
do_change_password("hahaha", "newpassword", "newpassword")
|
221
|
+
do_change_password("atest", "passwordpasswordpasswordpasswordpassowrdpasswordpasswordpasswordpasswordpassword", "passwordpasswordpasswordpasswordpassowrdpasswordpasswordpasswordpasswordpassword")
|
222
|
+
do_change_password("atest", "hahaha", "hehehe")
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
def test_valid_forgot_password
|
228
|
+
ActionMailer::Base.deliveries = Array.new
|
229
|
+
logs_in_as "bob"
|
230
|
+
get "user/forgot_password"
|
231
|
+
assert_response :success
|
232
|
+
assert_template "user/forgot_password"
|
233
|
+
|
234
|
+
post "user/send_new_password", "user" => { "email" => "bob@test.com" }
|
235
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
236
|
+
mail = ActionMailer::Base.deliveries[0]
|
237
|
+
assert_equal "bob@test.com", mail.to_addrs[0].to_s
|
238
|
+
assert_match /login\sid:\w+/, mail.encoded
|
239
|
+
assert_match /password:[\w\d]+/, mail.encoded
|
240
|
+
is_redirected_to "user/login"
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
def test_invalid_forgot_password
|
246
|
+
ActionMailer::Base.deliveries = Array.new
|
247
|
+
logs_in_as "bob"
|
248
|
+
get "user/forgot_password"
|
249
|
+
assert_response :success
|
250
|
+
assert_template "user/forgot_password"
|
251
|
+
|
252
|
+
post "user/send_new_password", "user" => { "email" => "bob@bad.com" }
|
253
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
254
|
+
is_redirected_to "user/login"
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
def test_valid_edit
|
260
|
+
logs_in_as "bob"
|
261
|
+
get "user/edit"
|
262
|
+
assert_response :success
|
263
|
+
assert_template "user/edit"
|
264
|
+
assert_equal "bob@test.com", assigns(:user).email
|
265
|
+
|
266
|
+
post "user/update", "user" => { "email" => "bob@excitingbob.com" }
|
267
|
+
is_redirected_to "user/show"
|
268
|
+
assert_response :success
|
269
|
+
assert_template "user/show"
|
270
|
+
assert_equal "bob@excitingbob.com", assigns(:user).email
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
def test_invalid_edit
|
275
|
+
logs_in_as "bob"
|
276
|
+
get "user/edit"
|
277
|
+
assert_response :success
|
278
|
+
assert_template "user/edit"
|
279
|
+
assert_equal "bob@test.com", assigns(:user).email
|
280
|
+
|
281
|
+
#blank email
|
282
|
+
post "user/update", "user" => { "email" => "" }
|
283
|
+
is_redirected_to "user/edit"
|
284
|
+
assert_equal "bob@test.com", assigns(:user).email
|
285
|
+
|
286
|
+
#non unique email
|
287
|
+
post "user/update", "user" => { "email" => "longbob@test.com" }
|
288
|
+
is_redirected_to "user/edit"
|
289
|
+
assert_equal "bob@test.com", assigns(:user).email
|
290
|
+
end
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
def test_show
|
295
|
+
logs_in_as "bob"
|
296
|
+
get "user/show"
|
297
|
+
assert_response :success
|
298
|
+
assert_template "user/show"
|
299
|
+
assert_equal "bob", assigns(:user).login
|
300
|
+
assert_equal "bob@test.com", assigns(:user).email
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<h1>Log In</h1>
|
2
|
+
|
3
|
+
<% if flash[:notice] %><div class="notice"><%= flash[:notice] %></div><% end %>
|
4
|
+
|
5
|
+
<% form_for(:user, :url => { :action => 'user_login' }) do |f| %>
|
6
|
+
<table>
|
7
|
+
<tr>
|
8
|
+
<td>Login ID</td>
|
9
|
+
<td><%= f.text_field(:login, :size => 30) %></td>
|
10
|
+
</tr>
|
11
|
+
<tr>
|
12
|
+
<td>Password</td>
|
13
|
+
<td><%= f.password_field(:password, :size => 30) %></td>
|
14
|
+
</tr>
|
15
|
+
</table>
|
16
|
+
<p><%= submit_tag 'Log in' %></p>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<p>
|
20
|
+
<%= link_to 'Sign Up', :action => 'signup' %> |
|
21
|
+
<%= link_to 'Forgot password', :action => 'forgot_password' %>
|
22
|
+
</p>
|
23
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class UserNotify < ActionMailer::Base
|
2
|
+
|
3
|
+
def setup_email(user)
|
4
|
+
@recipients = "#{user.email}"
|
5
|
+
@from = ADMIN_EMAIL
|
6
|
+
@subject = "[#{APP_NAME}] "
|
7
|
+
@sent_on = Time.now
|
8
|
+
@headers['Content-Type'] = "text/plain; charset=utf-8; format=flowed"
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def signup(user, password, url)
|
14
|
+
setup_email(user)
|
15
|
+
|
16
|
+
# Email header info
|
17
|
+
@subject += "Welcome to #{APP_NAME}!"
|
18
|
+
|
19
|
+
# Email body substitutions
|
20
|
+
@body["login"] = user.login
|
21
|
+
@body["password"] = password
|
22
|
+
@body["url"] = url
|
23
|
+
@body["app_name"] = APP_NAME
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
def forgot_password(user, randomPassword)
|
29
|
+
setup_email(user)
|
30
|
+
|
31
|
+
# Email header info
|
32
|
+
@subject += "Forgotten password notification"
|
33
|
+
|
34
|
+
# Email body substitutions
|
35
|
+
@body["login"] = user.login
|
36
|
+
@body["randomPassword"] = randomPassword
|
37
|
+
@body["app_name"] = APP_NAME
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
def change_password(user, password)
|
43
|
+
setup_email(user)
|
44
|
+
|
45
|
+
# Email header info
|
46
|
+
@subject += "Changed password notification"
|
47
|
+
|
48
|
+
# Email body substitutions
|
49
|
+
@body["login"] = user.login
|
50
|
+
@body["password"] = password
|
51
|
+
@body["url"] = APP_NAME
|
52
|
+
@body["app_name"] = APP_NAME
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Dear <%= @login %>,
|
2
|
+
|
3
|
+
At your request, <%= @app_name %> has changed your password. If it was not at your request, then you should be aware that someone has access to your account and requested this change.
|
4
|
+
|
5
|
+
Your new login credentials are:
|
6
|
+
|
7
|
+
login: <%= @login %>
|
8
|
+
password: <%= @password %>
|
9
|
+
|
10
|
+
<%= @url %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Dear <%= @login %>,
|
2
|
+
|
3
|
+
At your request, <%= @app_name %> has resetted your password. If it was not at your request, then you should be aware that someone has entered your email address as theirs in the forgotten password section of <%= @app_name %>.
|
4
|
+
|
5
|
+
Your new password:<%= @randomPassword %>
|
6
|
+
And your login id:<%= @login %>
|
7
|
+
|
8
|
+
It's advisable for you to change your password as soon as you login. It's as simple as navigating to 'Preferences' and clicking on 'Change Password'.
|