self-service interface: add proper password changer and prevent "Setup my services...
authorivan <ivan>
Wed, 9 Aug 2006 10:47:18 +0000 (10:47 +0000)
committerivan <ivan>
Wed, 9 Aug 2006 10:47:18 +0000 (10:47 +0000)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/svc_acct.pm
fs_selfservice/FS-SelfService/SelfService.pm
fs_selfservice/FS-SelfService/cgi/change_password.html [new file with mode: 0644]
fs_selfservice/FS-SelfService/cgi/myaccount_menu.html
fs_selfservice/FS-SelfService/cgi/process_change_password.html [new file with mode: 0644]
fs_selfservice/FS-SelfService/cgi/provision_list.html
fs_selfservice/FS-SelfService/cgi/selfservice.cgi

index 163718e..54b8a99 100644 (file)
@@ -526,6 +526,51 @@ sub list_pkgs {
 
 }
 
 
 }
 
+sub list_svcs {
+  my $p = shift;
+
+  use Data::Dumper;
+
+  my($context, $session, $custnum) = _custoragent_session_custnum($p);
+  return { 'error' => $session } if $context eq 'error';
+
+  my $search = { 'custnum' => $custnum };
+  $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+  my $cust_main = qsearchs('cust_main', $search )
+    or return { 'error' => "unknown custnum $custnum" };
+
+  my @cust_svc = ();
+  #foreach my $cust_pkg ( $cust_main->ncancelled_pkgs ) {
+  foreach my $cust_pkg ( $cust_main->unsuspended_pkgs ) {
+    push @cust_svc, @{[ $cust_pkg->cust_svc ]}; #@{[ ]} to force array context
+  }
+  @cust_svc = grep { $_->part_svc->svcdb eq $p->{'svcdb'} } @cust_svc
+    if $p->{'svcdb'};
+
+  #@svc_x = sort { $a->domain cmp $b->domain || $a->username cmp $b->username }
+  #              @svc_x;
+
+  { 
+    #no#'svcnum'   => $session->{'svcnum'},
+    'custnum'  => $custnum,
+    'svcs'     => [ map { 
+                          my $svc_x = $_->svc_x;
+                          my($label, $value) = $_->label;
+
+                          { 'svcnum'   => $_->svcnum,
+                            'label'    => $label,
+                            'value'    => $value,
+                            'username' => $svc_x->username,
+                            'email'    => $svc_x->email,
+                            # more...
+                          };
+                        }
+                        @cust_svc
+                  ],
+  };
+
+}
+
 sub order_pkg {
   my $p = shift;
 
 sub order_pkg {
   my $p = shift;
 
@@ -799,6 +844,45 @@ sub unprovision_svc {
 
 }
 
 
 }
 
+sub myaccount_passwd {
+  my $p = shift;
+  my($context, $session, $custnum) = _custoragent_session_custnum($p);
+  return { 'error' => $session } if $context eq 'error';
+
+  return { 'error' => "New passwords don't match." }
+    if $p->{'new_password'} ne $p->{'new_password2'};
+
+  return { 'error' => 'Enter new password' }
+    unless length($p->{'new_password'});
+
+  #my $search = { 'custnum' => $custnum };
+  #$search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+  $custnum =~ /^(\d+)$/ or die "illegal custnum";
+  my $search = " AND custnum = $1";
+  $search .= " AND agentnum = ". $session->{'agentnum'} if $context eq 'agent';
+
+  my $svc_acct = qsearchs( {
+    'table'     => 'svc_acct',
+    'addl_from' => 'LEFT JOIN cust_svc  USING ( svcnum  ) '.
+                   'LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
+                   'LEFT JOIN cust_main USING ( custnum ) ',
+    'hashref'   => { 'svcnum' => $p->{'svcnum'}, },
+    'extra_sql' => $search, #important
+  } )
+    or return { 'error' => "Service not found" };
+
+  $svc_acct->_password($p->{'new_password'});
+  my $error = $svc_acct->replace();
+
+  my($label, $value) = $svc_acct->cust_svc->label;
+
+  return { 'error' => $error,
+           'label' => $label,
+           'value' => $value,
+         };
+
+}
+
 #--
 
 sub _custoragent_session_custnum {
 #--
 
 sub _custoragent_session_custnum {
index c50dfd5..b201f23 100644 (file)
@@ -484,6 +484,11 @@ sub replace {
   my $error;
   warn "$me replacing $old with $new\n" if $DEBUG;
 
   my $error;
   warn "$me replacing $old with $new\n" if $DEBUG;
 
+  # We absolutely have to have an old vs. new record to make this work.
+  if (!defined($old)) {
+    $old = qsearchs( 'svc_acct', { 'svcnum' => $new->svcnum } );
+  }
+
   return "can't modify system account" if $old->_check_system;
 
   {
   return "can't modify system account" if $old->_check_system;
 
   {
index 16ca48e..c3026fa 100644 (file)
@@ -33,7 +33,8 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'payment_info'         => 'MyAccount/payment_info',
   'process_payment'      => 'MyAccount/process_payment',
   'process_prepay'       => 'MyAccount/process_prepay',
   'payment_info'         => 'MyAccount/payment_info',
   'process_payment'      => 'MyAccount/process_payment',
   'process_prepay'       => 'MyAccount/process_prepay',
-  'list_pkgs'            => 'MyAccount/list_pkgs',     #add to ss cgi!
+  'list_pkgs'            => 'MyAccount/list_pkgs',     #add to ss cgi (added?)
+  'list_svcs'            => 'MyAccount/list_svcs',     #add to ss cgi (added?)
   'order_pkg'            => 'MyAccount/order_pkg',     #add to ss cgi!
   'cancel_pkg'           => 'MyAccount/cancel_pkg',    #add to ss cgi!
   'charge'               => 'MyAccount/charge',        #?
   'order_pkg'            => 'MyAccount/order_pkg',     #add to ss cgi!
   'cancel_pkg'           => 'MyAccount/cancel_pkg',    #add to ss cgi!
   'charge'               => 'MyAccount/charge',        #?
@@ -41,6 +42,7 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'provision_acct'       => 'MyAccount/provision_acct',
   'provision_external'   => 'MyAccount/provision_external',
   'unprovision_svc'      => 'MyAccount/unprovision_svc',
   'provision_acct'       => 'MyAccount/provision_acct',
   'provision_external'   => 'MyAccount/provision_external',
   'unprovision_svc'      => 'MyAccount/unprovision_svc',
+  'myaccount_passwd'     => 'MyAccount/myaccount_passwd',
   'signup_info'          => 'Signup/signup_info',
   'new_customer'         => 'Signup/new_customer',
   'agent_login'          => 'Agent/agent_login',
   'signup_info'          => 'Signup/signup_info',
   'new_customer'         => 'Signup/new_customer',
   'agent_login'          => 'Agent/agent_login',
@@ -73,6 +75,7 @@ foreach my $autoload ( keys %autoload ) {
                    if ( ref($_[0]) ) {
                      $param = shift;
                    } else {
                    if ( ref($_[0]) ) {
                      $param = shift;
                    } else {
+                     #warn scalar(@_). ": ". join(" / ", @_);
                      $param = { @_ };
                    }
 
                      $param = { @_ };
                    }
 
diff --git a/fs_selfservice/FS-SelfService/cgi/change_password.html b/fs_selfservice/FS-SelfService/cgi/change_password.html
new file mode 100644 (file)
index 0000000..af7b453
--- /dev/null
@@ -0,0 +1,53 @@
+<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD>
+<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR>
+<%= $url = "$selfurl?session=$session_id;action="; ''; %>
+<%= include('myaccount_menu') %>
+<TD VALIGN="top">
+
+<FONT SIZE=4>Change password</FONT><BR><BR>
+
+<%= if ( $error ) {
+  $OUT .= qq!<FONT SIZE="+1" COLOR="#ff0000">$error</FONT><BR><BR>!;
+} ''; %>
+
+<FORM ACTION="<%= $selfurl %>" METHOD="POST">
+<INPUT TYPE="hidden" NAME="session" VALUE="<%= $session_id %>">
+<INPUT TYPE="hidden" NAME="action" VALUE="process_change_password">
+
+<TABLE BGCOLOR="#cccccc">
+
+  <TR>
+    <TH ALIGN="right">Change password for account: </TH>
+    <TD>
+      <SELECT NAME="svcnum">
+        <%= foreach my $svc ( @svcs ) {
+              $OUT .= '<OPTION VALUE="'. $svc->{'svcnum'}. '"'.
+                        ( $svc->{'svcnum'} eq $svcnum ? ' SELECTED' : '' ). '>'.
+                      $svc->{'label'}. ': '. $svc->{'value'}. "\n";
+            }
+        %>
+      </SELECT>
+    </TD>
+  </TR>
+
+  <TR>
+    <TH ALIGN="right">New password: </TH>
+    <TD><INPUT TYPE="password" NAME="new_password" SIZE="18"></TD>
+  </TR>
+
+  <TR>
+    <TH ALIGN="right">Re-enter new password: </TH>
+    <TD><INPUT TYPE="password" NAME="new_password2" SIZE="18"></TD>
+  </TR>
+
+</TABLE>
+<BR>
+
+<INPUT TYPE="submit" VALUE="Change password">
+
+</FORM>
+
+</TD></TR></TABLE>
+<HR>
+<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT>
+</BODY></HTML>
index f2e5e99..aa22e7c 100644 (file)
@@ -35,9 +35,9 @@ push @menu, (
 { title=>' ' },
 
 { title=>'Change my information', size=>'+1', },
 { title=>' ' },
 
 { title=>'Change my information', size=>'+1', },
-  { title=>'Change payment information*', url=>'change_bill', indent=>2 },
-  { title=>'Change service address*',     url=>'change_ship', indent=>2 },
-  { title=>'Change password(s)*',         url=>'hmmmFIXME',   indent=>2 },
+  { title=>'Change payment information*', url=>'change_bill',     indent=>2 },
+  { title=>'Change service address*',     url=>'change_ship',     indent=>2 },
+  { title=>'Change password(s)',          url=>'change_password', indent=>2 },
 
 { title=>' ' },
 
 
 { title=>' ' },
 
@@ -82,8 +82,8 @@ foreach my $item ( @menu ) {
 
 %>
 
 
 %>
 
+<TR><TD STYLE="border-right: 1px solid black"><BR><BR>*&nbsp;coming&nbsp;soon</TD></TR>
+
 </TABLE>
 
 </TABLE>
 
-<A HREF="passwd.html">(tempFIXME) Change&nbsp;password(s)</A><BR><BR>
-*&nbsp;coming&nbsp;soon
 </TD>
 </TD>
diff --git a/fs_selfservice/FS-SelfService/cgi/process_change_password.html b/fs_selfservice/FS-SelfService/cgi/process_change_password.html
new file mode 100644 (file)
index 0000000..4fdee79
--- /dev/null
@@ -0,0 +1,13 @@
+<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD>
+<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR>
+<%= $url = "$selfurl?session=$session_id;action="; ''; %>
+<%= include('myaccount_menu') %>
+<TD VALIGN="top">
+
+<FONT SIZE=4>Password changed for <%= $value %> <%= $label %>.</FONT>
+
+</TD></TR></TABLE>
+<HR>
+<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT>
+</BODY></HTML>
+
index 0f68dfe..cd587f0 100644 (file)
@@ -75,7 +75,10 @@ function areyousure(href, message) {
     $OUT .= "<TR>$td COLSPAN=3 ALIGN=center>".
             qq!<A HREF="$link">!. 'Setup '. $part_svc->{'svc'}. '</A> '.
             '('. $part_svc->{'num_avail'}. ' available)'.
     $OUT .= "<TR>$td COLSPAN=3 ALIGN=center>".
             qq!<A HREF="$link">!. 'Setup '. $part_svc->{'svc'}. '</A> '.
             '('. $part_svc->{'num_avail'}. ' available)'.
-            '</TD></TR>';
+            '</TD></TR>'
+      #self-service only supports these services so far
+      if grep { $part_svc->{'svcdb'} eq $_ } qw( svc_acct svc_external );
+
     $col = $col eq $col1 ? $col2 : $col1;
   }
 
     $col = $col eq $col1 ? $col2 : $col1;
   }
 
index 034a684..4ab1309 100644 (file)
@@ -13,6 +13,7 @@ use FS::SelfService qw( login customer_info invoice
                         list_pkgs
                         part_svc_info provision_acct provision_external
                         unprovision_svc
                         list_pkgs
                         part_svc_info provision_acct provision_external
                         unprovision_svc
+                        list_svcs myaccount_passwd
                       );
 
 $template_dir = '.';
                       );
 
 $template_dir = '.';
@@ -62,7 +63,7 @@ $session_id = $cgi->param('session');
 
 #order|pw_list XXX ???
 $cgi->param('action') =~
 
 #order|pw_list XXX ???
 $cgi->param('action') =~
-    /^(myaccount|view_invoice|make_payment|payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc)$/
+    /^(myaccount|view_invoice|make_payment|payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc|change_password|process_change_password)$/
   or die "unknown action ". $cgi->param('action');
 my $action = $1;
 
   or die "unknown action ". $cgi->param('action');
 my $action = $1;
 
@@ -257,6 +258,41 @@ sub delete_svc {
   );
 }
 
   );
 }
 
+sub change_password {
+  list_svcs(
+    'session_id' => $session_id,
+    'svcdb'      => 'svc_acct',
+  );
+};
+
+sub process_change_password {
+
+  my $result = myaccount_passwd(
+    'session_id'    => $session_id,
+    map { $_ => $cgi->param($_) } qw( svcnum new_password new_password2 )
+  );
+
+  if ( exists $result->{'error'} && $result->{'error'} ) { 
+
+    $action = 'change_password';
+    return {
+      $cgi->Vars,
+      %{ list_svcs( 'session_id' => $session_id,
+                    'svcdb'      => 'svc_acct',
+                  )
+       },
+      #'svcnum' => $cgi->param('svcnum'),
+      'error'  => $result->{'error'}
+    };
+
+ } else {
+
+   return $result;
+
+ }
+
+}
+
 #--
 
 sub do_template {
 #--
 
 sub do_template {