Skip to content

Commit

Permalink
MDL-42208 add password unhiding option to auth configs
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Oct 18, 2013
1 parent fcb103c commit 6e0ace3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions admin/auth_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
echo "</div>\n";
echo "</form>\n";

$unmask = get_string('unmaskpassword', 'core_form');
$attributes = array('formid' => 'authmenu', 'checkboxlabel' => $unmask);
$PAGE->requires->yui_module('moodle-auth-passwordunmask', 'M.auth.passwordunmask', array($attributes));

echo $OUTPUT->footer();
exit;

Expand Down
41 changes: 41 additions & 0 deletions auth/yui/passwordunmask/passwordunmask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
YUI.add('moodle-auth-passwordunmask', function(Y) {
var PASSWORDUNMASK = function() {
PASSWORDUNMASK.superclass.constructor.apply(this, arguments);
}

Y.extend(PASSWORDUNMASK, Y.Base, {
// Initialize checkboxes.
initializer : function(params) {
this.add_checkboxes(params.checkboxlabel);
},
// Create checkboxes for all unmasking passwords.
add_checkboxes : function(checkboxlabel) {
Y.all('#authmenu input[type=password]').each(function(node) {
var elementid = node.get('id');
var elementname = node.get('name');

// Retain unmask div from previous implementation.
var unmaskdiv = Y.Node.create('<div id="'+elementid+'unmaskdiv" class="unmask"></div>');

// Add checkbox for unmasking to unmaskdiv.
var unmaskchb = Y.Node.create('<input id="'+elementid+'unmask" type="checkbox" name="'+elementname+'unmask">');
unmaskdiv.appendChild(unmaskchb);
//Attach event using static javascript function for unmasking password.
unmaskchb.on('click', function() {unmaskPassword(elementid);});

// Add label for checkbox to unmaskdiv.
var unmasklabel = Y.Node.create('<label for="'+elementid+'unmask">'+checkboxlabel+'</label>');
unmaskdiv.appendChild(unmasklabel);

// Insert unmask div in the same div as password input.
node.get('parentNode').insert(unmaskdiv, node.get('lastNode'));
});
return;
}
});

M.auth = M.auth || {};
M.auth.passwordunmask = function(params) {
return new PASSWORDUNMASK(params);
}
}, '@VERSION@', {requires:['base', 'node']});

0 comments on commit 6e0ace3

Please sign in to comment.