Class: Motion::Authentication::DeviseTokenAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/project/strategies/devise_token_auth.rb

Class Method Summary collapse

Class Method Details

.authorization_headerObject



19
20
21
22
23
# File 'lib/project/strategies/devise_token_auth.rb', line 19

def authorization_header
  token = MotionKeychain.get :auth_token
  email = MotionKeychain.get :auth_email
  %Q|Token token="#{token}", email="#{email}"|
end

.sign_in(sign_in_url, params, &block) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/project/strategies/devise_token_auth.rb', line 5

def (, params, &block)
  AFMotion::JSON.post(, user: params) do |response|
    if response.success?
      store_auth_tokens(response.object)
    end
    block.call(response)
  end
end

.sign_out(&block) ⇒ Object



29
30
31
32
33
# File 'lib/project/strategies/devise_token_auth.rb', line 29

def sign_out(&block)
  MotionKeychain.remove :auth_email
  MotionKeychain.remove :auth_token
  block.call
end

.signed_in?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/project/strategies/devise_token_auth.rb', line 25

def signed_in?
  !! MotionKeychain.get(:auth_token)
end

.store_auth_tokens(data) ⇒ Object



14
15
16
17
# File 'lib/project/strategies/devise_token_auth.rb', line 14

def store_auth_tokens(data)
  MotionKeychain.set :auth_email, data["email"]
  MotionKeychain.set :auth_token, data["token"]
end