### Home Classes Methods

### In Files

- app/models/user.rb

### Parent

ActiveRecord::Base

### Methods

- ::authenticate
- ::encrypt_password
- #ensure_an_admin_remains
- #generate_salt
- #password=
- #password_must_be_present

### Files

- README_FOR_APP

### Class Index

Quicksearch

- AdminController
- AdminHelper
- ApplicationController
- ApplicationHelper
- Cart
- CartsController
- CartsHelper
- LineItem
- LineItemsController
- LineItemsHelper
- Notifier
- Order
- OrdersController
- OrdersHelper
- Product
- ProductsController
- ProductsHelper
- SessionsController
- SessionsHelper
- StoreController
- StoreHelper
- User
- UsersController
- UsersHelper

No matching classes.

# User

### Attributes

password_confirmation[RW]
password[R]

### Public Class Methods

authenticate(name, password) click to toggle source

        # File app/models/user.rb, line 20
    20:   def User.authenticate(name, password)

    21:     if user = find_by_name(name)

    22:       if user.hashed_password == encrypt_password(password, user.salt)

    23:         user

    24:       end

    25:     end

    26:   end

encrypt_password(password, salt) click to toggle source

        # File app/models/user.rb, line 28
    28:   def User.encrypt_password(password, salt)

    29:     Digest::SHA2.hexdigest(password + "blabla" + salt)

    30:   end

### Public Instance Methods

ensure_an_admin_remains() click to toggle source

        # File app/models/user.rb, line 14
    14:   def ensure_an_admin_remains

    15:     if User.count.zero?

    16:       raise "Nelze odstranit posledního uživatele"

    17:     end

    18:   end

password=(password) click to toggle source

‘password’ je virtuální atribut

        # File app/models/user.rb, line 33
    33:   def password=(password)

    34:     @password = password

    35:

    36:     if password.present?

    37:       generate_salt

    38:       self.hashed_password = self.class.encrypt_password(password, salt)

    39:     end

    40:   end

### Private Instance Methods

generate_salt() click to toggle source

        # File app/models/user.rb, line 48
    48:     def generate_salt

    49:       self.salt = self.object_id.to_s + rand.to_s

    50:     end

password_must_be_present() click to toggle source

        # File app/models/user.rb, line 44
    44:     def password_must_be_present

    45:       errors.add(:password, "Chybí heslo") unless hashed_password.present?

    46:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.