public function testCheckIdentity_userDoesNotExistNoEmail_defaults()
 {
     $identityCheck = UserCommands::checkIdentity('', '', null);
     $this->assertFalse($identityCheck->usernameExists);
     $this->assertFalse($identityCheck->usernameExistsOnThisSite);
     $this->assertTrue($identityCheck->usernameMatchesAccount);
     $this->assertFalse($identityCheck->allowSignupFromOtherSites);
     $this->assertFalse($identityCheck->emailExists);
     $this->assertTrue($identityCheck->emailIsEmpty);
     $this->assertFalse($identityCheck->emailMatchesAccount);
 }
 public function forgotPassword(Request $request, Application $app)
 {
     $usernameOrEmail = $request->request->get('_username');
     $user = new UserModel();
     if (!$user->readByUsernameOrEmail($usernameOrEmail)) {
         $app['session']->getFlashBag()->add('errorMessage', 'User not found.');
         return $this->view($request, $app, 'forgot_password');
     }
     $identityCheck = UserCommands::checkIdentity($user->username, $user->email, $this->website);
     if (!$identityCheck->usernameExistsOnThisSite) {
         $user->siteRole[$this->website->domain] = $this->website->userDefaultSiteRole;
     }
     Communicate::sendForgotPasswordVerification($user, $this->website);
     $app['session']->getFlashBag()->add('infoMessage', 'Password Reset email sent for username "' . $usernameOrEmail . '"');
     return $app->redirect('/auth/login');
 }
Ejemplo n.º 3
0
 public function identity_check($username, $email)
 {
     // intentionally we have no security here: people can see what users exist by trial and error
     $identityCheck = UserCommands::checkIdentity($username, $email, $this->website);
     return JsonEncoder::encode($identityCheck);
 }
 /**
  * Sends an email to invite emailee to join the project
  * @param string $projectId
  * @param string $inviterUserId
  * @param Website $website
  * @param string $toEmail
  * @param DeliveryInterface $delivery
  * @throws \Exception
  * @return string $userId
  */
 public static function sendInvite($projectId, $inviterUserId, $website, $toEmail, DeliveryInterface $delivery = null)
 {
     $newUser = new UserModel();
     $inviterUser = new UserModel($inviterUserId);
     $project = new ProjectModel($projectId);
     $newUser->emailPending = $toEmail;
     // Check if email already exists in an account
     $identityCheck = UserCommands::checkIdentity('', $toEmail, $website);
     if ($identityCheck->emailExists) {
         $newUser->readByProperty('email', $toEmail);
     }
     // Make sure the user exists on the site
     if (!$newUser->hasRoleOnSite($website)) {
         $newUser->siteRole[$website->domain] = $website->userDefaultSiteRole;
     }
     // Determine if user is already a member of the project
     if ($project->userIsMember($newUser->id->asString())) {
         return $newUser->id;
     }
     // Add the user to the project
     $newUser->addProject($project->id->asString());
     $userId = $newUser->write();
     $project->addUser($userId, ProjectRoles::CONTRIBUTOR);
     $project->write();
     if (!$identityCheck->emailExists) {
         // Email communication with new user
         Communicate::sendInvite($inviterUser, $newUser, $project, $website, $delivery);
     } else {
         // Tell existing user they're now part of the project
         Communicate::sendAddedToProject($inviterUser, $newUser, $project, $website, $delivery);
     }
     return $userId;
 }