public function check(Application $app, $validateKey = '')
 {
     $userActivated = false;
     $userModel = new UserModelBase();
     if ($userModel->readByProperty('validationKey', $validateKey)) {
         if ($userModel->validate()) {
             $userModel->active = true;
             $userModel->write();
             $userActivated = true;
         }
     }
     if ($userActivated) {
         return $this->renderPage($app, 'validate');
     } else {
         // if the validation has expired, chances are they have already validated.  Redirect to login
         return $app->redirect('/auth/login');
     }
 }
 /**
  * Removes a user from the collection
  * Project references to this user are also removed
  */
 public function remove()
 {
     foreach ($this->projects->refs as $id) {
         /* @var Id $id */
         $project = new ProjectModel($id->asString());
         $project->removeUser($this->id->asString());
         $project->write();
     }
     parent::remove();
 }
 /**
  * @param Application $app
  * @param string $resetPasswordKey
  * @param string $newPassword
  * @throws UserUnauthorizedException
  * @return string $userId
  */
 public static function resetPassword(Application $app, $resetPasswordKey = '', $newPassword = '')
 {
     $user = new UserModelBase();
     if (!$user->readByProperty('resetPasswordKey', $resetPasswordKey)) {
         $app['session']->getFlashBag()->add('errorMessage', 'Your password reset cannot be completed. Please try again.');
         return false;
     }
     if (!$user->hasForgottenPassword()) {
         $app['session']->getFlashBag()->add('errorMessage', 'Your password reset cannot be completed. It may have expired. Please try again.');
         return false;
     }
     $userId = $user->id->asString();
     UserCommands::changePassword($userId, $newPassword, $userId);
     $app['session']->getFlashBag()->add('infoMessage', 'Your password has been reset. Please login.');
     return $user->write();
 }
 /**
  * @param string $validationKey
  * @return array
  * @throws \Exception
  */
 public static function readForRegistration($validationKey)
 {
     $user = new UserModelBase();
     if (!$user->readByProperty('validationKey', $validationKey)) {
         return array();
     }
     if (!$user->validate(false)) {
         throw new \Exception("Sorry, your registration link has expired.");
     }
     return JsonEncoder::encode($user);
 }