default to a session cookie instead of setting an explicit timeout, weird timezone...
[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 %    $cgi->param('error', $error);
11 % } else {
12 %       if ($svcnum) { $cgi->query_string($svcnum); }
13 %       elsif ($contactnum) { $cgi->query_string($contactnum); }
14 % }
15
16 % if (!$popup) {
17 %   if ($svcnum) { 
18          <% $cgi->redirect($fsurl.'view/svc_acct.cgi?'.$cgi->query_string) %>
19 %   }
20 %   elsif ($contactnum) { 
21 %     my $freeside_status = "Contact ".$contact->{'Hash'}->{'first'}." ".$contact->{'Hash'}->{'last'}." password updated.";
22          <% $cgi->redirect( -uri    => popurl(3). "view/cust_main.cgi?". $cgi->param('custnum'),
23                    -cookie => CGI::Cookie->new(
24                      -name    => 'freeside_status',
25                      -value   => mt($freeside_status),
26                      -expires => '+5m',
27                    ),
28    )
29 %>
30 %   }
31 % }
32
33 <& /elements/header-popup.html, 'Password Set' &>
34 <SCRIPT TYPE="text/javascript">
35   topreload();
36   parent.cClick();
37 </SCRIPT>
38
39 <%init>
40 my $curuser = $FS::CurrentUser::CurrentUser;
41 my $contact;
42
43 $cgi->param('svcnum') =~ /^(\d+)$/ or die "illegal svcnum" if $cgi->param('svcnum');
44 my $svcnum = $1;
45
46 foreach my $prefix (grep /^(.*)(password)$/, $cgi->param) {
47      $cgi->param('password' => $cgi->param($prefix));
48 }
49
50 $cgi->param('contactnum') =~ /^(\d+)$/ or die "illegal contactnum" if $cgi->param('contactnum');
51 my $contactnum = $1;
52
53 my $popup = $cgi->param('popup');
54
55 my $newpass = $cgi->param('password');
56
57 my $error;
58
59 if ($svcnum) {
60         my $svc_acct = FS::svc_acct->by_key($svcnum)
61           or die "svc_acct $svcnum not found";
62         my $part_svc = $svc_acct->part_svc;
63         die "access denied" unless (
64           $curuser->access_right('Provision customer service') or
65           ( $curuser->access_right('Edit password') and 
66             ! $part_svc->restrict_edit_password )
67           );
68
69         $error = $svc_acct->is_password_allowed($newpass)
70                 ||  $svc_acct->set_password($newpass)
71                 ||  $svc_acct->replace;
72
73         # annoyingly specific to view/svc_acct.cgi, for now...
74         $cgi->delete('password');
75 }
76 elsif ($contactnum) {
77         $contact = qsearchs('contact', { 'contactnum' => $contactnum } )
78       or return { 'error' => "Contact not found" . $contactnum };
79
80         $error = $contact->is_password_allowed($newpass)
81                 ||  $contact->change_password($newpass);
82
83         # annoyingly specific to view/svc_acct.cgi, for now...
84         #$cgi->delete('password');
85 }
86
87 </%init>