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
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

Parameters:

  • email (String)

Returns:

  • (+*account card, nil)


72
73
74
# File 'card/lib/card/auth/current.rb', line 72

def  email
   :email, email.strip.downcase
end

#resetObject



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

#sessionObject

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_keyObject



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

Returns:

  • (true/false)


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  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  opts={}
  if opts[:token]
     opts[:token]
  else
    
  end
end

#signin_with_sessionObject

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 
  card_id = session[session_user_key]
  card_id = nil unless card_id.card&.account?
   card_id
end