public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     $username = $token->getUser()->getUsername();
     $user = new UserModel();
     $website = Website::get();
     // automatically logout if 1) the user doesn't exist or 2) the user is not a system admin and has no site rights on the current site
     if (!$user->readByUserName($username) or $user->role != SystemRoles::SYSTEM_ADMIN and !($user->siteRole->offsetExists($website->domain) and $user->siteRole[$website->domain] != SiteRoles::NONE)) {
         return $this->httpUtils->createRedirectResponse($request, '/app/logout');
     }
     $projectId = $user->getCurrentProjectId($website->domain);
     // redirect to page before the login screen was presented, or to the default project for this user
     $referer = $this->determineTargetUrl($request);
     $url = '/app/projects';
     if ($referer and strpos($referer, '/app/') !== false) {
         $url = $referer;
     } elseif ($projectId && ProjectModel::projectExistsOnWebsite($projectId, $website)) {
         $project = ProjectModel::getById($projectId);
         if ($project->userIsMember($user->id->asString())) {
             $url = '/app/' . $project->appName . '/' . $projectId;
         }
     }
     return $this->httpUtils->createRedirectResponse($request, $url);
 }
 public function testReadByUserName_userNotFound_EmptyModel()
 {
     $environ = new MongoTestEnvironment();
     $environ->clean();
     $environ->createUser('jsmith', 'joe smith', '*****@*****.**');
     $user = new UserModel();
     $result = $user->readByUserName('adam');
     $this->assertFalse($result);
     $this->assertEquals('', $user->email);
 }
 /**
  * Utility to check if a username already exists and if an email address matches the account
  * @param string $username
  * @param string $email
  * @param Website $website
  * @return IdentityCheck
  */
 public static function checkIdentity($username, $email = '', $website = null)
 {
     $identityCheck = new IdentityCheck();
     $user = new UserModel();
     $emailUser = new UserModel();
     $identityCheck->usernameExists = $user->readByUserName($username);
     // This utility assumes username matches the account
     $identityCheck->usernameMatchesAccount = true;
     if ($website) {
         $identityCheck->allowSignupFromOtherSites = $website->allowSignupFromOtherSites;
         if ($identityCheck->usernameExists) {
             $identityCheck->usernameExistsOnThisSite = $user->hasRoleOnSite($website);
         }
     }
     if ($email) {
         $identityCheck->emailExists = $emailUser->readByProperty('email', $email);
     }
     $identityCheck->emailIsEmpty = empty($user->email);
     if (!$identityCheck->emailIsEmpty && !empty($email)) {
         $identityCheck->emailMatchesAccount = $user->email === $email;
     }
     return $identityCheck;
 }