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

Methods

Attributes

password  [RW]  has_and_belongs_to_many :roles

Public Class methods

Return the User with the given name and plain-text password

[Source]

    # File app/models/user.rb, line 30
30:   def self.login(name, password)
31:     hashed_password = hash_password(password || "")
32:     find(:first,
33:          :conditions => ["name = ? and hashed_password = ? and confirmed = 1",
34:     name, hashed_password])
35:   end

Public Instance methods

Clear out the plain-text password once we’ve saved this row. This stops it being made available in the session

[Source]

    # File app/models/user.rb, line 54
54:   def after_create
55:     @password = nil
56:   end

When a new User is created, it initially has a plain-text password. We convert this to an SHA1 hash before saving the user in the database.

[Source]

    # File app/models/user.rb, line 47
47:   def before_create
48:     self.hashed_password = User.hash_password(self.password)
49:   end

Log in if the name and password (after hashing) match the database, or if the name matches an entry in the database with no password

[Source]

    # File app/models/user.rb, line 40
40:   def try_to_login
41:     User.login(self.name, self.password)
42:   end

[Validate]