RT# 75817 - updated set contact password to use popup window. fixes break in first...
[freeside.git] / httemplate / misc / process / change-password.html
1 % if ( $error ) {
2 %       if ($svcnum) {
3 %               $cgi->param('svcnum', $svcnum);
4 %               $cgi->param("changepw${svcnum}_error", $error);
5 %       }
6 %       elsif ($contactnum) {
7 %               $cgi->param('contactnum', $contactnum);
8 %               $cgi->param("changepw${contactnum}_error", $error);
9 %       }
10 % } else {
11 %       if ($svcnum) { $cgi->query_string($svcnum); }
12 %       elsif ($contactnum) { $cgi->query_string($contactnum); }
13 % }
14
15 % if (!$popup) {
16 %   if ($svcnum) { 
17          <% $cgi->redirect($fsurl.'view/svc_acct.cgi?'.$cgi->query_string) %>
18 %   }
19 %   elsif ($contactnum) { 
20          <% $cgi->redirect($fsurl.'edit/cust_main-contacts.html?'.$cgi->param('custnum')) %>
21 %   }
22 % }
23
24 <& /elements/header-popup.html, 'Password Set' &>
25 <SCRIPT TYPE="text/javascript">
26   topreload();
27   parent.cClick();
28 </SCRIPT>
29
30 <%init>
31 my $curuser = $FS::CurrentUser::CurrentUser;
32
33 $cgi->param('svcnum') =~ /^(\d+)$/ or die "illegal svcnum" if $cgi->param('svcnum');
34 my $svcnum = $1;
35
36 $cgi->param('contactnum') =~ /^(\d+)$/ or die "illegal contactnum" if $cgi->param('contactnum');
37 my $contactnum = $1;
38
39 my $popup = $cgi->param('popup');
40
41 my $newpass = $cgi->param('password');
42
43 my $error;
44
45 if ($svcnum) {
46         my $svc_acct = FS::svc_acct->by_key($svcnum)
47           or die "svc_acct $svcnum not found";
48         my $part_svc = $svc_acct->part_svc;
49         die "access denied" unless (
50           $curuser->access_right('Provision customer service') or
51           ( $curuser->access_right('Edit password') and 
52             ! $part_svc->restrict_edit_password )
53           );
54
55         my $error = $svc_acct->is_password_allowed($newpass)
56                 ||  $svc_acct->set_password($newpass)
57                 ||  $svc_acct->replace;
58
59         # annoyingly specific to view/svc_acct.cgi, for now...
60         $cgi->delete('password');
61 }
62 elsif ($contactnum) {
63         my $contact = qsearchs('contact', { 'contactnum' => $contactnum } )
64       or return { 'error' => "Contact not found" . $contactnum };
65
66         my $error = $contact->is_password_allowed($newpass)
67                 ||  $contact->change_password($newpass);
68
69         # annoyingly specific to view/svc_acct.cgi, for now...
70         #$cgi->delete('password');
71 }
72
73 </%init>