Hooked up on the fly OpenID user creation.
* Use OpenID registration fields for the user. * Generate a random password when a user is created. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2443 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
896e64b759
commit
0310f43126
|
@ -196,25 +196,25 @@ private
|
||||||
|
|
||||||
|
|
||||||
def open_id_authenticate(openid_url)
|
def open_id_authenticate(openid_url)
|
||||||
user = nil
|
|
||||||
authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
|
authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
|
||||||
if result.successful?
|
if result.successful?
|
||||||
user = User.find_or_initialize_by_identity_url(identity_url)
|
user = User.find_or_initialize_by_identity_url(identity_url)
|
||||||
if user.new_record?
|
if user.new_record?
|
||||||
# Create on the fly
|
# Create on the fly
|
||||||
# TODO: name
|
|
||||||
user.login = registration['nickname']
|
user.login = registration['nickname']
|
||||||
user.mail = registration['email']
|
user.mail = registration['email']
|
||||||
user.save
|
user.firstname, user.lastname = registration['fullname'].split(' ')
|
||||||
end
|
user.random_password
|
||||||
|
if user.save
|
||||||
user.reload
|
successful_authentication(user)
|
||||||
if user.new_record?
|
else
|
||||||
# Onthefly creation failed, display the registration form to fill/fix attributes
|
# Onthefly creation failed, display the registration form to fill/fix attributes
|
||||||
@user = user
|
@user = user
|
||||||
session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
|
session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
|
||||||
render :action => 'register'
|
render :action => 'register'
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
# Existing record
|
||||||
successful_authentication(user)
|
successful_authentication(user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -139,6 +139,18 @@ class User < ActiveRecord::Base
|
||||||
User.hash_password(clear_password) == self.hashed_password
|
User.hash_password(clear_password) == self.hashed_password
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generate and set a random password. Useful for automated user creation
|
||||||
|
# Based on Token#generate_token_value
|
||||||
|
#
|
||||||
|
def random_password
|
||||||
|
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
||||||
|
password = ''
|
||||||
|
40.times { |i| password << chars[rand(chars.size-1)] }
|
||||||
|
self.password = password
|
||||||
|
self.password_confirmation = password
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
def pref
|
def pref
|
||||||
self.preference ||= UserPreference.new(:user => self)
|
self.preference ||= UserPreference.new(:user => self)
|
||||||
end
|
end
|
||||||
|
|
|
@ -177,4 +177,11 @@ class UserTest < Test::Unit::TestCase
|
||||||
assert_not_nil u
|
assert_not_nil u
|
||||||
assert_equal 'jsmith@somenet.foo', u.mail
|
assert_equal 'jsmith@somenet.foo', u.mail
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_random_password
|
||||||
|
u = User.new
|
||||||
|
u.random_password
|
||||||
|
assert !u.password.blank?
|
||||||
|
assert !u.password_confirmation.blank?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue