more style fixes

This commit is contained in:
Bernhard Posselt 2014-06-06 16:51:58 +02:00 committed by Morris Jobke
parent a6e45a8d0e
commit 2b2b1b487c
1 changed files with 24 additions and 15 deletions

View File

@ -71,6 +71,14 @@ class LostController extends Controller {
); );
} }
private function error($message, array $additional=array()) {
return array_combine(array('status' => 'error', 'msg' => $message), $additional);
}
private function success() {
return array('status'=>'success');
}
/** /**
* @PublicPage * @PublicPage
* *
@ -82,39 +90,36 @@ class LostController extends Controller {
try { try {
$this->sendEmail($user, $proceed); $this->sendEmail($user, $proceed);
} catch (EncryptedDataException $e){ } catch (EncryptedDataException $e){
array('status' => 'error', 'encryption' => '1'); return $this->error('', array('encryption' => '1'));
} catch (\Exception $e){ } catch (\Exception $e){
return array('status' => 'error', 'msg' => $e->getMessage()); return $this->error($e->getMessage());
} }
return array('status'=>'success'); return $this->success();
} }
/** /**
* @PublicPage * @PublicPage
*/ */
public function setPassword($token, $uid, $password) { public function setPassword($token, $userId, $password) {
try { try {
if (!$this->checkToken($uid, $token)) { $user = $this->userManager->get($userId);
throw new \Exception();
}
$user = $this->userManager->get($uid);
if (!$user->setPassword($uid, $password)) {
if (!$this->checkToken($userId, $token) ||
!$user->setPassword($userId, $password)) {
throw new \Exception(); throw new \Exception();
} }
// FIXME: should be added to the all config at some point // FIXME: should be added to the all config at some point
\OC_Preferences::deleteKey($uid, 'owncloud', 'lostpassword'); \OC_Preferences::deleteKey($userId, 'owncloud', 'lostpassword');
$this->userSession->unsetMagicInCookie(); $this->userSession->unsetMagicInCookie();
} catch (\Exception $e){ } catch (\Exception $e){
return array('status' => 'error','msg' => $e->getMessage()); return $this->error($e->getMessage());
} }
return array('status'=>'success'); return $this->success();
} }
@ -153,6 +158,7 @@ class LostController extends Controller {
$msg = $tmpl->fetchPage(); $msg = $tmpl->fetchPage();
try { try {
// FIXME: should be added to the container and injected in here
\OC_Mail::send($email, $user, $this->l10n->t( \OC_Mail::send($email, $user, $this->l10n->t(
'%s password reset', '%s password reset',
array( array(
@ -162,8 +168,9 @@ class LostController extends Controller {
$this->defaults->getName() $this->defaults->getName()
)); ));
} catch (\Exception $e) { } catch (\Exception $e) {
throw new \Exception($this->l10n->t('Couldnt send reset email. ' . throw new \Exception($this->l10n->t(
'Please contact your administrator.')); 'Couldnt send reset email. Please contact your administrator.'
));
} }
} }
@ -174,6 +181,7 @@ class LostController extends Controller {
'uid' => $user 'uid' => $user
); );
$link = $this->urlGenerator->linkToRoute($route, $parameters); $link = $this->urlGenerator->linkToRoute($route, $parameters);
return $this->urlGenerator->getAbsoluteUrl($link); return $this->urlGenerator->getAbsoluteUrl($link);
} }
@ -184,4 +192,5 @@ class LostController extends Controller {
) === hash('sha256', $token); ) === hash('sha256', $token);
} }
} }