##// 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 def open_id_authenticate(openid_url)
198 def open_id_authenticate(openid_url)
199 user = nil
200 authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
199 authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
201 if result.successful?
200 if result.successful?
202 user = User.find_or_initialize_by_identity_url(identity_url)
201 user = User.find_or_initialize_by_identity_url(identity_url)
203 if user.new_record?
202 if user.new_record?
204 # Create on the fly
203 # Create on the fly
205 # TODO: name
206 user.login = registration['nickname']
204 user.login = registration['nickname']
207 user.mail = registration['email']
205 user.mail = registration['email']
208 user.save
206 user.firstname, user.lastname = registration['fullname'].split(' ')
209 end
207 user.random_password
210
208 if user.save
211 user.reload
209 successful_authentication(user)
212 if user.new_record?
210 else
213 # Onthefly creation failed, display the registration form to fill/fix attributes
211 # Onthefly creation failed, display the registration form to fill/fix attributes
214 @user = user
212 @user = user
215 session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
213 session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
216 render :action => 'register'
214 render :action => 'register'
215 end
217 else
216 else
217 # Existing record
218 successful_authentication(user)
218 successful_authentication(user)
219 end
219 end
220 end
220 end
@@ -138,6 +138,18 class User < ActiveRecord::Base
138 def check_password?(clear_password)
138 def check_password?(clear_password)
139 User.hash_password(clear_password) == self.hashed_password
139 User.hash_password(clear_password) == self.hashed_password
140 end
140 end
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
141
153
142 def pref
154 def pref
143 self.preference ||= UserPreference.new(:user => self)
155 self.preference ||= UserPreference.new(:user => self)
@@ -177,4 +177,11 class UserTest < Test::Unit::TestCase
177 assert_not_nil u
177 assert_not_nil u
178 assert_equal 'jsmith@somenet.foo', u.mail
178 assert_equal 'jsmith@somenet.foo', u.mail
179 end
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 end
187 end
General Comments 0
You need to be logged in to leave comments. Login now