Class: Goldberg::User

Inherits:
ActiveRecord::Base show all
Includes:
Model
Defined in:
lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

included

Methods inherited from ActiveRecord::Base

#associated_valid?, #no_errors_in_associated?, #save_associated, #save_associated!, #save_with_unsaved_flag, #to_label, #unsaved=, #unsaved?

Instance Attribute Details

#clear_passwordObject

Returns the value of attribute clear_password.



12
13
14
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 12

def clear_password
  @clear_password
end

#confirm_passwordObject

Returns the value of attribute confirm_password.



13
14
15
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 13

def confirm_password
  @confirm_password
end

Class Method Details

.random_passwordObject



59
60
61
62
63
64
65
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 59

def random_password
  letters = ('A' .. 'Z').to_a + ('a' .. 'z').to_a
  password = (1 .. 6).collect do
    letters[ (rand * letters.length).to_i ]
  end
  password.to_s
end

Instance Method Details

#after_saveObject



29
30
31
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 29

def after_save
  self.clear_password = nil
end

#before_saveObject



23
24
25
26
27
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 23

def before_save
  if self.self_reg_confirmation_required
    self.set_confirmation_key
  end
end

#before_validationObject



15
16
17
18
19
20
21
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 15

def before_validation
  if self.clear_password  # Only update password if changed
    self.password_salt = self.object_id.to_s + rand.to_s
    self.password = Digest::SHA1.hexdigest(self.password_salt +
                                           self.clear_password)
  end
end

#check_password(clear_password) ⇒ Object



33
34
35
36
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 33

def check_password(clear_password)
  self.password == Digest::SHA1.hexdigest(self.password_salt.to_s +
                                          clear_password)
end

#email_valid?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 43

def email_valid?
  self.email &&
    self.email.length > 0 &&
    # http://regexlib.com/DisplayPatterns.aspx
    self.email =~ /\A.+@[^\.].*\.[a-z]{2,}\z/
end

#get_start_pathObject



50
51
52
53
54
55
56
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 50

def get_start_path
  if self.start_path and self.start_path.length > 0
    self.start_path
  else
    self.role.get_start_path
  end
end

#set_confirmation_keyObject



38
39
40
41
# File 'lib/six-updater-web/vendor/plugins/goldberg/app/models/goldberg/user.rb', line 38

def set_confirmation_key
  self.confirmation_key = Digest::SHA1.hexdigest(self.object_id.to_s +
                                                   rand.to_s)
end