Permalink
Browse files

feature(forms): Add new user now has an option to autogenerate the pa…

…ssword

Makes it easier for admins to add new users by adding an option to autogenerate passwords.
  • Loading branch information...
hypeJunction committed Jun 13, 2016
1 parent 91c76df commit ee4758d3c053e5b22827f368ebf1546dc41208a6
Showing with 59 additions and 0 deletions.
  1. +6 −0 actions/useradd.php
  2. +1 −0 languages/en.php
  3. +41 −0 views/default/forms/useradd.js
  4. +11 −0 views/default/forms/useradd.php
View
@@ -24,6 +24,12 @@
$admin = $admin[0];
}
$autogen_password = get_input('autogen_password');
if ($autogen_password) {
$password = generate_random_cleartext_password();
$password2 = $password;
}
// no blank fields
if ($username == '' || $password == '' || $password2 == '' || $email == '' || $name == '') {
register_error(elgg_echo('register:fields'));
View
@@ -142,6 +142,7 @@
'password' => "Password",
'passwordagain' => "Password (again for verification)",
'admin_option' => "Make this user an admin?",
'autogen_password_option' => "Automatically generate a secure password?",
/**
* Access
@@ -0,0 +1,41 @@
define(function(require) {
var $ = require('jquery');
var checkbox_selector = 'input[type="checkbox"][name="autogen_password"]';
/**
* Toggle password input visibility based on the value
* of the autogenerate password checkbox
*
* @param {jQuery} $checkbox Checkbox input
* @returns {void}
*/
function togglePasswordInput($checkbox) {
var $form = $checkbox.closest('.elgg-form-useradd');
if (!$form.length) {
return;
}
if ($checkbox.is(':checked')) {
$('[name="password"],[name="password2"]', $form).each(function() {
$(this).prop('required', false);
$(this).closest('.elgg-field').addClass('hidden');
});
} else {
$('[name="password"],[name="password2"]', $form).each(function() {
$(this).prop('required', true);
$(this).closest('.elgg-field').removeClass('hidden');
});
}
}
$(document).on('change', checkbox_selector, function() {
togglePasswordInput($(this));
});
require(['elgg/ready'], function() {
togglePasswordInput($(checkbox_selector));
});
});
@@ -1,11 +1,13 @@
<?php
/**
* Elgg add user form.
*
* @package Elgg
* @subpackage Core
*
*/
elgg_require_js('forms/useradd');
if (elgg_is_sticky_form('useradd')) {
$values = elgg_get_sticky_values('useradd');
@@ -19,6 +21,7 @@
$username = elgg_extract('username', $values);
$email = elgg_extract('email', $values);
$admin = elgg_extract('admin', $values);
$autogen_password = elgg_extract('autogen_password', $values);
echo elgg_view_input('text', [
'name' => 'name',
@@ -41,6 +44,14 @@
'required' => true,
]);
echo elgg_view_input('checkbox', array(
'name' => 'autogen_password',
'value' => 1,
'default' => false,
'label' => elgg_echo('autogen_password_option'),
'checked' => (bool) $autogen_password,
));
echo elgg_view_input('password', [
'name' => 'password',
'value' => $password,

0 comments on commit ee4758d

Please sign in to comment.