Class: Appoxy::Sessions::User

Inherits:
SimpleRecord::Base
  • Object
show all
Defined in:
lib/sessions/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.email_is_valid?(email) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/sessions/user.rb', line 44

def self.email_is_valid?(email)
  return email.present? && email =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
end

.included(base) ⇒ Object



7
8
9
# File 'lib/sessions/user.rb', line 7

def self.included(base)
  puts self.name + " included in " + base.name
end

Instance Method Details

#activate!Object



59
60
61
62
# File 'lib/sessions/user.rb', line 59

def activate!
  self.activation_code=nil
  self.status         = "active"
end

#authenticate(password) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sessions/user.rb', line 65

def authenticate(password)

  return nil if attributes["password"].blank? # if the user has no password (will this happen?  maybe for invites...)

  # This is a normal unencrypted password, temporary
  if attributes["password"][0].length < 100
    self.password = attributes["password"][0]
    self.save
  end

  (self.password == password) ? self : nil
end

#is_active?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sessions/user.rb', line 49

def is_active?
  status == "active"
end

#set_activation_codeObject



54
55
56
# File 'lib/sessions/user.rb', line 54

def set_activation_code
  self.activation_code=Digest::SHA1.hexdigest(email.to_s+Time.now.to_s)
end

#set_rememberObject



78
79
80
81
82
# File 'lib/sessions/user.rb', line 78

def set_remember
  rme_string            = Appoxy::Utils.random_string(50)
  self.remember_token   = rme_string
  self.remember_token_expires = 30.days.since
end

#validateObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sessions/user.rb', line 31

def validate
#        errors.add("email", "is not valid") unless User.email_is_valid?(email)

  if status == "invited"
    # doesn't need password
  elsif open_id
    # doesn't need password
  else
#          errors.add("password", "must be at least 6 characters long.") if password.blank?
  end
end