module Card::Auth

Singleton methods for account authentication and contextualization.

Manages current user, “as” user, and password verification.

Public Class Methods

authenticate(email, password) click to toggle source

authenticate a user by their login name and unencrypted password. @param email [String] @param password [String] @return [+*account card, nil]

# File lib/card/auth.rb, line 19
def authenticate email, password
  account = Auth.find_account_by_email email
  case
  when !account                                 then nil
  when !account.active?                         then nil
  when Card.config.no_authentication            then account
  when password_valid?(account, password.strip) then account
  end
end
encrypt(password, salt) click to toggle source

encrypt password string with the given salt. @return [SHA1 String]

# File lib/card/auth.rb, line 38
def encrypt password, salt
  Digest::SHA1.hexdigest "#{salt}--#{password}--"
end
password_valid?(account, password) click to toggle source

check whether password is correct for account card @param account [+*account card] @param password [String]

# File lib/card/auth.rb, line 32
def password_valid? account, password
  account.password == encrypt(password, account.salt)
end
serialize() click to toggle source
# File lib/card/auth.rb, line 42
def serialize
  { as_id: as_id, current_id: current_id }
end