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

Instance Method Details

#current_cardCard Also known as: current

current accounted card (must have +*account)

Returns:



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_idInteger

id of current user card.

Returns:

  • (Integer)


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.

Returns:

  • (Integer)


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_rolesObject



28
29
30
31
# File 'card/lib/card/auth/current.rb', line 28

def current_roles
  @current_roles ||= [Card.fetch_name(:anyone_signed_in),
                      current.fetch(:roles)&.item_names].flatten.compact
end

#find_account_by_email(email) ⇒ +*account card?

find +*account card by +*email card

Parameters:

  • email (String)

Returns:

  • (+*account card, nil)


70
71
72
# File 'card/lib/card/auth/current.rb', line 70

def  email
   :email, email.strip.downcase
end

#resetObject



74
75
76
# File 'card/lib/card/auth/current.rb', line 74

def reset
  @as_id = @as_card = @current_id = @current_card = @current_roles = nil
end

#sessionObject

get session object from Env return [Session]



63
64
65
# File 'card/lib/card/auth/current.rb', line 63

def session
  Card::Env.session
end

#session_user_keyObject



78
79
80
# File 'card/lib/card/auth/current.rb', line 78

def session_user_key
  "user_#{Cardio.database_name.underscore}".to_sym
end

#signed_in?true/false

current user is not anonymous

Returns:

  • (true/false)


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

def signed_in?
  current_id != Card::AnonymousID
end

#signin(cardish) ⇒ Object

set current user in process and session



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

def  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



46
47
48
49
50
51
52
# File 'card/lib/card/auth/current.rb', line 46

def  _opts={}
  if opts[:token]
     opts[:token]
  else
    
  end
end

#signin_with_sessionObject

get :user id from session and set Auth.current_id



55
56
57
58
59
# File 'card/lib/card/auth/current.rb', line 55

def 
  card_id = session[session_user_key]
  card_id = nil unless Card.exists? card_id
   card_id
end