@@ -122,6 +122,7 class AccountController < ApplicationController | |||
|
122 | 122 | else |
|
123 | 123 | @user.login = params[:user][:login] |
|
124 | 124 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] |
|
125 | # TODO: Duplicated in open_id_authenticate action. A good sized refactoring would be good here | |
|
125 | 126 | case Setting.self_registration |
|
126 | 127 | when '1' |
|
127 | 128 | # Email activation |
@@ -205,13 +206,39 private | |||
|
205 | 206 | user.mail = registration['email'] unless registration['email'].nil? |
|
206 | 207 | user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil? |
|
207 | 208 | user.random_password |
|
209 | user.status = User::STATUS_REGISTERED | |
|
210 | ||
|
211 | # TODO: Duplicated in register action. A good sized refactoring would be good here | |
|
212 | case Setting.self_registration | |
|
213 | when '1' | |
|
214 | # Email activation | |
|
215 | token = Token.new(:user => user, :action => "register") | |
|
216 | if user.save and token.save | |
|
217 | Mailer.deliver_register(token) | |
|
218 | flash[:notice] = l(:notice_account_register_done) | |
|
219 | redirect_to :action => 'login' | |
|
220 | else | |
|
221 | onthefly_creation_failed(user, {:login => user.login, :identity_url => identity_url }) | |
|
222 | end | |
|
223 | when '3' | |
|
224 | # Automatic activation | |
|
225 | user.status = User::STATUS_ACTIVE | |
|
208 | 226 | if user.save |
|
227 | flash[:notice] = l(:notice_account_activated) | |
|
209 | 228 | successful_authentication(user) |
|
210 | 229 | else |
|
211 | # Onthefly creation failed, display the registration form to fill/fix attributes | |
|
212 |
|
|
|
213 | session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url } | |
|
214 | render :action => 'register' | |
|
230 | onthefly_creation_failed(user, {:login => user.login, :identity_url => identity_url }) | |
|
231 | end | |
|
232 | else | |
|
233 | # Manual activation by the administrator | |
|
234 | if user.save | |
|
235 | # Sends an email to the administrators | |
|
236 | Mailer.deliver_account_activation_request(user) | |
|
237 | flash[:notice] = l(:notice_account_pending) | |
|
238 | redirect_to :action => 'login' | |
|
239 | else | |
|
240 | onthefly_creation_failed(user, {:login => user.login, :identity_url => identity_url }) | |
|
241 | end | |
|
215 | 242 | end |
|
216 | 243 | else |
|
217 | 244 | # Existing record |
@@ -232,4 +259,11 private | |||
|
232 | 259 | redirect_back_or_default :controller => 'my', :action => 'page' |
|
233 | 260 | end |
|
234 | 261 | |
|
262 | # Onthefly creation failed, display the registration form to fill/fix attributes | |
|
263 | def onthefly_creation_failed(user, auth_source_options = { }) | |
|
264 | @user = user | |
|
265 | session[:auth_source_registration] = auth_source_options unless auth_source_options.empty? | |
|
266 | render :action => 'register' | |
|
267 | end | |
|
268 | ||
|
235 | 269 | end |
@@ -65,11 +65,13 class AccountControllerTest < Test::Unit::TestCase | |||
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def test_login_with_openid |
|
68 | Setting.self_registration = '3' | |
|
68 | 69 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
69 | 70 | assert_redirected_to 'my/page' |
|
70 | 71 | end |
|
71 | 72 | |
|
72 | 73 | def test_login_with_openid_with_new_user_created |
|
74 | Setting.self_registration = '3' | |
|
73 | 75 | post :login, :openid_url => 'http://openid.example.com/good_user' |
|
74 | 76 | assert_redirected_to 'my/page' |
|
75 | 77 | user = User.find_by_login('cool_user') |
@@ -78,7 +80,28 class AccountControllerTest < Test::Unit::TestCase | |||
|
78 | 80 | assert_equal 'User', user.lastname |
|
79 | 81 | end |
|
80 | 82 | |
|
83 | def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token | |
|
84 | Setting.self_registration = '1' | |
|
85 | post :login, :openid_url => 'http://openid.example.com/good_user' | |
|
86 | assert_redirected_to 'login' | |
|
87 | user = User.find_by_login('cool_user') | |
|
88 | assert user | |
|
89 | ||
|
90 | token = Token.find_by_user_id_and_action(user.id, 'register') | |
|
91 | assert token | |
|
92 | end | |
|
93 | ||
|
94 | def test_login_with_openid_with_new_user_created_with_manual_activation | |
|
95 | Setting.self_registration = '2' | |
|
96 | post :login, :openid_url => 'http://openid.example.com/good_user' | |
|
97 | assert_redirected_to 'login' | |
|
98 | user = User.find_by_login('cool_user') | |
|
99 | assert user | |
|
100 | assert_equal User::STATUS_REGISTERED, user.status | |
|
101 | end | |
|
102 | ||
|
81 | 103 | def test_login_with_openid_with_new_user_with_conflict_should_register |
|
104 | Setting.self_registration = '3' | |
|
82 | 105 | existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com') |
|
83 | 106 | existing_user.login = 'cool_user' |
|
84 | 107 | assert existing_user.save! |
General Comments 0
You need to be logged in to leave comments.
Login now