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