Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. //UsersController
  2. public function token()
  3. {
  4. $user = $this->Auth->identify();
  5. if (!$user) {
  6. throw new UnauthorizedException('Invalid username or password');
  7. }else{
  8. $this->Auth->setUser($user);
  9. };
  10.  
  11. $this->set([
  12. 'success' => true,
  13. 'user_id'=>$user['id'],
  14. // SET NEW TOKEN BY REQUEST
  15. 'token' => JWT::encode([
  16. 'sub' => $user['id'],
  17. 'exp' => time() + 604800
  18. ],Security::salt()),
  19. '_serialize' => ['success', 'token' , 'user_id']
  20. ]);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement