Class: TestController

Inherits:
Rubee::BaseController show all
Includes:
Rubee::AuthTokenable
Defined in:
lib/tests/controllers/auth_tokenable_test.rb

Constant Summary

Constants included from Rubee::AuthTokenable

Rubee::AuthTokenable::EXPIRE, Rubee::AuthTokenable::KEY

Instance Method Summary collapse

Methods included from Rubee::AuthTokenable

included

Methods inherited from Rubee::BaseController

attach_websocket!, #css, #extract_params, #handle_websocket, #headers, #image, #initialize, #js, #params, #render_template, #response_with, #websocket, #websocket_connections

Methods included from Rubee::Hookable

included

Constructor Details

This class inherits a constructor from Rubee::BaseController

Instance Method Details

#loginObject

POST /test/login (login logic)



11
12
13
14
15
16
17
18
19
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 11

def 
  if authentificate! # AuthTokenable method that init @token_header
    # Redirect to restricted area, make sure headers: @token_header is passed
    response_with(type: :json, object: { ok: :ok }, headers: @token_header)
  else
    @error = "Wrong email or password"
    response_with(type: :json, object: { error: 'user unauthenticated' }, status: :unauthenticated)
  end
end

#logoutObject

POST /test/logout (logout logic)



22
23
24
25
26
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 22

def logout
  unauthentificate! # AuthTokenable method aimed to handle logout action.
  # Make sure @zeroed_token_header is paRssed within headers options
  response_with(type: :json, object: { ok: 'logged out' }, headers: @zeroed_token_header)
end

#showObject



6
7
8
# File 'lib/tests/controllers/auth_tokenable_test.rb', line 6

def show
  response_with(type: :json, object: { ok: :ok })
end