Advertisement
Guest User

Untitled

a guest
May 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. public function login()
  2. {
  3. // If the user is already logged in, redirect to home page
  4. if ($this->Auth->user()) {
  5. return $this->redirect($this->Auth->redirectUrl());
  6. }
  7.  
  8. if ($this->request->is('post')) {
  9. $emptyEmail = false;
  10.  
  11. try {
  12. $user = $this->Auth->identify();
  13. } catch (\RuntimeException $e) {
  14. $user = [];
  15. $emptyEmail = true;
  16. }
  17.  
  18. if ($user) {
  19. $this->Auth->setUser($user);
  20.  
  21. $user = $this->Users->get($this->Auth->user('id'));
  22.  
  23. if ($this->Auth->authenticationProvider()->needsPasswordRehash()) {
  24. $user->password = $this->request->data('password');
  25.  
  26. $this->Users->save($user);
  27. }
  28.  
  29. $user->last_login = date('Y-m-d H:i:s');
  30. $this->Users->save($user);
  31.  
  32. //$this->_setCookie();
  33.  
  34. return $this->redirect($this->Auth->redirectUrl());
  35. } else {
  36. if ($emptyEmail) {
  37. $this->Flash->auth(
  38. __('Sorry, but for social login you need to allow sharing your email!'),
  39. 'default',
  40. [],
  41. 'auth'
  42. );
  43. } else {
  44. $this->Flash->auth(
  45. __('Sorry, invalid user or password.'),
  46. 'default',
  47. [],
  48. 'auth'
  49. );
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement