12 var callSetPassword = rpc.declare({
14 method: 'setPassword',
15 params: [ 'username', 'password' ],
16 expect: { result: false }
19 return L.view.extend({
20 checkPassword: function(section_id, value) {
21 var strength = document.querySelector('.cbi-value-description'),
22 strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g"),
23 mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g"),
24 enoughRegex = new RegExp("(?=.{6,}).*", "g");
26 if (strength && value.length) {
27 if (false == enoughRegex.test(value))
28 strength.innerHTML = '%s: <span style="color:red">%s</span>'.format(_('Password strength'), _('More Characters'));
29 else if (strongRegex.test(value))
30 strength.innerHTML = '%s: <span style="color:green">%s</span>'.format(_('Password strength'), _('Strong'));
31 else if (mediumRegex.test(value))
32 strength.innerHTML = '%s: <span style="color:orange">%s</span>'.format(_('Password strength'), _('Medium'));
34 strength.innerHTML = '%s: <span style="color:red">%s</span>'.format(_('Password strength'), _('Weak'));
43 m = new form.JSONMap(formData, _('Router Password'), _('Changes the administrator password for accessing the device'));
44 s = m.section(form.NamedSection, 'password', 'password');
46 o = s.option(form.Value, 'pw1', _('Password'));
48 o.validate = this.checkPassword;
50 o = s.option(form.Value, 'pw2', _('Confirmation'), ' ');
52 o.renderWidget = function(/* ... */) {
53 var node = form.Value.prototype.renderWidget.apply(this, arguments);
55 node.childNodes[1].addEventListener('keydown', function(ev) {
56 if (ev.keyCode == 13 && !ev.currentTarget.classList.contains('cbi-input-invalid'))
57 document.querySelector('.cbi-button-save').click();
66 handleSave: function() {
67 var map = document.querySelector('.cbi-map');
69 return L.dom.callClassMethod(map, 'save').then(function() {
70 if (formData.password.pw1 == null || formData.password.pw1.length == 0)
73 if (formData.password.pw1 != formData.password.pw2) {
74 L.ui.addNotification(null, E('p', _('Given password confirmation did not match, password not changed!')), 'danger');
78 return callSetPassword('root', formData.password.pw1).then(function(success) {
80 L.ui.addNotification(null, E('p', _('The system password has been successfully changed.')), 'info');
82 L.ui.addNotification(null, E('p', _('Failed to change the system password.')), 'danger');
84 formData.password.pw1 = null;
85 formData.password.pw2 = null;
87 L.dom.callClassMethod(map, 'render');
92 handleSaveApply: null,