summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/account_controller.rb22
-rw-r--r--app/models/user.rb12
2 files changed, 23 insertions, 11 deletions
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 2e280dac9..cdbca5927 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -196,25 +196,25 @@ private
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|
if result.successful?
user = User.find_or_initialize_by_identity_url(identity_url)
if user.new_record?
# Create on the fly
- # TODO: name
user.login = registration['nickname']
user.mail = registration['email']
- user.save
- end
-
- user.reload
- if user.new_record?
- # Onthefly creation failed, display the registration form to fill/fix attributes
- @user = user
- session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
- render :action => 'register'
+ user.firstname, user.lastname = registration['fullname'].split(' ')
+ user.random_password
+ if user.save
+ successful_authentication(user)
+ else
+ # Onthefly creation failed, display the registration form to fill/fix attributes
+ @user = user
+ session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
+ render :action => 'register'
+ end
else
+ # Existing record
successful_authentication(user)
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 0005c85d1..b35c1a815 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -138,6 +138,18 @@ class User < ActiveRecord::Base
def check_password?(clear_password)
User.hash_password(clear_password) == self.hashed_password
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
self.preference ||= UserPreference.new(:user => self)