##// END OF EJS Templates
Hooked up on the fly OpenID user creation....
Eric Davis -
r2382:0310f43126ac
parent child
Show More
@@ -196,25 +196,25 private
196 196
197 197
198 198 def open_id_authenticate(openid_url)
199 user = nil
200 199 authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
201 200 if result.successful?
202 201 user = User.find_or_initialize_by_identity_url(identity_url)
203 202 if user.new_record?
204 203 # Create on the fly
205 # TODO: name
206 204 user.login = registration['nickname']
207 205 user.mail = registration['email']
208 user.save
209 end
210
211 user.reload
212 if user.new_record?
206 user.firstname, user.lastname = registration['fullname'].split(' ')
207 user.random_password
208 if user.save
209 successful_authentication(user)
210 else
213 211 # Onthefly creation failed, display the registration form to fill/fix attributes
214 212 @user = user
215 213 session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
216 214 render :action => 'register'
215 end
217 216 else
217 # Existing record
218 218 successful_authentication(user)
219 219 end
220 220 end
@@ -139,6 +139,18 class User < ActiveRecord::Base
139 139 User.hash_password(clear_password) == self.hashed_password
140 140 end
141 141
142 # Generate and set a random password. Useful for automated user creation
143 # Based on Token#generate_token_value
144 #
145 def random_password
146 chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
147 password = ''
148 40.times { |i| password << chars[rand(chars.size-1)] }
149 self.password = password
150 self.password_confirmation = password
151 self
152 end
153
142 154 def pref
143 155 self.preference ||= UserPreference.new(:user => self)
144 156 end
@@ -177,4 +177,11 class UserTest < Test::Unit::TestCase
177 177 assert_not_nil u
178 178 assert_equal 'jsmith@somenet.foo', u.mail
179 179 end
180
181 def test_random_password
182 u = User.new
183 u.random_password
184 assert !u.password.blank?
185 assert !u.password_confirmation.blank?
186 end
180 187 end
General Comments 0
You need to be logged in to leave comments. Login now