Class: Workarea::Api::Storefront::AuthenticationTokensController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/workarea/api/storefront/authentication_tokens_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#assert_current_metrics_id, #cache_page, #skip_session

Methods included from Authentication

#authentication?, #current_user, find_user

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/workarea/api/storefront/authentication_tokens_controller.rb', line 7

def create
  user = User.(params[:email], params[:password])

  if user.blank?
    render(
      json: { problem: t('workarea.api.storefront.authentication_tokens.error') },
      status: :unprocessable_entity
    )
  else
    @authentication_token = User::AuthenticationToken.create!(user: user)
  end
end

#updateObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/workarea/api/storefront/authentication_tokens_controller.rb', line 20

def update
  @authentication_token = authenticate_with_http_token do |token, options|
    User::AuthenticationToken.refresh!(token, options)
  end

  if @authentication_token.blank?
    render(
      json: { problem: t('workarea.api.storefront.authentication_tokens.error') },
      status: :unprocessable_entity
    )
  end
end