Bug 18298: Move password generation to template side
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / member-password.tt
1 [% USE Koha %]
2 [% USE Branches %]
3 [% INCLUDE 'doc-head-open.inc' %]
4 <title>Koha &rsaquo; Patrons &rsaquo; [% IF ( newpassword ) %]Password updated [% ELSE %]Update password for [% surname %], [% firstname %][% END %]</title>
5 [% INCLUDE 'doc-head-close.inc' %]
6 <script type="text/JavaScript">
7 //<![CDATA[
8
9     function generate_password() {
10         // Always generate a strong password
11         var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
12         var length = [% minPasswordLength %];
13         var password='';
14         for ( var i = 0 ; i < length ; i++){
15             password += chars.charAt(Math.floor(Math.random()*chars.length));
16         }
17         return password;
18     }
19     $(document).ready(function() {
20         $("body").on('click', "#fillrandom",function(e) {
21             e.preventDefault();
22             var password = '';
23             var pattern_regex = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{[% minPasswordLength %],}/;
24             while ( ! pattern_regex.test( password ) ) {
25                 password = generate_password();
26             }
27             $("#newpassword").val(password);
28             $("#newpassword").attr('type', 'text');
29             $("#newpassword2").val(password);
30             $("#newpassword2").attr('type', 'text');
31         });
32         $("div.hint").eq(0).after(" <div class=\"hint\"><a href=\"#\" id=\"fillrandom\">"+_("Click to fill with a randomly generated suggestion. ")+"<strong>"+_("Passwords will be displayed as text")+"</strong>.</a></div>");
33
34         $(document).ajaxStart(function () {
35             $("input[name^=newpassword]").hide();
36             $("label[for=newpassword2]").hide();
37             $(".hint:last").after($(".loading").show());
38         });
39         $(document).ajaxStop(function () {
40             $("input[name^=newpassword]").show();
41             $("label[for=newpassword2]").show();
42             $(".loading").hide();
43             $("label.error").hide();
44         });
45         [% IF NOMATCH %]
46             $("#newpassword").addClass('focus');
47         [% END %]
48
49         $("#changepasswordf").validate({
50             rules: {
51                 newpassword: {
52                     required: true,
53                     password_strong: true,
54                     password_no_spaces: true
55                 },
56                 newpassword2: {
57                     required: true,
58                     password_match: true
59                 }
60             }
61         });
62     });
63 //]]>
64 </script>
65 </head>
66 <body id="pat_member-password" class="pat">
67 [% INCLUDE 'header.inc' %]
68 [% INCLUDE 'patron-search.inc' %]
69
70 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% firstname %] [% surname %]</a> &rsaquo; [% IF ( newpassword ) %]Password Updated[% ELSE %]Change username and/or password[% END %]</div>
71
72 <div id="doc3" class="yui-t2">
73
74    <div id="bd">
75         <div id="yui-main">
76         <div class="yui-b">
77 [% INCLUDE 'members-toolbar.inc' %]
78
79 [% IF ( newpassword ) %]
80 <h1>Password Updated</h1>
81
82 [% ELSE %]
83
84 <form method="post" id="changepasswordf" action="/cgi-bin/koha/members/member-password.pl">
85 <input type="hidden" name="destination" value="[% destination %]" />
86 <input type="hidden" name="cardnumber" value="[% cardnumber %]" />
87 <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
88         [% IF ( errormsg ) %]
89                 <div class="dialog alert">
90                 <h4>The following errors have occurred:</h4>
91                 <ul>
92                 [% IF ( BADUSERID ) %]
93         <li>You have entered a username that already exists. Please choose another one.</li>
94                 [% END %]
95                 [% IF ( SHORTPASSWORD ) %]
96                 <li><strong>The password entered is too short</strong>. Password must be at least [% minPasswordLength %] characters.</li>
97                 [% END %]
98                 [% IF ( NOPERMISSION ) %]
99                 <li>You do not have permission to edit this patron's login information.</li>
100                 [% END %]
101                 [% IF ( NOMATCH ) %]
102                 <li><strong>The passwords entered do not match</strong>. Please re-enter the new password.</li>
103                 [% END %]
104                 </ul>
105                 </div>
106         [% END %]
107
108
109     <fieldset class="brief"><legend>Change username and/or password for [% firstname %] [% surname %]</legend>
110         <ol>
111     <li><label for="newuserid">New username:</label>
112         <input type="hidden" name="member" value="[% borrowernumber %]" /><input type="text" id="newuserid" name="newuserid" size="20" value="[% userid %]" /></li>
113     [% SET password_pattern = ".{" _ minPasswordLength _ ",}" %]
114     [% IF Koha.Preference('RequireStrongPassword') %]
115         [% SET password_pattern = '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{' _ minPasswordLength _ ',}' %]
116     [% END %]
117     <li>
118         <label for="newpassword">New password:</label>
119         <div class="hint">Koha cannot display existing passwords. Leave the field blank to leave password unchanged.</div>
120         <input name="newpassword"  id="newpassword" type="password" size="20" />
121     </li>
122     <li>
123         <label for="newpassword2">Confirm new password:</label>
124         <input name="newpassword2"  id="newpassword2" type="password" size="20" />
125     </li>
126         </ol>
127 </fieldset>
128     <fieldset class="action">
129         <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
130         <input type="submit" value="Save" />
131         <a class="cancel" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">Cancel</a>
132     </fieldset>
133 </form>[% END %]
134
135 </div>
136 </div>
137 <div class="loading hide"><strong>Processing...</strong><img src="[% interface %]/[% theme %]/img/loading.gif" alt="" /></div>
138 <div class="yui-b">
139 [% INCLUDE 'circ-menu.inc' %]
140 </div>
141 </div>
142 [% INCLUDE 'intranet-bottom.inc' %]
143 [% PROCESS 'password_check.inc' %]
144 [% PROCESS 'add_password_check' new_password => 'newpassword' %]