summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index a13a6f77870..942f333702e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -2,7 +2,7 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :token_authenticatable,
- :recoverable, :rememberable, :trackable, :validatable
+ :recoverable, :rememberable, :trackable, :validatable, :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
@@ -62,6 +62,30 @@ class User < ActiveRecord::Base
def last_activity_project
projects.first
end
+
+ def self.generate_random_password
+ (0...8).map{ ('a'..'z').to_a[rand(26)] }.join
+ end
+
+ def first_name
+ name.split(" ").first unless name.blank?
+ end
+
+ def self.find_for_ldap_auth(omniauth_info)
+ name = omniauth_info.name
+ email = omniauth_info.email
+
+ if @user = User.find_by_email(email)
+ @user
+ else
+ password = generate_random_password
+ @user = User.create(:name => name,
+ :email => email,
+ :password => password,
+ :password_confirmation => password
+ )
+ end
+ end
end
# == Schema Information
#