make password-insecure option work when adding a new svc_acct, #40236
[freeside.git] / httemplate / elements / validate_password.html
1 <%doc>
2
3 To validate passwords via javascript/xmlhttp:
4
5   <INPUT ID="password_field" TYPE="text">
6   <DIV ID="password_field_result">
7   <& '/elements/validate_password.html', 
8       fieldid  => 'password_field',
9       svcnum   => $svcnum,
10       pkgnum   => $pkgnum, # used if the service doesn't exist yet
11   &>
12
13 The ID of the input field can be anything;  the ID of the DIV in which to display results
14 should be the input id plus '_result'.
15
16 </%doc>
17
18 <& '/elements/xmlhttp.html',
19     'url'  => $p.'misc/xmlhttp-validate_password.html',
20     'subs' => [ 'validate_password' ],
21     'method' => 'POST', # important not to put passwords in url
22 &>
23 <SCRIPT>
24 function add_password_validation (fieldid) {
25   var inputfield = document.getElementById(fieldid);
26   inputfield.onchange = function () {
27     var fieldid = this.id+'_result';
28     var resultfield = document.getElementById(fieldid);
29     if (this.value) {
30       resultfield.innerHTML = '<SPAN STYLE="color: blue;">Validating password...</SPAN>';
31       validate_password('fieldid',fieldid,
32                         'svcnum',<% $opt{'svcnum'} |js_string %>,
33                         'pkgnum',<% $opt{'pkgnum'} |js_string %>,
34                         'password',this.value,
35         function (result) {
36           result = JSON.parse(result);
37           var resultfield = document.getElementById(result.fieldid);
38           if (resultfield) {
39             var errorimg = '<IMG SRC="<% $p %>images/error.png" style="width: 1em; display: inline-block; padding-right: .5em">';
40             var validimg = '<IMG SRC="<% $p %>images/tick.png" style="width: 1em; display: inline-block; padding-right: .5em">';
41             if (result.valid) {
42               resultfield.innerHTML = validimg+'<SPAN STYLE="color: green;">Password valid!</SPAN>';
43             } else if (result.error) {
44               resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.error+'</SPAN>';
45             } else {
46               result.syserror = result.syserror || 'Server error';
47               resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.syserror+'</SPAN>';
48             }
49           }
50         }
51       );
52     } else {
53       resultfield.innerHTML = '';
54     }
55   };
56 }
57 add_password_validation('<% $opt{'fieldid'} %>');
58 </SCRIPT>
59
60 <%init>
61 my %opt = @_;
62 </%init>
63
64