Added user setup needed based on the system's registration settings
* Copied the register action's chunk of code used to setup the account based on Setting.self_registration * Extracted method for when onthefly_creation_failed * Added tests to confirm the behavior #699 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2446 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
876fb69271
commit
8194cfaf86
@ -122,6 +122,7 @@ class AccountController < ApplicationController
|
|||||||
else
|
else
|
||||||
@user.login = params[:user][:login]
|
@user.login = params[:user][:login]
|
||||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
|
||||||
|
# TODO: Duplicated in open_id_authenticate action. A good sized refactoring would be good here
|
||||||
case Setting.self_registration
|
case Setting.self_registration
|
||||||
when '1'
|
when '1'
|
||||||
# Email activation
|
# Email activation
|
||||||
@ -205,14 +206,40 @@ private
|
|||||||
user.mail = registration['email'] unless registration['email'].nil?
|
user.mail = registration['email'] unless registration['email'].nil?
|
||||||
user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
|
user.firstname, user.lastname = registration['fullname'].split(' ') unless registration['fullname'].nil?
|
||||||
user.random_password
|
user.random_password
|
||||||
if user.save
|
user.status = User::STATUS_REGISTERED
|
||||||
successful_authentication(user)
|
|
||||||
|
# TODO: Duplicated in register action. A good sized refactoring would be good here
|
||||||
|
case Setting.self_registration
|
||||||
|
when '1'
|
||||||
|
# Email activation
|
||||||
|
token = Token.new(:user => user, :action => "register")
|
||||||
|
if user.save and token.save
|
||||||
|
Mailer.deliver_register(token)
|
||||||
|
flash[:notice] = l(:notice_account_register_done)
|
||||||
|
redirect_to :action => 'login'
|
||||||
|
else
|
||||||
|
onthefly_creation_failed(user, {:login => user.login, :identity_url => identity_url })
|
||||||
|
end
|
||||||
|
when '3'
|
||||||
|
# Automatic activation
|
||||||
|
user.status = User::STATUS_ACTIVE
|
||||||
|
if user.save
|
||||||
|
flash[:notice] = l(:notice_account_activated)
|
||||||
|
successful_authentication(user)
|
||||||
|
else
|
||||||
|
onthefly_creation_failed(user, {:login => user.login, :identity_url => identity_url })
|
||||||
|
end
|
||||||
else
|
else
|
||||||
# Onthefly creation failed, display the registration form to fill/fix attributes
|
# Manual activation by the administrator
|
||||||
@user = user
|
if user.save
|
||||||
session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
|
# Sends an email to the administrators
|
||||||
render :action => 'register'
|
Mailer.deliver_account_activation_request(user)
|
||||||
end
|
flash[:notice] = l(:notice_account_pending)
|
||||||
|
redirect_to :action => 'login'
|
||||||
|
else
|
||||||
|
onthefly_creation_failed(user, {:login => user.login, :identity_url => identity_url })
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
# Existing record
|
# Existing record
|
||||||
successful_authentication(user)
|
successful_authentication(user)
|
||||||
@ -232,4 +259,11 @@ private
|
|||||||
redirect_back_or_default :controller => 'my', :action => 'page'
|
redirect_back_or_default :controller => 'my', :action => 'page'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Onthefly creation failed, display the registration form to fill/fix attributes
|
||||||
|
def onthefly_creation_failed(user, auth_source_options = { })
|
||||||
|
@user = user
|
||||||
|
session[:auth_source_registration] = auth_source_options unless auth_source_options.empty?
|
||||||
|
render :action => 'register'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -65,11 +65,13 @@ class AccountControllerTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_login_with_openid
|
def test_login_with_openid
|
||||||
|
Setting.self_registration = '3'
|
||||||
post :login, :openid_url => 'http://openid.example.com/good_user'
|
post :login, :openid_url => 'http://openid.example.com/good_user'
|
||||||
assert_redirected_to 'my/page'
|
assert_redirected_to 'my/page'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_login_with_openid_with_new_user_created
|
def test_login_with_openid_with_new_user_created
|
||||||
|
Setting.self_registration = '3'
|
||||||
post :login, :openid_url => 'http://openid.example.com/good_user'
|
post :login, :openid_url => 'http://openid.example.com/good_user'
|
||||||
assert_redirected_to 'my/page'
|
assert_redirected_to 'my/page'
|
||||||
user = User.find_by_login('cool_user')
|
user = User.find_by_login('cool_user')
|
||||||
@ -78,7 +80,28 @@ class AccountControllerTest < Test::Unit::TestCase
|
|||||||
assert_equal 'User', user.lastname
|
assert_equal 'User', user.lastname
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_login_with_openid_with_new_user_created_with_email_activation_should_have_a_token
|
||||||
|
Setting.self_registration = '1'
|
||||||
|
post :login, :openid_url => 'http://openid.example.com/good_user'
|
||||||
|
assert_redirected_to 'login'
|
||||||
|
user = User.find_by_login('cool_user')
|
||||||
|
assert user
|
||||||
|
|
||||||
|
token = Token.find_by_user_id_and_action(user.id, 'register')
|
||||||
|
assert token
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_login_with_openid_with_new_user_created_with_manual_activation
|
||||||
|
Setting.self_registration = '2'
|
||||||
|
post :login, :openid_url => 'http://openid.example.com/good_user'
|
||||||
|
assert_redirected_to 'login'
|
||||||
|
user = User.find_by_login('cool_user')
|
||||||
|
assert user
|
||||||
|
assert_equal User::STATUS_REGISTERED, user.status
|
||||||
|
end
|
||||||
|
|
||||||
def test_login_with_openid_with_new_user_with_conflict_should_register
|
def test_login_with_openid_with_new_user_with_conflict_should_register
|
||||||
|
Setting.self_registration = '3'
|
||||||
existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
|
existing_user = User.new(:firstname => 'Cool', :lastname => 'User', :mail => 'user@somedomain.com')
|
||||||
existing_user.login = 'cool_user'
|
existing_user.login = 'cool_user'
|
||||||
assert existing_user.save!
|
assert existing_user.save!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user