2

I build a rest api with CakePHP 3.x but when I testing with Postman 3.1.1 is 500 internal server error:

The view for UsersController::token() was not found.)

In file routes.php :

Router::prefix('api', function ($routes) {
  $routes->extensions(['json']);
  $routes->resources('Users');
  $routes->resources('Organizations');
  $routes->resources('AccountRegistrations');
  $routes->fallbacks('InflectedRoute');
});

In controller :

public function token() {   
  $user = $this->Auth->identify();
  if (!$user) {
    $message ='Invalid username or password';   
  }
  $this->set([
    'success' => true,
    'data' => [
      'token' => $token = \JWT::encode([
        'id' => $user['id'],
        'exp' =>  time() + 604800
      ],
      Security::salt())
    ],
    '_serialize' => ['success', 'data']
  ]);
}
Oops D'oh
  • 941
  • 1
  • 15
  • 34
JachMa
  • 21
  • 2

0 Answers0