Class: Account

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_email_address(address) ⇒ Object



7
8
9
10
11
12
# File 'app/models/account.rb', line 7

def self.find_by_email_address(address)
  p = Person.find_by_email_address(address)
  if not p.nil?
    return p.
  end
end

.hash_password(p) ⇒ Object



22
23
24
25
26
27
28
# File 'app/models/account.rb', line 22

def self.hash_password(p)
  if p.nil?
    return nil
  else
    return Digest::MD5.hexdigest(p)
  end
end

Instance Method Details

#check_password(p) ⇒ Object



30
31
32
# File 'app/models/account.rb', line 30

def check_password(p)
  return self.password == Account.hash_password(p)
end

#generate_activation(address = nil) ⇒ Object



43
44
45
46
47
48
49
# File 'app/models/account.rb', line 43

def generate_activation(address=nil)
  self.active = false
  self.activation_key = Digest::MD5.hexdigest("#{password} #{Time.now.to_s}")
  self.save
  
  AuthNotifier::(self, address)
end

#generate_password(address = nil, length = 6) ⇒ Object



34
35
36
37
38
39
40
41
# File 'app/models/account.rb', line 34

def generate_password(address = nil, length = 6)
  chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('1'..'9').to_a - ['o', 'O', 'i', 'I']
  genpwd = Array.new(length) { chars[rand(chars.size)] }.join
  self.password= genpwd
  save
  AuthNotifier::deliver_generated_password(self, genpwd, address)
  return genpwd
end

#password=(p) ⇒ Object



14
15
16
17
18
19
20
# File 'app/models/account.rb', line 14

def password=(p)
  if not p.nil?
    write_attribute("password", Account.hash_password(p))
  else
    write_attribute("password", nil)
  end
end