Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login()
- {
- // If the user is already logged in, redirect to home page
- if ($this->Auth->user()) {
- return $this->redirect($this->Auth->redirectUrl());
- }
- if ($this->request->is('post')) {
- $emptyEmail = false;
- try {
- $user = $this->Auth->identify();
- } catch (\RuntimeException $e) {
- $user = [];
- $emptyEmail = true;
- }
- if ($user) {
- $this->Auth->setUser($user);
- $user = $this->Users->get($this->Auth->user('id'));
- if ($this->Auth->authenticationProvider()->needsPasswordRehash()) {
- $user->password = $this->request->data('password');
- $this->Users->save($user);
- }
- $user->last_login = date('Y-m-d H:i:s');
- $this->Users->save($user);
- //$this->_setCookie();
- return $this->redirect($this->Auth->redirectUrl());
- } else {
- if ($emptyEmail) {
- $this->Flash->auth(
- __('Sorry, but for social login you need to allow sharing your email!'),
- 'default',
- [],
- 'auth'
- );
- } else {
- $this->Flash->auth(
- __('Sorry, invalid user or password.'),
- 'default',
- [],
- 'auth'
- );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement