Commit faa0ec7c authored by Nihad Abbasov's avatar Nihad Abbasov

cleanup User model

parent fc74627f
class User < ActiveRecord::Base class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :token_authenticatable, devise :database_authenticatable, :token_authenticatable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable :recoverable, :rememberable, :trackable, :validatable, :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, attr_accessible :email, :password, :password_confirmation, :remember_me, :bio,
:name, :projects_limit, :skype, :linkedin, :twitter, :dark_scheme, :theme_id :name, :projects_limit, :skype, :linkedin, :twitter, :dark_scheme, :theme_id
...@@ -46,7 +43,7 @@ class User < ActiveRecord::Base ...@@ -46,7 +43,7 @@ class User < ActiveRecord::Base
validates :bio, :length => { :within => 0..255 } validates :bio, :length => { :within => 0..255 }
before_create :ensure_authentication_token before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token alias_attribute :private_token, :authentication_token
scope :not_in_project, lambda { |project| where("id not in (:ids)", :ids => project.users.map(&:id) ) } scope :not_in_project, lambda { |project| where("id not in (:ids)", :ids => project.users.map(&:id) ) }
...@@ -76,7 +73,6 @@ class User < ActiveRecord::Base ...@@ -76,7 +73,6 @@ class User < ActiveRecord::Base
admin admin
end end
def require_ssh_key? def require_ssh_key?
keys.count == 0 keys.count == 0
end end
...@@ -89,12 +85,8 @@ class User < ActiveRecord::Base ...@@ -89,12 +85,8 @@ class User < ActiveRecord::Base
projects.first projects.first
end end
def self.generate_random_password
(0...8).map{ ('a'..'z').to_a[rand(26)] }.join
end
def first_name def first_name
name.split(" ").first unless name.blank? name.split.first unless name.blank?
end end
def self.find_for_ldap_auth(omniauth_info) def self.find_for_ldap_auth(omniauth_info)
...@@ -104,8 +96,9 @@ class User < ActiveRecord::Base ...@@ -104,8 +96,9 @@ class User < ActiveRecord::Base
if @user = User.find_by_email(email) if @user = User.find_by_email(email)
@user @user
else else
password = generate_random_password password = Devise.friendly_token[0, 8].downcase
@user = User.create(:name => name, @user = User.create(
:name => name,
:email => email, :email => email,
:password => password, :password => password,
:password_confirmation => password :password_confirmation => password
...@@ -163,4 +156,3 @@ end ...@@ -163,4 +156,3 @@ end
# authentication_token :string(255) # authentication_token :string(255)
# dark_scheme :boolean default(FALSE), not null # dark_scheme :boolean default(FALSE), not null
# #
...@@ -14,6 +14,7 @@ describe User do ...@@ -14,6 +14,7 @@ describe User do
it { should respond_to(:is_admin?) } it { should respond_to(:is_admin?) }
it { should respond_to(:identifier) } it { should respond_to(:identifier) }
it { should respond_to(:name) } it { should respond_to(:name) }
it { should respond_to(:private_token) }
end end
it "should return valid identifier" do it "should return valid identifier" do
...@@ -67,4 +68,3 @@ end ...@@ -67,4 +68,3 @@ end
# authentication_token :string(255) # authentication_token :string(255)
# dark_scheme :boolean default(FALSE), not null # dark_scheme :boolean default(FALSE), not null
# #
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment