##// END OF EJS Templates
Fixed: Openid registration form should not require user to enter password (#11331)....
Jean-Philippe Lang -
r9746:76a4b81cf3a9
parent child
Show More
@@ -84,8 +84,9 class AccountController < ApplicationController
84 session[:auth_source_registration] = nil
84 session[:auth_source_registration] = nil
85 @user = User.new(:language => Setting.default_language)
85 @user = User.new(:language => Setting.default_language)
86 else
86 else
87 user_params = params[:user] || {}
87 @user = User.new
88 @user = User.new
88 @user.safe_attributes = params[:user]
89 @user.safe_attributes = user_params
89 @user.admin = false
90 @user.admin = false
90 @user.register
91 @user.register
91 if session[:auth_source_registration]
92 if session[:auth_source_registration]
@@ -100,7 +101,9 class AccountController < ApplicationController
100 end
101 end
101 else
102 else
102 @user.login = params[:user][:login]
103 @user.login = params[:user][:login]
103 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
104 unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank?
105 @user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation]
106 end
104
107
105 case Setting.self_registration
108 case Setting.self_registration
106 when '1'
109 when '1'
@@ -116,6 +116,42 class AccountControllerTest < ActionController::TestCase
116 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
116 assert_equal 'http://openid.example.com/good_user', assigns(:user)[:identity_url]
117 end
117 end
118
118
119 def test_login_with_openid_with_new_user_with_missing_information_should_register
120 Setting.self_registration = '3'
121
122 post :login, :openid_url => 'http://openid.example.com/good_blank_user'
123 assert_response :success
124 assert_template 'register'
125 assert assigns(:user)
126 assert_equal 'http://openid.example.com/good_blank_user', assigns(:user)[:identity_url]
127
128 assert_select 'input[name=?]', 'user[login]'
129 assert_select 'input[name=?]', 'user[password]'
130 assert_select 'input[name=?]', 'user[password_confirmation]'
131 assert_select 'input[name=?][value=?]', 'user[identity_url]', 'http://openid.example.com/good_blank_user'
132 end
133
134 def test_register_after_login_failure_should_not_require_user_to_enter_a_password
135 Setting.self_registration = '3'
136
137 assert_difference 'User.count' do
138 post :register, :user => {
139 :login => 'good_blank_user',
140 :password => '',
141 :password_confirmation => '',
142 :firstname => 'Cool',
143 :lastname => 'User',
144 :mail => 'user@somedomain.com',
145 :identity_url => 'http://openid.example.com/good_blank_user'
146 }
147 assert_response 302
148 end
149
150 user = User.first(:order => 'id DESC')
151 assert_equal 'http://openid.example.com/good_blank_user', user.identity_url
152 assert user.hashed_password.blank?, "Hashed password was #{user.hashed_password}"
153 end
154
119 def test_setting_openid_should_return_true_when_set_to_true
155 def test_setting_openid_should_return_true_when_set_to_true
120 assert_equal true, Setting.openid?
156 assert_equal true, Setting.openid?
121 end
157 end
@@ -16,9 +16,10 module OpenIdAuthentication
16
16
17 def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc:
17 def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc:
18 if User.find_by_identity_url(identity_url) || identity_url.include?('good')
18 if User.find_by_identity_url(identity_url) || identity_url.include?('good')
19 extension_response_fields = {}
20
19 # Don't process registration fields unless it is requested.
21 # Don't process registration fields unless it is requested.
20 unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
22 unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
21 extension_response_fields = {}
22
23
23 options[:required].each do |field|
24 options[:required].each do |field|
24 extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
25 extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
General Comments 0
You need to be logged in to leave comments. Login now