##// END OF EJS Templates
Added user setup needed based on the system's registration settings...
Eric Davis -
r2385:8194cfaf8690
parent child
Show More
@@ -122,6 +122,7 class AccountController < ApplicationController
122 else
122 else
123 @user.login = params[:user][:login]
123 @user.login = params[:user][:login]
124 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
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 case Setting.self_registration
126 case Setting.self_registration
126 when '1'
127 when '1'
127 # Email activation
128 # Email activation
@@ -205,14 +206,40 private
205 user.mail = registration['email'] unless registration['email'].nil?
206 user.mail = registration['email'] unless registration['email'].nil?
206 user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
207 user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
207 user.random_password
208 user.random_password
208 if user.save
209 user.status = User::STATUS_REGISTERED
209 successful_authentication(user)
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
226 if user.save
227 flash[:notice] = l(:notice_account_activated)
228 successful_authentication(user)
229 else
230 onthefly_creation_failed(user, {:login => user.login, :identity_url => identity_url })
231 end
210 else
232 else
211 # Onthefly creation failed, display the registration form to fill/fix attributes
233 # Manual activation by the administrator
212 @user = user
234 if user.save
213 session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
235 # Sends an email to the administrators
214 render :action => 'register'
236 Mailer.deliver_account_activation_request(user)
215 end
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
242 end
216 else
243 else
217 # Existing record
244 # Existing record
218 successful_authentication(user)
245 successful_authentication(user)
@@ -232,4 +259,11 private
232 redirect_back_or_default :controller => 'my', :action => 'page'
259 redirect_back_or_default :controller => 'my', :action => 'page'
233 end
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 end
269 end
@@ -65,11 +65,13 class AccountControllerTest < Test::Unit::TestCase
65 end
65 end
66
66
67 def test_login_with_openid
67 def test_login_with_openid
68 Setting.self_registration = '3'
68 post :login, :openid_url => 'http://openid.example.com/good_user'
69 post :login, :openid_url => 'http://openid.example.com/good_user'
69 assert_redirected_to 'my/page'
70 assert_redirected_to 'my/page'
70 end
71 end
71
72
72 def test_login_with_openid_with_new_user_created
73 def test_login_with_openid_with_new_user_created
74 Setting.self_registration = '3'
73 post :login, :openid_url => 'http://openid.example.com/good_user'
75 post :login, :openid_url => 'http://openid.example.com/good_user'
74 assert_redirected_to 'my/page'
76 assert_redirected_to 'my/page'
75 user = User.find_by_login('cool_user')
77 user = User.find_by_login('cool_user')
@@ -78,7 +80,28 class AccountControllerTest < Test::Unit::TestCase
78 assert_equal 'User', user.lastname
80 assert_equal 'User', user.lastname
79 end
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 def test_login_with_openid_with_new_user_with_conflict_should_register
103 def test_login_with_openid_with_new_user_with_conflict_should_register
104 Setting.self_registration = '3'
82 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
105 existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
83 existing_user.login = 'cool_user'
106 existing_user.login = 'cool_user'
84 assert existing_user.save!
107 assert existing_user.save!
General Comments 0
You need to be logged in to leave comments. Login now