| 23 | | if ($this->Request->isPost() && !empty($this->params['user'])){ |
| 24 | | if($this->User->signUp($this->params['user'])){ |
| 25 | | $this->flash_options = array('seconds_to_close' => 10); |
| 26 | | $this->flash['success'] = $this->t('Your account has been successfully created'); |
| 27 | | $this->redirectToAction('sign_in'); |
| 28 | | } |
| 29 | | } |
| 30 | | } |
| 31 | | |
| 32 | | function is_login_available() |
| 33 | | { |
| 34 | | if(!empty($this->params['login'])){ |
| 35 | | $this->User->set('login', $this->params['login']); |
| 36 | | $this->User->validatesUniquenessOf('login'); |
| 37 | | if($this->User->getErrorsOn('login')){ |
| 38 | | $this->renderText('0'); |
| 39 | | return ; |
| 40 | | } |
| 41 | | } |
| 42 | | $this->renderText('1'); |
| 43 | | } |
| 44 | | |
| 45 | | function logout() |
| 46 | | { |
| 47 | | $this->flash['message'] = $this->t("You have successfully logged out."); |
| 48 | | $this->_perform_logout(); |
| 49 | | } |
| 50 | | |
| 51 | | function _perform_logout($redirect = true) |
| 52 | | { |
| 53 | | $this->Sentinel->init($this); |
| 54 | | $this->Sentinel->unsetCurrentUser(); |
| 55 | | if($redirect){ |
| 56 | | $settings = Ak::getSettings('admin'); |
| 57 | | $this->redirectTo(empty($settings['sign_in_url'])? array('action'=>'sign_in') : $settings['sign_in_url']); |
| 58 | | } |
| 59 | | } |
| 60 | | |
| 61 | | function password_reminder() |
| 62 | | { |
| 63 | | if($this->Request->isPost()){ |
| 64 | | $this->Sentinel->init($this); |
| 65 | | if($User = $this->User->findFirstBy('email', @$this->params['email'])){ |
| 66 | | if($this->Sentinel->sendPasswordReminder($User)){ |
| 67 | | $this->renderAction('password_reminder_sent'); |
| 68 | | }else{ |
| 69 | | $this->flash_now['error'] = $this->t('There was an error while trying to send you the instructions to reset your password.'); |
| 70 | | } |
| 71 | | }else{ |
| 72 | | $this->flash_now['error'] = $this->t('Account not found'); |
| 73 | | } |
| 74 | | } |
| 75 | | |
| 76 | | } |
| 77 | | |
| 78 | | function reset_password() |
| 79 | | { |
| 80 | | if($this->User = $this->Sentinel->authenticateWithToken(@$this->params['token'])){ |
| 81 | | $this->token = $this->User->getToken(array('expires' => true, 'single_use' => true)); |
| 82 | | if($this->Request->isPost()){ |
| 83 | | $this->User->setAttributes($this->params['user']); |
| 84 | | if($this->User->save()){ |
| 85 | | $this->flash['message'] = $this->t("You can now login using your user name and password."); |
| 86 | | $this->_perform_logout(); |
| 87 | | } |
| 88 | | } |
| 89 | | }else{ |
| 90 | | $this->flash['error'] = $this->t('Invalid or expired authentication URL.'); |
| 91 | | $this->redirectToAction('password_reminder'); |
| 92 | | } |
| 93 | | $this->_perform_logout(false); |