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);
 }
Пример #2
0
$projectList->read();
print "{$projectList->count} projects will be deleted\n\n";
foreach ($projectList->entries as $p) {
    $project = new ProjectModel($p['id']);
    print "Deleting Project " . $project->projectName . "\n";
    if ($runForReal) {
        try {
            $project->remove();
        } catch (\Exception $e) {
            // don't do anything
        }
    }
}
// start with a fresh database
print "\nDropping main database...\n";
if ($runForReal) {
    $db = \Api\Model\Mapper\MongoStore::connect(SF_DATABASE);
    foreach ($db->listCollections() as $collection) {
        $collection->drop();
    }
}
print "\nDropping other dbs on the server (like test dbs)\n";
if ($runForReal) {
    $cmd = "mongo --quiet --eval 'db.getMongo().getDBNames().forEach(function(i){  if (i.indexOf(\"sf_\") == 0 || i.indexOf(\"scriptureforge\") == 0) { print(\"Dropping \" + i); db.getSiblingDB(i).dropDatabase()}})'";
    system($cmd);
}
print "\nCreating user: admin password: password\n";
if ($runForReal) {
    $adminUser = UserCommands::createUser(array('id' => '', 'name' => 'Admin', 'email' => '*****@*****.**', 'username' => 'admin', 'password' => 'password', 'active' => true, 'role' => SystemRoles::SYSTEM_ADMIN), $languageforgeWebsite);
}
print "\n\n";
Пример #3
0
 public function listRequests()
 {
     $allUserList = UserCommands::listUsers();
     $userList = [];
     for ($i = 0, $l = count($allUserList->entries); $i < $l; $i++) {
         $userId = $allUserList->entries[$i]['id'];
         if (array_key_exists($userId, $this->userJoinRequests)) {
             $userList[$i] = array("user" => $allUserList->entries[$i], "role" => $this->userJoinRequests[$userId]);
         }
     }
     return $userList;
 }
Пример #4
0
 /**
  * @param Application $app
  * @param string $resetPasswordKey
  * @param string $newPassword
  * @throws \Api\Library\Shared\Palaso\Exception\UserUnauthorizedException
  */
 public static function resetPassword(Application $app, $resetPasswordKey = '', $newPassword = '')
 {
     $user = new UserModelBase();
     if ($user->readByProperty('resetPasswordKey', $resetPasswordKey)) {
         $userId = $user->id->asString();
         if ($user->hasForgottenPassword()) {
             UserCommands::changePassword($userId, $newPassword, $userId);
             $user->write();
             $app['session']->getFlashBag()->add('infoMessage', 'Your password has been reset. Please login.');
         } else {
             $app['session']->getFlashBag()->add('errorMessage', 'Your password reset cannot be completed. It may have expired. Please try again.');
         }
     } else {
         $app['session']->getFlashBag()->add('errorMessage', 'Your password reset cannot be completed. Please try again.');
     }
 }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 public function project_acceptJoinRequest($userId, $role)
 {
     UserCommands::acceptJoinRequest($this->_projectId, $userId, $this->_website, $role);
     ProjectCommands::removeJoinRequest($this->_projectId, $userId);
 }
