Change routes. Update templates
This commit is contained in:
parent
218d0add36
commit
4b359ad20c
|
@ -30,7 +30,7 @@ OC.Lostpassword = {
|
||||||
$('#submit').trigger('click');
|
$('#submit').trigger('click');
|
||||||
} else {
|
} else {
|
||||||
$.post(
|
$.post(
|
||||||
OC.filePath('core', 'ajax', 'password/lost'),
|
OC.generateUrl('/lostpassword/email'),
|
||||||
{
|
{
|
||||||
user : $('#user').val(),
|
user : $('#user').val(),
|
||||||
proceed: $('#encrypted-continue').attr('checked') ? 'Yes' : 'No'
|
proceed: $('#encrypted-continue').attr('checked') ? 'Yes' : 'No'
|
||||||
|
|
|
@ -25,9 +25,9 @@ class Application extends App {
|
||||||
$container->registerService('LostController', function($c) {
|
$container->registerService('LostController', function($c) {
|
||||||
return new LostController(
|
return new LostController(
|
||||||
$c->query('AppName'),
|
$c->query('AppName'),
|
||||||
$c->query('ServerContainer')->getRequest(),
|
$c->query('Request'),
|
||||||
$c->query('ServerContainer')->getURLGenerator(),
|
$c->query('ServerContainer')->getURLGenerator(),
|
||||||
$c->query('ServerContainer')->getUserManager(),
|
'\OC_User',
|
||||||
new \OC_Defaults(),
|
new \OC_Defaults(),
|
||||||
$c->query('ServerContainer')->getL10N('core'),
|
$c->query('ServerContainer')->getL10N('core'),
|
||||||
\OCP\Util::getDefaultEmailAddress('lostpassword-noreply'),
|
\OCP\Util::getDefaultEmailAddress('lostpassword-noreply'),
|
||||||
|
|
|
@ -15,17 +15,17 @@ use \OCP\AppFramework\Http\TemplateResponse;
|
||||||
class LostController extends Controller {
|
class LostController extends Controller {
|
||||||
|
|
||||||
protected $urlGenerator;
|
protected $urlGenerator;
|
||||||
protected $userManager;
|
protected $userClass;
|
||||||
protected $defaults;
|
protected $defaults;
|
||||||
protected $l10n;
|
protected $l10n;
|
||||||
protected $from;
|
protected $from;
|
||||||
protected $isDataEncrypted;
|
protected $isDataEncrypted;
|
||||||
|
|
||||||
public function __construct($appName, IRequest $request, IURLGenerator $urlGenerator, $userManager,
|
public function __construct($appName, IRequest $request, IURLGenerator $urlGenerator, $userClass,
|
||||||
$defaults, $l10n, $from, $isDataEncrypted) {
|
$defaults, $l10n, $from, $isDataEncrypted) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->userManager = $userManager;
|
$this->userClass = $userClass;
|
||||||
$this->defaults = $defaults;
|
$this->defaults = $defaults;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->from = $from;
|
$this->from = $from;
|
||||||
|
@ -39,14 +39,15 @@ class LostController extends Controller {
|
||||||
* @param string $token
|
* @param string $token
|
||||||
* @param string $uid
|
* @param string $uid
|
||||||
*/
|
*/
|
||||||
public function reset($token, $uid) {
|
public function resetform($token, $uid) {
|
||||||
// Someone wants to reset their password:
|
// Someone wants to reset their password:
|
||||||
if($this->checkToken($uid, $token)) {
|
if($this->checkToken($uid, $token)) {
|
||||||
return new TemplateResponse(
|
return new TemplateResponse(
|
||||||
'core/lostpassword',
|
'core/lostpassword',
|
||||||
'resetpassword',
|
'resetpassword',
|
||||||
array(
|
array(
|
||||||
'link' => $link
|
'link' => $this->getLink('core.lost.setPassword', $uid, $token),
|
||||||
|
'isEncrypted' => $this->isDataEncrypted,
|
||||||
),
|
),
|
||||||
'guest'
|
'guest'
|
||||||
);
|
);
|
||||||
|
@ -57,7 +58,7 @@ class LostController extends Controller {
|
||||||
'lostpassword',
|
'lostpassword',
|
||||||
array(
|
array(
|
||||||
'isEncrypted' => $this->isDataEncrypted,
|
'isEncrypted' => $this->isDataEncrypted,
|
||||||
'link' => $this->getResetPasswordLink($uid, $token)
|
'link' => $this->getLink('core.lost.setPassword', $uid, $token)
|
||||||
),
|
),
|
||||||
'guest'
|
'guest'
|
||||||
);
|
);
|
||||||
|
@ -69,7 +70,7 @@ class LostController extends Controller {
|
||||||
*
|
*
|
||||||
* @param bool $proceed
|
* @param bool $proceed
|
||||||
*/
|
*/
|
||||||
public function lost($user, $proceed){
|
public function email($user, $proceed){
|
||||||
$response = new JSONResponse(array('status'=>'success'));
|
$response = new JSONResponse(array('status'=>'success'));
|
||||||
try {
|
try {
|
||||||
$this->sendEmail($user, $proceed);
|
$this->sendEmail($user, $proceed);
|
||||||
|
@ -91,17 +92,18 @@ class LostController extends Controller {
|
||||||
/**
|
/**
|
||||||
* @PublicPage
|
* @PublicPage
|
||||||
*/
|
*/
|
||||||
public function resetPassword($user, $password, $token) {
|
public function setPassword($token, $uid, $password) {
|
||||||
$response = new JSONResponse(array('status'=>'success'));
|
$response = new JSONResponse(array('status'=>'success'));
|
||||||
try {
|
try {
|
||||||
if (!$this->checkToken($user, $token)) {
|
if (!$this->checkToken($uid, $token)) {
|
||||||
throw new \RuntimeException('');
|
throw new \RuntimeException('');
|
||||||
}
|
}
|
||||||
if (!$this->userManager->setPassword($user, $newPassword)) {
|
$userClass = $this->userClass;
|
||||||
|
if (!$userClass::setPassword($uid, $password)) {
|
||||||
throw new \RuntimeException('');
|
throw new \RuntimeException('');
|
||||||
}
|
}
|
||||||
\OC_Preferences::deleteKey($user, 'owncloud', 'lostpassword');
|
\OC_Preferences::deleteKey($uid, 'owncloud', 'lostpassword');
|
||||||
$this->userManager->unsetMagicInCookie();
|
$userClass::unsetMagicInCookie();
|
||||||
} catch (Exception $e){
|
} catch (Exception $e){
|
||||||
$response->setData(array(
|
$response->setData(array(
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
|
@ -116,7 +118,7 @@ class LostController extends Controller {
|
||||||
throw new EncryptedDataException();
|
throw new EncryptedDataException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->userManager->userExists($user)) {
|
if (!$this->userClass->userExists($user)) {
|
||||||
throw new \Exception($this->l10n->t('Couldn’t send reset email. Please make sure your username is correct.'));
|
throw new \Exception($this->l10n->t('Couldn’t send reset email. Please make sure your username is correct.'));
|
||||||
}
|
}
|
||||||
$token = hash('sha256', \OC_Util::generateRandomBytes(30));
|
$token = hash('sha256', \OC_Util::generateRandomBytes(30));
|
||||||
|
@ -126,7 +128,7 @@ class LostController extends Controller {
|
||||||
throw new \Exception($this->l10n->t('Couldn’t send reset email because there is no email address for this username. Please contact your administrator.'));
|
throw new \Exception($this->l10n->t('Couldn’t send reset email because there is no email address for this username. Please contact your administrator.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = $this->getResetPasswordLink($user, $token);
|
$link = $this->getLink('core.lost.resetform', $user, $token);
|
||||||
echo $link;
|
echo $link;
|
||||||
$tmpl = new \OC_Template('core/lostpassword', 'email');
|
$tmpl = new \OC_Template('core/lostpassword', 'email');
|
||||||
$tmpl->assign('link', $link, false);
|
$tmpl->assign('link', $link, false);
|
||||||
|
@ -138,12 +140,12 @@ class LostController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getResetPasswordLink($user, $token){
|
protected function getLink($route, $user, $token){
|
||||||
$parameters = array(
|
$parameters = array(
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
'uid' => $user
|
'uid' => $user
|
||||||
);
|
);
|
||||||
$link = $this->urlGenerator->linkToRoute('core.lost.reset', $parameters);
|
$link = $this->urlGenerator->linkToRoute($route, $parameters);
|
||||||
return $this->urlGenerator->getAbsoluteUrl($link);
|
return $this->urlGenerator->getAbsoluteUrl($link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<form action="<?php print_unescaped($_['link']) ?>" method="post">
|
<form action="<?php print_unescaped($_['link']) ?>" id="reset-password" method="post">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<p>
|
<p>
|
||||||
<label for="password" class="infield"><?php p($l->t('New password')); ?></label>
|
<label for="password" class="infield"><?php p($l->t('New password')); ?></label>
|
||||||
|
@ -7,3 +7,4 @@
|
||||||
<input type="submit" id="submit" value="<?php p($l->t('Reset password')); ?>" />
|
<input type="submit" id="submit" value="<?php p($l->t('Reset password')); ?>" />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
<?php OCP\Util::addScript('core', 'lostpassword'); ?>
|
||||||
|
|
|
@ -10,9 +10,9 @@ use OC\Core\LostPassword\Application;
|
||||||
|
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
$application->registerRoutes($this, array('routes' => array(
|
$application->registerRoutes($this, array('routes' => array(
|
||||||
array('name' => 'lost#lost', 'url' => '/core/ajax/password/lost', 'verb' => 'POST'),
|
array('name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'),
|
||||||
array('name' => 'lost#reset', 'url' => '/lostpassword/reset/{token}/{uid}', 'verb' => 'GET'),
|
array('name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{uid}', 'verb' => 'GET'),
|
||||||
array('name' => 'lost#resetPassword', 'url' => '/core/ajax/password/reset/{token}/{user}', 'verb' => 'POST'),
|
array('name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{uid}', 'verb' => 'POST'),
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue