/**
  * Activate a user on the specified site and validate email if it was empty, otherwise login
  * @param string $username
  * @param string $password
  * @param string $email
  * @param Website $website
  * @param Application $app
  * @param DeliveryInterface $delivery
  * @return string|boolean $userId|false otherwise
  */
 public static function activate($username, $password, $email, $website, $app, DeliveryInterface $delivery = null)
 {
     CodeGuard::checkEmptyAndThrow($username, 'username');
     CodeGuard::checkEmptyAndThrow($password, 'password');
     CodeGuard::checkEmptyAndThrow($email, 'email');
     CodeGuard::checkNullAndThrow($website, 'website');
     $identityCheck = self::checkIdentity($username, $email, $website);
     if ($website->allowSignupFromOtherSites && $identityCheck->usernameExists && !$identityCheck->usernameExistsOnThisSite && ($identityCheck->emailIsEmpty || $identityCheck->emailMatchesAccount)) {
         $user = new PasswordModel();
         if ($user->readByProperty('username', $username)) {
             if ($user->verifyPassword($password)) {
                 $user = new UserModel($user->id->asString());
                 $user->siteRole[$website->domain] = $website->userDefaultSiteRole;
                 if ($identityCheck->emailIsEmpty) {
                     $user->emailPending = $email;
                 }
                 $user->write();
                 // if website has a default project then add them to that project
                 $project = ProjectModel::getDefaultProject($website);
                 $url = '/app';
                 if ($project) {
                     $project->addUser($user->id->asString(), ProjectRoles::CONTRIBUTOR);
                     $user->addProject($project->id->asString());
                     $project->write();
                     $user->write();
                     $url = '/app/' . $project->appName . '/' . $project->id->asString();
                 }
                 if ($identityCheck->emailIsEmpty) {
                     Communicate::sendSignup($user, $website, $delivery);
                 }
                 if ($identityCheck->emailMatchesAccount) {
                     Auth::login($app, $username, $password);
                     return Auth::result(Auth::LOGIN_SUCCESS, $url, 'location');
                 }
                 return Auth::result(Auth::LOGIN_FAIL_USER_UNAUTHORIZED, '', 'location');
             }
         }
     }
     return false;
 }
 public function reset_password($resetPasswordKey, $newPassword)
 {
     return Auth::resetPassword($this->app, $resetPasswordKey, $newPassword);
 }
示例#3
0
 public function reset_password($resetPasswordKey, $newPassword)
 {
     return Auth::resetPassword($this->_controller, $resetPasswordKey, $newPassword);
 }