Module: Card::Auth

Extended by:
Current, Permissions, Proxy, Setup
Defined in:
lib/card/auth.rb,
lib/card/auth/proxy.rb,
lib/card/auth/setup.rb,
lib/card/auth/current.rb,
lib/card/auth/permissions.rb

Overview

Singleton methods for authentication. Manages current user, "as" user, and password verification.

Defined Under Namespace

Modules: Current, Permissions, Proxy, Setup

Constant Summary

Constants included from Permissions

Permissions::RECAPTCHA_DEFAULTS

Constants included from Setup

Setup::SETUP_COMPLETED_KEY

Class Method Summary collapse

Methods included from Permissions

admin?, always_ok?, always_ok_usr_id?, createable_types, has_role?

Methods included from Proxy

as, as_bot, as_card, as_id, get_user_id

Methods included from Setup

instant_account_activation, needs_setup?, simulate_setup_need!

Methods included from Current

current, current=, current_id, current_id=, find_account_by, find_account_by_email, find_account_by_token, serialize, session, set_current, set_current_from_session, set_current_from_token, signed_in?, signin, with

Class Method Details

.authenticate(email, password) ⇒ +*account card?

authenticate a user by their login name and unencrypted password.

Parameters:

  • email (String)
  • password (String)

Returns:

  • (+*account card, nil)


22
23
24
25
26
27
28
29
30
# File 'lib/card/auth.rb', line 22

def authenticate email, password
   = Auth. email
  case
  when !                                 then nil
  when !.active?                         then nil
  when Card.config.no_authentication            then 
  when password_valid?(, password.strip) then 
  end
end

.encrypt(password, salt) ⇒ SHA1 String

encrypt password string with the given salt.

Returns:

  • (SHA1 String)


41
42
43
# File 'lib/card/auth.rb', line 41

def encrypt password, salt
  Digest::SHA1.hexdigest "#{salt}--#{password}--"
end

.password_valid?(account, password) ⇒ Boolean

check whether password is correct for account card

Parameters:

  • account (+*account card)
  • password (String)

Returns:

  • (Boolean)


35
36
37
# File 'lib/card/auth.rb', line 35

def password_valid? , password
  .password == encrypt(password, .salt)
end