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/token.rb,
lib/card/auth/current.rb,
lib/card/auth/permissions.rb
Overview
Singleton methods for account authentication and contextualization.
Manages current user, "as" user, and password verification.
Defined Under Namespace
Modules: Current, Permissions, Proxy, Setup, Token
Constant Summary
Constants included from Setup
Class Method Summary collapse
-
.authenticate(email, password) ⇒ +*account card?
authenticate a user by their login name and unencrypted password.
-
.encrypt(password, salt) ⇒ SHA1 String
encrypt password string with the given salt.
-
.password_valid?(account, password) ⇒ Boolean
check whether password is correct for account card.
Methods included from Permissions
admin?, always_cache, always_ok?, always_ok_usr_id?, createable_types, has_role?, update_always_cache
Methods included from Proxy
as, as_bot, as_card, as_id, get_user_id
Methods included from Setup
hide_accounts!, instant_account_activation, needs_setup?, simulate_setup_need!
Methods included from Current
current, current_id, current_roles, database, find_account_by, find_account_by_api_key, find_account_by_email, serialize, session, session_user, session_user_key, set_session_user, signed_in?, signin, signin_with, signin_with_api_key, signin_with_session, signin_with_token, with
Class Method Details
.authenticate(email, password) ⇒ +*account card?
authenticate a user by their login name and unencrypted password.
21 22 23 24 25 26 27 28 29 |
# File 'lib/card/auth.rb', line 21 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) ⇒ SHA1 String
encrypt password string with the given salt.
40 41 42 |
# File 'lib/card/auth.rb', line 40 def encrypt password, salt Digest::SHA1.hexdigest "#{salt}--#{password}--" end |
.password_valid?(account, password) ⇒ Boolean
check whether password is correct for account card
34 35 36 |
# File 'lib/card/auth.rb', line 34 def password_valid? account, password account.password == encrypt(password, account.salt) end |