Ejemplo n.º 1
0
 public function change_password($userId, $newPassword)
 {
     return UserCommands::changePassword($userId, $newPassword, $this->userId);
 }
 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');
 }
 /**
  * @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 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);
 }