diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2014-03-25 01:38:11 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-06-13 15:34:51 +0200 |
commit | 23ed038a27901b947b75413b966d4beab21cd2bc (patch) | |
tree | 03d7522cc0f943160a35f07dc860de741dcd5d0b /core/lostpassword | |
parent | c09f5680c98d66d6e5a0fe793561194ecafed3ea (diff) | |
download | nextcloud-server-23ed038a27901b947b75413b966d4beab21cd2bc.tar.gz nextcloud-server-23ed038a27901b947b75413b966d4beab21cd2bc.zip |
Basics
Diffstat (limited to 'core/lostpassword')
-rw-r--r-- | core/lostpassword/ajaxcontroller.php | 45 | ||||
-rw-r--r-- | core/lostpassword/controller.php | 62 | ||||
-rw-r--r-- | core/lostpassword/encrypteddataexception.php | 14 | ||||
-rw-r--r-- | core/lostpassword/templates/lostpassword.php | 2 |
4 files changed, 86 insertions, 37 deletions
diff --git a/core/lostpassword/ajaxcontroller.php b/core/lostpassword/ajaxcontroller.php new file mode 100644 index 00000000000..3722681308b --- /dev/null +++ b/core/lostpassword/ajaxcontroller.php @@ -0,0 +1,45 @@ +<?php +/** + * @author Victor Dubiniuk + * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\LostPassword; + +class AjaxController { + public static function lost() { + \OCP\JSON::callCheck(); + + try { + Controller::sendEmail(@$_POST['user'], @$_POST['proceed']); + \OCP\JSON::success(); + } catch (EncryptedDataException $e){ + \OCP\JSON::error( + array('encryption' => '1') + ); + } catch (\Exception $e){ + \OCP\JSON::error( + array('msg'=> $e->getMessage()) + ); + } + + exit(); + } + + public static function resetPassword($args) { + \OCP\JSON::callCheck(); + try { + Controller::resetPassword($args); + \OCP\JSON::success(); + } catch (Exception $e){ + \OCP\JSON::error( + array('msg'=> $e->getMessage()) + ); + } + exit(); + } +} diff --git a/core/lostpassword/controller.php b/core/lostpassword/controller.php index c858696885b..0c6ada4edce 100644 --- a/core/lostpassword/controller.php +++ b/core/lostpassword/controller.php @@ -36,47 +36,37 @@ class Controller { return \OC_Preferences::getValue($user, 'owncloud', 'lostpassword') === hash('sha256', $token); } - public static function index($args) { - self::displayLostPasswordPage(false, false); - } - - public static function sendEmail($args) { - + public static function sendEmail($user, $proceed) { + $l = \OC_L10N::get('core'); $isEncrypted = \OC_App::isEnabled('files_encryption'); - if(!$isEncrypted || isset($_POST['continue'])) { - $continue = true; - } else { - $continue = false; + if ($isEncrypted && $proceed !== 'Yes'){ + throw new EncryptedDataException(); } - if (\OC_User::userExists($_POST['user']) && $continue) { - $token = hash('sha256', \OC_Util::generateRandomBytes(30).\OC_Config::getValue('passwordsalt', '')); - \OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', - hash('sha256', $token)); // Hash the token again to prevent timing attacks - $email = \OC_Preferences::getValue($_POST['user'], 'settings', 'email', ''); - if (!empty($email)) { - $link = \OC_Helper::linkToRoute('core_lostpassword_reset', - array('user' => $_POST['user'], 'token' => $token)); - $link = \OC_Helper::makeURLAbsolute($link); + if (!\OC_User::userExists($user)) { + throw new \Exception($l->t('Couldn’t send reset email. Please make sure your username is correct.')); + } + $token = hash('sha256', \OC_Util::generateRandomBytes(30).\OC_Config::getValue('passwordsalt', '')); + \OC_Preferences::setValue($user, 'owncloud', 'lostpassword', + hash('sha256', $token)); // Hash the token again to prevent timing attacks + $email = \OC_Preferences::getValue($user, 'settings', 'email', ''); + if (empty($email)) { + throw new \Exception($l->t('Couldn’t send reset email because there is no email address for this username. Please contact your administrator.')); + } + $link = \OC_Helper::linkToRoute('core_lostpassword_reset', + array('user' => $user, 'token' => $token)); + $link = \OC_Helper::makeURLAbsolute($link); - $tmpl = new \OC_Template('core/lostpassword', 'email'); - $tmpl->assign('link', $link, false); - $msg = $tmpl->fetchPage(); - $l = \OC_L10N::get('core'); - $from = \OCP\Util::getDefaultEmailAddress('lostpassword-noreply'); - try { - $defaults = new \OC_Defaults(); - \OC_Mail::send($email, $_POST['user'], $l->t('%s password reset', array($defaults->getName())), $msg, $from, $defaults->getName()); - } catch (Exception $e) { - \OC_Template::printErrorPage( $l->t('A problem has occurred whilst sending the email, please contact your administrator.') ); - } - self::displayLostPasswordPage(false, true); - } else { - self::displayLostPasswordPage(true, false); - } - } else { - self::displayLostPasswordPage(true, false); + $tmpl = new \OC_Template('core/lostpassword', 'email'); + $tmpl->assign('link', $link, false); + $msg = $tmpl->fetchPage(); + $from = \OCP\Util::getDefaultEmailAddress('lostpassword-noreply'); + try { + $defaults = new \OC_Defaults(); + \OC_Mail::send($email, $user, $l->t('%s password reset', array($defaults->getName())), $msg, $from, $defaults->getName()); + } catch (\Exception $e) { + throw new \Exception( $l->t('Couldn’t send reset email. Please contact your administrator.')); } } diff --git a/core/lostpassword/encrypteddataexception.php b/core/lostpassword/encrypteddataexception.php new file mode 100644 index 00000000000..99d19445b6c --- /dev/null +++ b/core/lostpassword/encrypteddataexception.php @@ -0,0 +1,14 @@ +<?php +/** + * @author Victor Dubiniuk + * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\LostPassword; + +class EncryptedDataException extends \Exception{ +} diff --git a/core/lostpassword/templates/lostpassword.php b/core/lostpassword/templates/lostpassword.php index fdfa32344ec..0c2c72b40ce 100644 --- a/core/lostpassword/templates/lostpassword.php +++ b/core/lostpassword/templates/lostpassword.php @@ -8,7 +8,7 @@ OCP\Util::addStyle('lostpassword', 'lostpassword'); ?> </p></div> <?php else: ?> - <form action="<?php print_unescaped(OC_Helper::linkToRoute('core_lostpassword_send_email')) ?>" method="post"> + <form action="<?php //print_unescaped(OC_Helper::linkToRoute('core_lostpassword_send_email')) ?>" method="post"> <fieldset> <?php if ($_['error']): ?> <div class="error"><p> |