Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit cfecd38

Browse files
author
Jamie Snape
committed
Add option to disable password recovery
1 parent c012643 commit cfecd38

File tree

7 files changed

+43
-17
lines changed

7 files changed

+43
-17
lines changed

core/configs/application.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ dynamichelp = "1"
2121
password.prefix =
2222
; outbound HTTP proxy to be used by PHP (empty for none)
2323
httpproxy =
24+
; allow password reset
25+
allow_password_reset = "1"
2426
; require secure cookies
2527
cookie_secure = "0"
2628
; show debug toolbar

core/controllers/AdminController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public function indexAction()
8181
$formArray['name']->setValue($config->global->application->name);
8282
$formArray['timezone']->setValue($config->global->default->timezone);
8383

84+
if (isset($config->global->allow_password_reset)) {
85+
$formArray['allow_password_reset']->setValue($config->global->allow_password_reset);
86+
}
8487
if (isset($config->global->closeregistration)) {
8588
$formArray['closeregistration']->setValue($config->global->closeregistration);
8689
}
@@ -116,10 +119,11 @@ public function indexAction()
116119
$config->global->application->lang = $this->getParam('lang');
117120
$config->global->default->timezone = $this->getParam('timezone');
118121
$config->global->defaultlicense = $this->getParam('licenseSelect');
119-
$config->global->dynamichelp = $this->getParam('dynamichelp');
122+
$config->global->allow_password_reset = $this->getParam('allow_password_reset');
120123
$config->global->closeregistration = $this->getParam('closeregistration');
121-
$config->global->httpproxy = $this->getParam('httpProxy');
124+
$config->global->dynamichelp = $this->getParam('dynamichelp');
122125
$config->global->gravatar = $this->getParam('gravatar');
126+
$config->global->httpproxy = $this->getParam('httpProxy');
123127

124128
$writer = new Zend_Config_Writer_Ini();
125129
$writer->setConfig($config);

core/controllers/UserController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public function recoverpasswordAction()
8686
if ($this->logged) {
8787
throw new Zend_Exception('Shouldn\'t be logged in');
8888
}
89+
90+
if ((int) Zend_Registry::get('configGlobal')->get('allow_password_reset', 0) === 0) {
91+
throw new Zend_Exception('Password reset is disabled');
92+
}
93+
8994
$this->disableLayout();
9095
$email = $this->getParam('email');
9196
if (isset($email)) {
@@ -643,6 +648,9 @@ public function loginAction()
643648
echo JsonComponent::encode(array('status' => false, 'message' => 'Invalid email or password'));
644649
}
645650
}
651+
652+
$this->view->allowPasswordReset = (int) Zend_Registry::get('configGlobal')->get('allow_password_reset', 0) === 1;
653+
$this->view->closeRegistration = (int) Zend_Registry::get('configGlobal')->get('closeregistration', 0) === 1;
646654
}
647655

648656
/** Term of service */

core/controllers/forms/AdminForm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function createConfigForm()
5454

5555
$dynamichelp = new Zend_Form_Element_Checkbox('dynamichelp');
5656
$gravatar = new Zend_Form_Element_Checkbox('gravatar');
57+
$allowPasswordReset = new Zend_Form_Element_Checkbox('allow_password_reset');
5758
$closeRegistration = new Zend_Form_Element_Checkbox('closeregistration');
5859

5960
$httpProxy = new Zend_Form_Element_Text('httpProxy');
@@ -69,6 +70,7 @@ public function createConfigForm()
6970
$gravatar,
7071
$lang,
7172
$name,
73+
$allowPasswordReset,
7274
$closeRegistration,
7375
$submit,
7476
$httpProxy,

core/public/js/user/user.login.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ $(document).ready(function () {
4949
});
5050

5151
// Deal with password recovery
52-
$('a#forgotPasswordLink').click(function () {
53-
midas.loadDialog("forgotpassword", "/user/recoverpassword");
54-
midas.showDialog("Recover Password");
55-
});
52+
if ($('a#forgotPasswordLink').length) {
53+
$('a#forgotPasswordLink').click(function () {
54+
midas.loadDialog("forgotpassword", "/user/recoverpassword");
55+
midas.showDialog("Recover Password");
56+
});
57+
}
5658

5759
$("a.registerLink").unbind('click').click(function () {
5860
midas.showOrHideDynamicBar('register');

core/views/admin/index.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ $this->headScript()->appendFile($this->coreWebroot.'/public/js/jquery/jquery.clu
8383
<label for='dynamichelp'>Dynamic help</label>
8484
{$this->configForm['dynamichelp']}
8585
</div>
86+
<div qtip='If you enable this feature, password reset will not be allowed.' class='allowPasswordReset'>
87+
<label for='allow_password_reset'>Allow password reset</label>
88+
{$this->configForm['allow_password_reset']}
89+
</div>
8690
<div qtip='If you enable this feature, user registration will not be allowed.' class='closeRegistration'>
8791
<label for='closeregistration'>Close registration</label>
8892
{$this->configForm['closeregistration']}

core/views/user/login.phtml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ echo '<script type="text/javascript" src="'.$this->coreWebroot.'/public/js/user/
3030
<td><label for="email"><?php echo $this->t('Email') ?></label></td>
3131
<td>
3232
<label for="password"><?php echo $this->t('Password') ?></label>
33-
<a id='forgotPasswordLink' style='text-decoration: underline;font-size: 10px;'
34-
href="#"><?php echo $this->t('Forgot your password') ?>?</a>
33+
<?php
34+
if ($this->allowPasswordReset) {
35+
?>
36+
<a id='forgotPasswordLink' style='text-decoration: underline;font-size: 10px;'
37+
href="#"><?php echo $this->t('Forgot your password'); ?>?</a>
38+
<?php
39+
}
40+
?>
3541
</td>
3642
<td></td>
3743
</tr>
@@ -46,16 +52,14 @@ echo '<script type="text/javascript" src="'.$this->coreWebroot.'/public/js/user/
4652
</tr>
4753
<tr>
4854
<td>
49-
<?php if (!isset(Zend_Registry::get('configGlobal')->closeregistration) || Zend_Registry::get(
50-
'configGlobal'
51-
)->closeregistration == "0") {
52-
echo $this->t("Not registered yet?"); ?>
53-
<a class="registerLink" style='text-decoration: underline;'><?php echo $this->t("Register here") ?></a>
55+
<?php
56+
if (!$this->closeRegistration) {
57+
echo $this->t("Not registered yet?"); ?>
58+
<a class="registerLink" style='text-decoration: underline;'><?php echo $this->t("Register here"); ?></a>
59+
<?php
60+
}
61+
?>
5462
</td>
55-
<?php
56-
} else {
57-
echo '</td>';
58-
} ?>
5963
<td><?php echo $this->form['remerberMe'] ?>
6064
<label id="rememberMeText" for="remerberMe"><?php echo $this->t("Remember Me") ?></label></td>
6165
<td></td>

0 commit comments

Comments
 (0)