Class User
In: app/models/user.rb
Parent: ActiveRecord::Base

Methods

Attributes

password_confirmation  [RW] 

Public Class methods

Authenticate against the database

[Source]

    # File app/models/user.rb, line 50
50:   def self.authenticate( username, password )
51:     @user = User.find( :first, :conditions => [ 'username = ?', username ] )
52:     if @user.nil?
53:       @user = User.find( :first, :conditions => [ 'email = ?', username ] )
54:     end
55:     return nil if @user.nil?
56:     return @user if User.hash_password( password, @user.passwd_salt ) == @user.passwd_hash
57:     nil
58:   end

Public Instance methods

Both of them, together

[Source]

    # File app/models/user.rb, line 33
33:   def fullname
34:     "#{ self.fname } #{ self.lname }"
35:   end

Find permission by iterating over group permissions

[Source]

    # File app/models/user.rb, line 38
38:   def has_perm?( perm )
39:     permission = Permission.find_by_name( perm )
40:     raise "#{perm} not found" if permission.nil?
41:     groups.each do |g|
42:       g.permissions.each do |p|
43:         return true if p.id == permission.id
44:       end
45:     end
46:     return false
47:   end

Convenience method

[Source]

    # File app/models/user.rb, line 61
61:   def password
62:     @password
63:   end

Setter method assigning a new password. Re-salts automatically.

[Source]

    # File app/models/user.rb, line 66
66:   def password=( passwd )
67:     @password = passwd
68:     return if passwd.blank?
69:     self.passwd_salt = User.salt
70:     self.passwd_hash = User.hash_password( @password, self.passwd_salt )
71:   end

[Validate]