$projectModel->projectCode = $constants['thirdProjectCode'];
$db = \Api\Model\Mapper\MongoStore::dropDB($projectModel->databaseName());
// drop the 'new' and 'empty' database because it is used in a 'create new project' test
$projectModel = new ProjectModel();
$projectModel->projectName = $constants['newProjectName'];
$projectModel->projectCode = $constants['newProjectCode'];
$db = \Api\Model\Mapper\MongoStore::dropDB($projectModel->databaseName());
$projectModel = new ProjectModel();
$projectModel->projectName = $constants['emptyProjectName'];
$projectModel->projectCode = $constants['emptyProjectCode'];
$db = \Api\Model\Mapper\MongoStore::dropDB($projectModel->databaseName());
$adminUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['adminName'], 'email' => $constants['adminEmail'], 'username' => $constants['adminUsername'], 'password' => $constants['adminPassword'], 'active' => true, 'role' => SystemRoles::SYSTEM_ADMIN), $website);
$managerUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['managerName'], 'email' => $constants['managerEmail'], 'username' => $constants['managerUsername'], 'password' => $constants['managerPassword'], 'active' => true, 'role' => SystemRoles::USER), $website);
$memberUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['memberName'], 'email' => $constants['memberEmail'], 'username' => $constants['memberUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website);
$expiredUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['expiredName'], 'email' => $constants['expiredEmail'], 'username' => $constants['expiredUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website);
$resetUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['resetName'], 'email' => $constants['resetEmail'], 'username' => $constants['resetUsername'], 'password' => $constants['memberPassword'], 'active' => true, 'role' => SystemRoles::USER), $website);
// set forgot password with expired date
$today = new DateTime();
$expiredUser = new UserModel($expiredUserId);
$expiredUser->resetPasswordKey = $constants['expiredPasswordKey'];
$expiredUser->resetPasswordExpirationDate = $today;
$expiredUser->write();
// set forgot password with valid date
$resetUser = new UserModel($resetUserId);
$resetUser->resetPasswordKey = $constants['resetPasswordKey'];
$resetUser->resetPasswordExpirationDate = $today->add(new DateInterval('P5D'));
$resetUser->write();
$projectType = null;
if ($site == 'scriptureforge') {
    $projectType = SfProjectModel::SFCHECKS_APP;
} else {
Пример #8
0
 public function testUserCRUD_CRUDOK()
 {
     $e = new ApiCrudTestEnvironment();
     // initial list
     $result = $e->json(UserCommands::listUsers());
     $count = $result['count'];
     // Create
     $userId = $e->e->createUser('someuser', 'SomeUser', '*****@*****.**');
     $someUser = new UserModel($userId);
     $this->assertNotNull($someUser);
     $this->assertEqual(24, strlen($someUser->id->asString()));
     // create project
     $projectId = ProjectCommands::createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE, 'sfchecks', $someUser->id->asString(), $e->e->website);
     // list
     $result = $e->json(UserCommands::listUsers());
     $this->assertEqual($count + 1, $result['count']);
     // Read
     $result = $e->json(UserCommands::readUser($someUser->id->asString()));
     $this->assertNotNull($result['id']);
     $this->assertEqual('someuser', $result['username']);
     $this->assertEqual('*****@*****.**', $result['email']);
     // Update
     $result['username'] = '******';
     $result['email'] = '*****@*****.**';
     $id = UserCommands::updateUser($result);
     $this->assertNotNull($id);
     $this->assertEqual($result['id'], $id);
     // typeahead
     $result = $e->json(UserCommands::userTypeaheadList('ome', '', $e->e->website));
     $this->assertTrue($result['count'] > 0);
     // change password
     UserCommands::changePassword($id, 'newpassword', $id);
     // Delete
     $result = UserCommands::deleteUsers(array($id));
     $this->assertTrue($result);
 }
 public function testChangePassword_SystemAdminChangeOtherUser_Succeeds()
 {
     $this->environ->clean();
     $adminModel = new Api\Model\UserModel();
     $adminModel->username = '******';
     $adminModel->role = SystemRoles::SYSTEM_ADMIN;
     $adminId = $adminModel->write();
     $userModel = new Api\Model\UserModel();
     $userModel->username = '******';
     $userModel->role = SystemRoles::NONE;
     $userId = $userModel->write();
     $this->assertNotEqual($adminId, $userId);
     UserCommands::changePassword($userId, 'somepass', $adminId);
     $passwordModel = new PasswordModel($userId);
     $result = $passwordModel->verifyPassword('somepass');
     $this->assertTrue($result, 'Could not verify changed password');
 }