Commit faa0ec7c authored by Nihad Abbasov's avatar Nihad Abbasov

cleanup User model

parent fc74627f
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, :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :bio,
:name, :projects_limit, :skype, :linkedin, :twitter, :dark_scheme, :theme_id
......@@ -46,7 +43,7 @@ class User < ActiveRecord::Base
validates :bio, :length => { :within => 0..255 }
before_create :ensure_authentication_token
before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token
scope :not_in_project, lambda { |project| where("id not in (:ids)", :ids => project.users.map(&:id) ) }
......@@ -76,7 +73,6 @@ class User < ActiveRecord::Base
admin
end
def require_ssh_key?
keys.count == 0
end
......@@ -89,12 +85,8 @@ class User < ActiveRecord::Base
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?
name.split.first unless name.blank?
end
def self.find_for_ldap_auth(omniauth_info)
......@@ -104,8 +96,9 @@ class User < ActiveRecord::Base
if @user = User.find_by_email(email)
@user
else
password = generate_random_password
@user = User.create(:name => name,
password = Devise.friendly_token[0, 8].downcase
@user = User.create(
:name => name,
:email => email,
:password => password,
:password_confirmation => password
......@@ -163,4 +156,3 @@ end
# authentication_token :string(255)
# dark_scheme :boolean default(FALSE), not null
#
......@@ -14,6 +14,7 @@ describe User do
it { should respond_to(:is_admin?) }
it { should respond_to(:identifier) }
it { should respond_to(:name) }
it { should respond_to(:private_token) }
end
it "should return valid identifier" do
......@@ -67,4 +68,3 @@ end
# authentication_token :string(255)
# 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