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 loadUserByUsername($username) { $identityCheck = UserCommands::checkIdentity($username, '', $this->website); if (!$identityCheck->usernameExists) { throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); } $user = new UserModelWithPassword(); $user->readByUserName($username); if (!$identityCheck->usernameExistsOnThisSite and $user->role != SystemRoles::SYSTEM_ADMIN) { throw new AccessDeniedException(sprintf('Username "%s" not available on "%s". Use "Create an Account".', $username, $this->website->domain)); } $roles = array('ROLE_' . $user->role); if ($user->siteRole and $user->siteRole->offsetExists($this->website->domain) and $user->siteRole[$this->website->domain] !== SiteRoles::NONE) { $roles[] = 'ROLE_SITE_' . $user->siteRole[$this->website->domain]; } return new User($user->username, $user->password, $roles, $user->active, true, true, true); }
public function forgotPassword(Request $request, Application $app) { $username = $request->request->get('_username'); $identityCheck = UserCommands::checkIdentity($username, '', $this->website); if (!$identityCheck->usernameExists) { $app['session']->getFlashBag()->add('errorMessage', 'User not found.'); return $this->view($request, $app, 'forgot_password'); } $user = new UserModel(); $user->readByUserName($username); if (!$identityCheck->usernameExistsOnThisSite and $user->role != SystemRoles::SYSTEM_ADMIN) { $app['session']->getFlashBag()->add('errorMessage', sprintf('Username "%s" not available on "%s". Use "Create an Account".', $username, $this->website->domain)); return $this->view($request, $app, 'forgot_password'); } Communicate::sendForgotPasswordVerification($user, $this->website); $app['session']->getFlashBag()->add('infoMessage', 'Password Reset email sent for username "' . $username . '"'); return $app->redirect('/auth/login'); }
/** * 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; }
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); }