summaryrefslogtreecommitdiffstats
path: root/apps/encryption/controller
diff options
context:
space:
mode:
authorClark Tomlinson <fallen013@gmail.com>2015-04-20 10:23:09 -0400
committerClark Tomlinson <fallen013@gmail.com>2015-04-22 10:46:55 -0400
commitc81bc152d7bd649b24b00482e0d57b6ce24643c4 (patch)
treec2b0094f174d31e4aeb6abac9df77a820f145ab2 /apps/encryption/controller
parent750f0bc4896dcc35695e535ae826da353d265daf (diff)
downloadnextcloud-server-c81bc152d7bd649b24b00482e0d57b6ce24643c4.tar.gz
nextcloud-server-c81bc152d7bd649b24b00482e0d57b6ce24643c4.zip
fixing return values and adding tests
Diffstat (limited to 'apps/encryption/controller')
-rw-r--r--apps/encryption/controller/recoverycontroller.php70
1 files changed, 38 insertions, 32 deletions
diff --git a/apps/encryption/controller/recoverycontroller.php b/apps/encryption/controller/recoverycontroller.php
index 9c07bda62e4..550190e952a 100644
--- a/apps/encryption/controller/recoverycontroller.php
+++ b/apps/encryption/controller/recoverycontroller.php
@@ -72,31 +72,36 @@ class RecoveryController extends Controller {
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);
+ $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);
+ $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);
+ $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(['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!'))]);
+ 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('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!'))]);
+ return new DataResponse(['data' => array('message' => (string)$this->l->t('Could not disable recovery key. Please check your recovery key password!'))]);
}
+ // this response should never be sent but just in case.
+ return new DataResponse(['data' => ['message' => (string)$this->l->t('Missing parameters')]]);
}
/**
@@ -108,42 +113,43 @@ class RecoveryController extends Controller {
public function changeRecoveryPassword($newPassword, $oldPassword, $confirmPassword) {
//check if both passwords are the same
if (empty($oldPassword)) {
- $errorMessage = (string) $this->l->t('Please provide the old recovery password');
+ $errorMessage = (string)$this->l->t('Please provide the old recovery password');
return new DataResponse(array('data' => array('message' => $errorMessage)));
}
if (empty($newPassword)) {
- $errorMessage = (string) $this->l->t('Please provide a new recovery password');
+ $errorMessage = (string)$this->l->t('Please provide a new recovery password');
return new DataResponse (array('data' => array('message' => $errorMessage)));
}
if (empty($confirmPassword)) {
- $errorMessage = (string) $this->l->t('Please repeat the new recovery password');
+ $errorMessage = (string)$this->l->t('Please repeat the new recovery password');
return new DataResponse(array('data' => array('message' => $errorMessage)));
}
if ($newPassword !== $confirmPassword) {
- $errorMessage = (string) $this->l->t('Repeated recovery key password does not match the provided recovery key password');
+ $errorMessage = (string)$this->l->t('Repeated recovery key password does not match the provided recovery key password');
return new DataResponse(array('data' => array('message' => $errorMessage)));
}
- $result = $this->recovery->changeRecoveryKeyPassword($newPassword, $oldPassword);
+ $result = $this->recovery->changeRecoveryKeyPassword($newPassword,
+ $oldPassword);
if ($result) {
return new DataResponse(
array(
- 'status' => 'success' ,
+ 'status' => 'success',
'data' => array(
- 'message' => (string) $this->l->t('Password successfully changed.'))
- )
- );
+ 'message' => (string)$this->l->t('Password successfully changed.'))
+ )
+ );
} else {
return new DataResponse(
array(
'data' => array
- ('message' => (string) $this->l->t('Could not change the password. Maybe the old password was not correct.'))
- )
- );
+ ('message' => (string)$this->l->t('Could not change the password. Maybe the old password was not correct.'))
+ )
+ );
}
}
@@ -161,19 +167,19 @@ class RecoveryController extends Controller {
if ($result) {
return new DataResponse(
array(
- 'status' => 'success',
- 'data' => array(
- 'message' => (string) $this->l->t('Recovery Key enabled'))
- )
- );
- } else {
- return new DataResponse(
- array(
- 'data' => array
- ('message' => (string) $this->l->t('Could not enable the recovery key, please try again or contact your administrator'))
+ 'status' => 'success',
+ 'data' => array(
+ 'message' => (string)$this->l->t('Recovery Key enabled'))
)
);
}
+
+ return new DataResponse(
+ array(
+ 'data' => array
+ ('message' => (string)$this->l->t('Could not enable the recovery key, please try again or contact your administrator'))
+ )
+ );
}
}