Module: Card::Auth::Current
- Included in:
- Card::Auth
- Defined in:
- card/lib/card/auth/current.rb
Overview
methods for setting current account
Instance Method Summary collapse
-
#current_card ⇒ Card
(also: #current)
current accounted card (must have +*account).
-
#current_id ⇒ Integer
id of current user card.
-
#current_id=(card_id) ⇒ Integer
set the id of the current user.
-
#current_roles ⇒ Object
-
#find_account_by_email(email) ⇒ +*account card?
find +*account card by +*email card.
-
#reset ⇒ Object
-
#session ⇒ Object
get session object from Env return [Session].
-
#session_user_key ⇒ Object
-
#signed_in? ⇒ true/false
current user is not anonymous.
-
#signin(cardish) ⇒ Object
set current user in process and session.
-
#signin_with(opts = {}) ⇒ Object
set current from token, api_key, or session.
-
#signin_with_session ⇒ Object
get :user id from session and set Auth.current_id.
Instance Method Details
#current_card ⇒ Card Also known as: current
current accounted card (must have +*account)
21 22 23 24 25 |
# File 'card/lib/card/auth/current.rb', line 21 def current_card return @current_card if @current_card&.id == current_id @current_card = Card[current_id] end |
#current_id ⇒ Integer
id of current user card.
7 8 9 |
# File 'card/lib/card/auth/current.rb', line 7 def current_id @current_id ||= Card::AnonymousID end |
#current_id=(card_id) ⇒ Integer
set the id of the current user.
13 14 15 16 17 |
# File 'card/lib/card/auth/current.rb', line 13 def current_id= card_id reset card_id = card_id.to_i if card_id.present? @current_id = card_id end |
#current_roles ⇒ Object
28 29 30 31 32 33 |
# File 'card/lib/card/auth/current.rb', line 28 def current_roles return [] unless signed_in? @current_roles ||= [:anyone_signed_in.cardname] + Set::Self::Role.role_ids(current_id).map(&:cardname) end |
#find_account_by_email(email) ⇒ +*account card?
find +*account card by +*email card
72 73 74 |
# File 'card/lib/card/auth/current.rb', line 72 def find_account_by_email email find_account_by :email, email.strip.downcase end |
#reset ⇒ Object
76 77 78 |
# File 'card/lib/card/auth/current.rb', line 76 def reset @as_id = @as_card = @current_id = @current_card = @current_roles = nil end |
#session ⇒ Object
get session object from Env return [Session]
65 66 67 |
# File 'card/lib/card/auth/current.rb', line 65 def session Card::Env.session end |
#session_user_key ⇒ Object
80 81 82 |
# File 'card/lib/card/auth/current.rb', line 80 def session_user_key "user_#{Cardio.database.underscore}".to_sym end |
#signed_in? ⇒ true/false
current user is not anonymous
43 44 45 |
# File 'card/lib/card/auth/current.rb', line 43 def signed_in? current_id != Card::AnonymousID end |
#signin(cardish) ⇒ Object
set current user in process and session
36 37 38 39 |
# File 'card/lib/card/auth/current.rb', line 36 def signin cardish session[session_user_key] = self.current_id = Card.id(cardish) || Card::AnonymousID end |
#signin_with(opts = {}) ⇒ Object
set current from token, api_key, or session
48 49 50 51 52 53 54 |
# File 'card/lib/card/auth/current.rb', line 48 def signin_with opts={} if opts[:token] signin_with_token opts[:token] else signin_with_session end end |
#signin_with_session ⇒ Object
get :user id from session and set Auth.current_id
57 58 59 60 61 |
# File 'card/lib/card/auth/current.rb', line 57 def signin_with_session card_id = session[session_user_key] card_id = nil unless card_id.card&.account? signin card_id end |