Esempio n. 1
0
 /**
  * @param string $recoveryPassword
  * @param string $confirmPassword
  * @param string $adminEnableRecovery
  * @return DataResponse
  */
 public function adminRecovery($recoveryPassword, $confirmPassword, $adminEnableRecovery)
 {
     // Check if both passwords are the same
     if (empty($recoveryPassword)) {
         $errorMessage = (string) $this->l->t('Missing recovery key password');
         return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST);
     }
     if (empty($confirmPassword)) {
         $errorMessage = (string) $this->l->t('Please repeat the recovery key password');
         return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST);
     }
     if ($recoveryPassword !== $confirmPassword) {
         $errorMessage = (string) $this->l->t('Repeated recovery key password does not match the provided recovery key password');
         return new DataResponse(['data' => ['message' => $errorMessage]], Http::STATUS_BAD_REQUEST);
     }
     if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') {
         if ($this->recovery->enableAdminRecovery($recoveryPassword)) {
             return new DataResponse(['data' => ['message' => (string) $this->l->t('Recovery key successfully enabled')]]);
         }
         return new DataResponse(['data' => ['message' => (string) $this->l->t('Could not enable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST);
     } elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') {
         if ($this->recovery->disableAdminRecovery($recoveryPassword)) {
             return new DataResponse(['data' => ['message' => (string) $this->l->t('Recovery key successfully disabled')]]);
         }
         return new DataResponse(['data' => ['message' => (string) $this->l->t('Could not disable recovery key. Please check your recovery key password!')]], Http::STATUS_BAD_REQUEST);
     }
     // this response should never be sent but just in case.
     return new DataResponse(['data' => ['message' => (string) $this->l->t('Missing parameters')]], Http::STATUS_BAD_REQUEST);
 }
 /**
  * @param string $recoveryPassword
  * @param string $confirmPassword
  * @param string $adminEnableRecovery
  * @return DataResponse
  */
 public function adminRecovery($recoveryPassword, $confirmPassword, $adminEnableRecovery)
 {
     // Check if both passwords are the same
     if (empty($recoveryPassword)) {
         $errorMessage = (string) $this->l->t('Missing recovery key password');
         return new DataResponse(['data' => ['message' => $errorMessage]], 500);
     }
     if (empty($confirmPassword)) {
         $errorMessage = (string) $this->l->t('Please repeat the recovery key password');
         return new DataResponse(['data' => ['message' => $errorMessage]], 500);
     }
     if ($recoveryPassword !== $confirmPassword) {
         $errorMessage = (string) $this->l->t('Repeated recovery key password does not match the provided recovery key password');
         return new DataResponse(['data' => ['message' => $errorMessage]], 500);
     }
     if (isset($adminEnableRecovery) && $adminEnableRecovery === '1') {
         if ($this->recovery->enableAdminRecovery($recoveryPassword)) {
             return new DataResponse(['status' => 'success', 'data' => array('message' => (string) $this->l->t('Recovery key successfully enabled'))]);
         }
         return new DataResponse(['data' => array('message' => (string) $this->l->t('Could not enable recovery key. Please check your recovery key password!'))]);
     } elseif (isset($adminEnableRecovery) && $adminEnableRecovery === '0') {
         if ($this->recovery->disableAdminRecovery($recoveryPassword)) {
             return new DataResponse(['data' => array('message' => (string) $this->l->t('Recovery key successfully disabled'))]);
         }
         return new DataResponse(['data' => array('message' => (string) $this->l->t('Could not disable recovery key. Please check your recovery key password!'))]);
     }
 }
Esempio n. 3
0
 public function testEnableAdminRecovery()
 {
     $this->keyManagerMock->expects($this->exactly(2))->method('recoveryKeyExists')->willReturnOnConsecutiveCalls(false, true);
     $this->cryptMock->expects($this->once())->method('createKeyPair')->willReturn(true);
     $this->keyManagerMock->expects($this->once())->method('setRecoveryKey')->willReturn(false);
     $this->keyManagerMock->expects($this->exactly(2))->method('checkRecoveryPassword')->willReturnOnConsecutiveCalls(true, false);
     $this->assertTrue($this->instance->enableAdminRecovery('password'));
     $this->assertArrayHasKey('recoveryAdminEnabled', self::$tempStorage);
     $this->assertEquals(1, self::$tempStorage['recoveryAdminEnabled']);
     $this->assertFalse($this->instance->enableAdminRecovery('password'));
 }
Esempio n. 4
0
 public function testEnableAdminRecoveryCouldNotCreateKey()
 {
     $this->keyManagerMock->expects($this->once())->method('recoveryKeyExists')->willReturn(false);
     $this->cryptMock->expects($this->once())->method('createKeyPair')->willReturn(false);
     $this->assertFalse($this->instance->enableAdminRecovery('password'));
 }