Class: Gaku::Api::V1::AuthenticationController

Inherits:
BaseController show all
Defined in:
app/controllers/gaku/api/v1/authentication_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_user

Instance Method Summary collapse

Instance Method Details

#authenticateObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/gaku/api/v1/authentication_controller.rb', line 7

def authenticate
  command = Gaku::Api::AuthenticateUser.call(
    username: params[:username],
    password: params[:password]
  )

  if command.success?
    render(respond_format => { tokens: command.result })
  else
    render(respond_format => { error: command.errors }, status: :unauthorized)
  end
end

#refreshObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/gaku/api/v1/authentication_controller.rb', line 20

def refresh
  refresh_token = params[:refresh_token]
  command = Gaku::Api::RefreshAuthenticateUser.call(params[:refresh_token])

  if command.success?
    render respond_format => { tokens: command.result }
  else
    render respond_format => { error: command.errors }, status: :unauthorized
  end
end