Exemplo 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);
 }
Exemplo n.º 2
0
 public function testDisableAdminRecovery()
 {
     $this->keyManagerMock->expects($this->exactly(2))->method('checkRecoveryPassword')->willReturnOnConsecutiveCalls(true, false);
     $this->assertArrayHasKey('recoveryAdminEnabled', self::$tempStorage);
     $this->assertTrue($this->instance->disableAdminRecovery('password'));
     $this->assertEquals(0, self::$tempStorage['recoveryAdminEnabled']);
     $this->assertFalse($this->instance->disableAdminRecovery('password'));
 }
Exemplo n.º 3
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]], 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!'))]);
     }
 }