/** * @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.'); } }
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 change_password($userId, $newPassword) { return UserCommands::changePassword($userId, $newPassword, $this->_userId); }
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'); }