Class: User

Inherits:
BaseNew
  • Object
show all
Defined in:
app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseNew

Proxy, install_data, install_data_hooks, #with_timestamps?

Class Method Details

.account_name_with_uuid(uuid) ⇒ Object



50
51
52
53
54
# File 'app/models/user.rb', line 50

def (uuid)
  h = Hash.new
  User.find(:uuid => uuid).accounts.each{|row| h.store(row.name,row.uuid) }
  h
end

.authenticate(login_id, password) ⇒ Object



38
39
40
41
42
# File 'app/models/user.rb', line 38

def authenticate(,password)
  return nil if .nil? || password.nil?
  u = User.find(:login_id=>, :password => encrypt_password(password))
  u.nil? ? false : u
end

.encrypt_password(password) ⇒ Object



60
61
62
63
# File 'app/models/user.rb', line 60

def encrypt_password(password)
  salt = Digest::SHA1.hexdigest(DcmgrGui::Application.config.secret_token)
  Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end

.get_user(uuid) ⇒ Object



44
45
46
47
48
# File 'app/models/user.rb', line 44

def get_user(uuid)
  return nil if uuid.nil?
  u = User.find(:uuid=>uuid)
  u.nil? ? false : u
end

.primary_account_id(uuid) ⇒ Object



56
57
58
# File 'app/models/user.rb', line 56

def (uuid)
  User.find(:uuid => uuid).
end

.update_last_login(user_id) ⇒ Object



65
66
67
68
69
# File 'app/models/user.rb', line 65

def (user_id)
  u = User.find(:id => user_id)
  u. = Time.now
  u.save
end

.update_settings(user_id, params) ⇒ Object



71
72
73
74
75
76
77
# File 'app/models/user.rb', line 71

def update_settings(user_id, params)
  u = User.find(:id => user_id)
  p params
  u.time_zone = params[:time_zone] || u.time_zone
  u.locale = params[:locale] || u.locale
  u.save
end

Instance Method Details

#before_createObject



21
22
23
24
25
26
# File 'app/models/user.rb', line 21

def before_create
  set(:locale => I18n.default_locale.to_s)
  set(:time_zone => Time.zone.name)
  set(:last_login_at => Time.now.utc)
  super
end

#before_destroyObject

Removes all relations to accounts before deleting the record



29
30
31
32
33
34
35
# File 'app/models/user.rb', line 29

def before_destroy
  relations = self.accounts
  for ss in 0...relations.length do
    self.(relations[0])		  
  end
  super
end