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)


34
35
36
# File 'lib/sessions/user.rb', line 34

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



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

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

#authenticate(password) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sessions/user.rb', line 57

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)


39
40
41
# File 'lib/sessions/user.rb', line 39

def is_active?
    status == "active"
end

#set_activation_codeObject



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

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

#validateObject



23
24
25
26
27
28
29
30
31
# File 'lib/sessions/user.rb', line 23

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

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