public function project_acceptJoinRequest($userId, $role) { UserCommands::acceptJoinRequest($this->projectId, $userId, $this->website, $role); ProjectCommands::removeJoinRequest($this->projectId, $userId); }
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']; MongoStore::dropDB($projectModel->databaseName()); $projectModel = new ProjectModel(); $projectModel->projectName = $constants['emptyProjectName']; $projectModel->projectCode = $constants['emptyProjectCode']; 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); $observerUserId = UserCommands::createUser(array('id' => '', 'name' => $constants['observerName'], 'email' => $constants['observerEmail'], 'username' => $constants['observerUsername'], 'password' => $constants['observerPassword'], '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 {
/** * @param Application $app * @param string $resetPasswordKey * @param string $newPassword * @throws UserUnauthorizedException * @return string $userId */ public static function resetPassword(Application $app, $resetPasswordKey = '', $newPassword = '') { $user = new UserModelBase(); if (!$user->readByProperty('resetPasswordKey', $resetPasswordKey)) { $app['session']->getFlashBag()->add('errorMessage', 'Your password reset cannot be completed. Please try again.'); return false; } if (!$user->hasForgottenPassword()) { $app['session']->getFlashBag()->add('errorMessage', 'Your password reset cannot be completed. It may have expired. Please try again.'); return false; } $userId = $user->id->asString(); UserCommands::changePassword($userId, $newPassword, $userId); $app['session']->getFlashBag()->add('infoMessage', 'Your password has been reset. Please login.'); return $user->write(); }
public function testChangePassword_SystemAdminChangeOtherUser_Succeeds() { self::$environ->clean(); $adminModel = new UserModel(); $adminModel->username = '******'; $adminModel->role = SystemRoles::SYSTEM_ADMIN; $adminId = $adminModel->write(); $userModel = new UserModel(); $userModel->username = '******'; $userModel->role = SystemRoles::NONE; $userId = $userModel->write(); $this->assertNotEquals($userId, $adminId); UserCommands::changePassword($userId, 'somepass', $adminId); $passwordModel = new PasswordModel($userId); $result = $passwordModel->verifyPassword('somepass'); $this->assertTrue($result, 'Could not verify changed password'); }
/** * 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 testUserCRUD_CRUDOK() { // initial list $result = self::$environ->fixJson(UserCommands::listUsers()); $count = $result['count']; // Create $userId = self::$environ->createUser('someuser', 'SomeUser', '*****@*****.**'); $someUser = new UserModel($userId); $this->assertNotNull($someUser); $this->assertEquals(24, strlen($someUser->id->asString())); // create project ProjectCommands::createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE, 'sfchecks', $someUser->id->asString(), self::$environ->website); // list $result = self::$environ->fixJson(UserCommands::listUsers()); $this->assertEquals($count + 1, $result['count']); // Read $result = self::$environ->fixJson(UserCommands::readUser($someUser->id->asString())); $this->assertNotNull($result['id']); $this->assertEquals('someuser', $result['username']); $this->assertEquals('*****@*****.**', $result['email']); // Update $result['username'] = '******'; $result['email'] = '*****@*****.**'; $id = UserCommands::updateUser($result, self::$environ->website); $this->assertNotNull($id); $this->assertEquals($result['id'], $id); // typeahead $result = self::$environ->fixJson(UserCommands::userTypeaheadList('ome', '', self::$environ->website)); $this->assertTrue($result['count'] > 0); // change password UserCommands::changePassword($id, 'newpassword', $id); // Delete $result = UserCommands::deleteUsers(array($id)); $this->assertTrue($result > 0); }
public function Run($argv) { $runForReal = false; if (count($argv) > 1 && $argv[1] == 'run') { $runForReal = true; } else { print "\nUsage: FactoryReset.php <run> <DIRECTORY>\n"; print "Run factory reset and restore mongodb and assets from DIRECTORY\n"; print "\nTest Mode - no data will be changed\n--------------------------------\n\n"; } $archivePath = count($argv) > 2 ? $argv[2] : ""; $projectList = new ProjectListModel(); $projectList->read(); // remove all existing projects print "\n{$projectList->count} projects will be deleted\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) { MongoStore::dropAllCollections(SF_DATABASE); } print "\nDropping other dbs on the server (like test dbs)\n"; $cmd = "mongo --quiet {$this->hostOption} --eval 'db.getMongo().getDBNames().forEach(function(i){ " . "if (i.indexOf(\"sf_\") == 0 || i.indexOf(\"scriptureforge\") == 0) { " . "print(\"Dropping \" + i); db.getSiblingDB(i).dropDatabase()}})'"; $this->Execute($runForReal, $cmd); if (is_dir($archivePath)) { print "\nExtracting archives...\n"; foreach (glob("{$archivePath}/*.tgz") as $filename) { print "Extracting {$filename}\n"; $cmd = "tar -xzf {$filename} -C {$archivePath}"; $this->Execute($runForReal, $cmd); } print "\nEnsure www-data has permissions...\n"; $cmd = "sudo chgrp -R www-data {$archivePath}/var/www"; $this->Execute($runForReal, $cmd); $cmd = "sudo chown -R www-data:fieldworks {$archivePath}/var/lib"; $this->Execute($runForReal, $cmd); print "\nRestoring mongodb...\n"; $mongodbBackup = $archivePath . "/mongo_backup"; $cmd = "mongorestore {$this->hostOption} {$mongodbBackup}"; $this->Execute($runForReal, $cmd); print "\nUpdating DB site names...\n"; $this->UpdateDBSiteName($runForReal); print "\nRestoring assets...\n"; $cmd = "rsync -rzlt --chmod=Dug=rwx,Fug=rw,o-rwx --group " . "--delete-during --stats --rsync-path='sudo rsync' " . "--exclude=sfchecks " . "{$archivePath}/var/www/languageforge.org/htdocs/assets/ " . "{$this->lfAssetsPath}/htdocs/assets/"; $this->Execute($runForReal, $cmd); $cmd = "rsync -rzlt --chmod=Dug=rwx,Fug=rw,o-rwx --group " . "--delete-during --stats --rsync-path='sudo rsync' " . "--exclude=lexicon --exclude=semdomtrans " . "{$archivePath}/var/www/scriptureforge.org/htdocs/assets/ " . "{$this->sfAssetsPath}/htdocs/assets/"; $this->Execute($runForReal, $cmd); $cmd = "sudo rm -R {$this->lfmergeSendReceivePath}/state/*"; $this->Execute($runForReal, $cmd); $cmd = "sudo rm -R {$this->lfmergeSendReceivePath}/webwork/*"; $this->Execute($runForReal, $cmd); $cmd = "rsync -rzlt --chmod=Dug=rwx,Fug=rw,o-rwx --group " . "--delete-during --stats --rsync-path='sudo rsync' " . "{$archivePath}{$this->lfmergeSendReceivePath} {$this->lfmergeSendReceivePath}"; $this->Execute($runForReal, $cmd); print "\nCleanup extracted files...\n"; $cmd = "sudo rm -R {$archivePath}/var"; $this->Execute($runForReal, $cmd); $cmd = "sudo rm -R {$archivePath}/mongo_backup"; $this->Execute($runForReal, $cmd); } else { print "\nCreating local user: admin password: password\n"; if ($runForReal) { $scriptureforgeWebsite = Website::get('scriptureforge.org'); $languageforgeWebsite = Website::get('languageforge.org'); $adminUser = UserCommands::createUser(array('id' => '', 'name' => 'Admin', 'email' => '*****@*****.**', 'username' => 'admin', 'password' => 'password', 'active' => true, 'role' => SystemRoles::SYSTEM_ADMIN), $languageforgeWebsite); } } }
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; }