RT# 75817 - Added the ability to set contacts password on the backend
[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                         'contactnum',<% $opt{'contactnum'} |js_string %>,
35                         'password',this.value,
36         function (result) {
37           result = JSON.parse(result);
38           var resultfield = document.getElementById(result.fieldid);
39           if (resultfield) {
40             var errorimg = '<IMG SRC="<% $p %>images/error.png" style="width: 1em; display: inline-block; padding-right: .5em">';
41             var validimg = '<IMG SRC="<% $p %>images/tick.png" style="width: 1em; display: inline-block; padding-right: .5em">';
42             if (result.valid) {
43               resultfield.innerHTML = validimg+'<SPAN STYLE="color: green;">Password valid!</SPAN>';
44             } else if (result.error) {
45               resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.error+'</SPAN>';
46             } else {
47               result.syserror = result.syserror || 'Server error';
48               resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.syserror+'</SPAN>';
49             }
50           }
51         }
52       );
53     } else {
54       resultfield.innerHTML = '';
55     }
56   };
57 }
58 add_password_validation('<% $opt{'fieldid'} %>');
59 </SCRIPT>
60
61 <%init>
62 my %opt = @_;
63 </%init>
64
65