add setting for "send password link"
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
3c7755fc66
commit
a37f29964f
|
@ -282,9 +282,9 @@ class Manager extends PublicEmitter implements IUserManager {
|
||||||
throw new \Exception($l->t('Username contains whitespace at the beginning or at the end'));
|
throw new \Exception($l->t('Username contains whitespace at the beginning or at the end'));
|
||||||
}
|
}
|
||||||
// No empty password
|
// No empty password
|
||||||
if (trim($password) == '') {
|
// if (trim($password) == '') {
|
||||||
throw new \Exception($l->t('A valid password must be provided'));
|
// throw new \Exception($l->t('A valid password must be provided'));
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Check if user already exists
|
// Check if user already exists
|
||||||
if ($this->userExists($uid)) {
|
if ($this->userExists($uid)) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ use OCP\Mail\IMailer;
|
||||||
use OCP\IAvatarManager;
|
use OCP\IAvatarManager;
|
||||||
use OCP\Security\ICrypto;
|
use OCP\Security\ICrypto;
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
use OC\AppFramework\Utility\TimeFactory;
|
use OCP\AppFramework\Utility\ITimeFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package OC\Settings\Controller
|
* @package OC\Settings\Controller
|
||||||
|
@ -89,7 +89,7 @@ class UsersController extends Controller {
|
||||||
private $accountManager;
|
private $accountManager;
|
||||||
/** @var ISecureRandom */
|
/** @var ISecureRandom */
|
||||||
private $secureRandom;
|
private $secureRandom;
|
||||||
/** @var TimeFactory */
|
/** @var ITimeFactory */
|
||||||
private $timeFactory;
|
private $timeFactory;
|
||||||
/** @var ICrypto */
|
/** @var ICrypto */
|
||||||
private $crypto;
|
private $crypto;
|
||||||
|
@ -113,7 +113,7 @@ class UsersController extends Controller {
|
||||||
* @param IAvatarManager $avatarManager
|
* @param IAvatarManager $avatarManager
|
||||||
* @param AccountManager $accountManager
|
* @param AccountManager $accountManager
|
||||||
* @param ISecureRandom $secureRandom
|
* @param ISecureRandom $secureRandom
|
||||||
* @param TimeFactory $timeFactory
|
* @param ITimeFactory $timeFactory
|
||||||
* @param ICrypto $crypto
|
* @param ICrypto $crypto
|
||||||
*/
|
*/
|
||||||
public function __construct($appName,
|
public function __construct($appName,
|
||||||
|
@ -133,7 +133,7 @@ class UsersController extends Controller {
|
||||||
IAvatarManager $avatarManager,
|
IAvatarManager $avatarManager,
|
||||||
AccountManager $accountManager,
|
AccountManager $accountManager,
|
||||||
ISecureRandom $secureRandom,
|
ISecureRandom $secureRandom,
|
||||||
TimeFactory $timeFactory,
|
ITimeFactory $timeFactory,
|
||||||
ICrypto $crypto) {
|
ICrypto $crypto) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
|
@ -411,19 +411,22 @@ class UsersController extends Controller {
|
||||||
if($email !== '') {
|
if($email !== '') {
|
||||||
$user->setEMailAddress($email);
|
$user->setEMailAddress($email);
|
||||||
|
|
||||||
|
if ($this->config->getAppValue('core', 'umgmt_send_passwordlink', 'false') === 'true') {
|
||||||
$token = $this->secureRandom->generate(
|
$token = $this->secureRandom->generate(
|
||||||
21,
|
21,
|
||||||
ISecureRandom::CHAR_DIGITS.
|
ISecureRandom::CHAR_DIGITS .
|
||||||
ISecureRandom::CHAR_LOWER.
|
ISecureRandom::CHAR_LOWER .
|
||||||
ISecureRandom::CHAR_UPPER
|
ISecureRandom::CHAR_UPPER
|
||||||
);
|
);
|
||||||
$tokenValue = $this->timeFactory->getTime() .':'. $token;
|
$tokenValue = $this->timeFactory->getTime() . ':' . $token;
|
||||||
$mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : '';
|
$mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : '';
|
||||||
$encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress.$this->config->getSystemValue('secret'));
|
$encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret'));
|
||||||
$this->config->setUserValue($username, 'core', 'lostpassword', $encryptedValue);
|
$this->config->setUserValue($username, 'core', 'lostpassword', $encryptedValue);
|
||||||
|
|
||||||
$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $username, 'token' => $token));
|
$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $username, 'token' => $token));
|
||||||
|
} else {
|
||||||
|
$link = $this->urlGenerator->getAbsoluteURL('/');
|
||||||
|
}
|
||||||
|
|
||||||
// data for the mail template
|
// data for the mail template
|
||||||
$mailData = array(
|
$mailData = array(
|
||||||
|
|
|
@ -918,7 +918,7 @@ $(document).ready(function () {
|
||||||
}));
|
}));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($.trim(password) === '') {
|
if ($.trim(password) === '' && !$('#CheckboxMailPasswordOnUserCreate').is(':checked')) {
|
||||||
OC.Notification.showTemporary(t('settings', 'Error creating user: {message}', {
|
OC.Notification.showTemporary(t('settings', 'Error creating user: {message}', {
|
||||||
message: t('settings', 'A valid password must be provided')
|
message: t('settings', 'A valid password must be provided')
|
||||||
}));
|
}));
|
||||||
|
@ -1044,15 +1044,37 @@ $(document).ready(function () {
|
||||||
|
|
||||||
if ($('#CheckboxMailOnUserCreate').is(':checked')) {
|
if ($('#CheckboxMailOnUserCreate').is(':checked')) {
|
||||||
$("#newemail").show();
|
$("#newemail").show();
|
||||||
|
$("#MailPasswordOnUserCreateSetting").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($('#CheckboxMailPasswordOnUserCreate').is(':checked')) {
|
||||||
|
$("#newuserpassword").hide();
|
||||||
|
} else {
|
||||||
|
$("#newuserpassword").show();
|
||||||
|
}
|
||||||
|
|
||||||
// Option to display/hide the "E-Mail" input field
|
// Option to display/hide the "E-Mail" input field
|
||||||
$('#CheckboxMailOnUserCreate').click(function() {
|
$('#CheckboxMailOnUserCreate').click(function() {
|
||||||
if ($('#CheckboxMailOnUserCreate').is(':checked')) {
|
if ($('#CheckboxMailOnUserCreate').is(':checked')) {
|
||||||
$("#newemail").show();
|
$("#newemail").show();
|
||||||
|
$("#MailPasswordOnUserCreateSetting").show();
|
||||||
OCP.AppConfig.setValue('core', 'umgmt_send_email', 'true');
|
OCP.AppConfig.setValue('core', 'umgmt_send_email', 'true');
|
||||||
} else {
|
} else {
|
||||||
$("#newemail").hide();
|
$("#newemail").hide();
|
||||||
|
$("#MailPasswordOnUserCreateSetting").hide();
|
||||||
OCP.AppConfig.setValue('core', 'umgmt_send_email', 'false');
|
OCP.AppConfig.setValue('core', 'umgmt_send_email', 'false');
|
||||||
|
OCP.AppConfig.setValue('core', 'umgmt_send_passwordlink', 'false');
|
||||||
|
$('#CheckboxMailPasswordOnUserCreate').removeAttr('checked');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#CheckboxMailPasswordOnUserCreate').click(function() {
|
||||||
|
if ($('#CheckboxMailPasswordOnUserCreate').is(':checked')) {
|
||||||
|
OCP.AppConfig.setValue('core', 'umgmt_send_passwordlink', 'true');
|
||||||
|
$("#newuserpassword").hide();
|
||||||
|
} else {
|
||||||
|
OCP.AppConfig.setValue('core', 'umgmt_send_passwordlink', 'false');
|
||||||
|
$("#newuserpassword").show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,13 @@ translation('settings');
|
||||||
<?php p($l->t('Send email to new user')) ?>
|
<?php p($l->t('Send email to new user')) ?>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
<p style="padding-left: 20px" id="MailPasswordOnUserCreateSetting">
|
||||||
|
<input type="checkbox" name="MailPasswordOnUserCreate" value="MailPasswordOnUserCreate" id="CheckboxMailPasswordOnUserCreate"
|
||||||
|
class="checkbox" <?php if ($_['send_passwordlink'] === 'true') print_unescaped('checked="checked"'); ?> />
|
||||||
|
<label for="CheckboxMailPasswordOnUserCreate">
|
||||||
|
<?php p($l->t('Send password link')) ?>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<input type="checkbox" name="EmailAddress" value="EmailAddress" id="CheckboxEmailAddress"
|
<input type="checkbox" name="EmailAddress" value="EmailAddress" id="CheckboxEmailAddress"
|
||||||
class="checkbox" <?php if ($_['show_email'] === 'true') print_unescaped('checked="checked"'); ?> />
|
class="checkbox" <?php if ($_['show_email'] === 'true') print_unescaped('checked="checked"'); ?> />
|
||||||
|
|
|
@ -124,5 +124,6 @@ $tmpl->assign('show_last_login', $config->getAppValue('core', 'umgmt_show_last_l
|
||||||
$tmpl->assign('show_email', $config->getAppValue('core', 'umgmt_show_email', 'false'));
|
$tmpl->assign('show_email', $config->getAppValue('core', 'umgmt_show_email', 'false'));
|
||||||
$tmpl->assign('show_backend', $config->getAppValue('core', 'umgmt_show_backend', 'false'));
|
$tmpl->assign('show_backend', $config->getAppValue('core', 'umgmt_show_backend', 'false'));
|
||||||
$tmpl->assign('send_email', $config->getAppValue('core', 'umgmt_send_email', 'false'));
|
$tmpl->assign('send_email', $config->getAppValue('core', 'umgmt_send_email', 'false'));
|
||||||
|
$tmpl->assign('send_passwordlink', $config->getAppValue('core', 'umgmt_send_passwordlink', 'false'));
|
||||||
|
|
||||||
$tmpl->printPage();
|
$tmpl->printPage();
|
||||||
|
|
Loading…
Reference in New Issue