add switch_acct and reset_passwd to self-service API, RT#13656
authorivan <ivan>
Sat, 8 Oct 2011 21:55:20 +0000 (21:55 +0000)
committerivan <ivan>
Sat, 8 Oct 2011 21:55:20 +0000 (21:55 +0000)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/ClientAPI_XMLRPC.pm
FS/FS/Conf.pm
fs_selfservice/FS-SelfService/SelfService.pm

index e3afac1..7608439 100644 (file)
@@ -251,6 +251,25 @@ sub logout {
   }
 }
 
+sub switch_acct {
+  my $p = shift;
+
+  my($context, $session, $custnum) = _custoragent_session_custnum($p);
+  return { 'error' => $session } if $context eq 'error';
+
+  my $svc_acct = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct' )
+    or return { 'error' => "Service not found" };
+
+  $session->{'svcnum'} = $svc_acct->svcnum;
+
+  my $conf = new FS::Conf;
+  my $timeout = $conf->config('selfservice-session_timeout') || '1 hour';
+  _cache->set( $p->{'session_id'}, $session, $timeout );
+
+  return { 'error' => '' };
+
+}
+
 sub payment_gateway {
   # internal use only
   # takes a cust_main and a cust_payby entry, returns the payment_gateway
@@ -2260,6 +2279,66 @@ sub myaccount_passwd {
 
 }
 
+sub reset_passwd {
+  my $p = shift;
+
+  my $conf = new FS::Conf;
+  my $verification = $conf->config('selfservice-password_reset_verification')
+    or return { 'error' => 'Password resets disabled' };
+
+  my $username = $p->{'username'};
+
+  my $svc_domain = qsearchs('svc_domain', { 'domain' => $p->{'domain'} } )
+    or return { 'error' => 'Account not found' };
+
+  my $svc_acct = qsearchs('svc_acct', { 'username' => $p->{'username'},
+                                        'domsvc'   => $svc_domain->svcnum  }
+                         )
+    or return { 'error' => 'Account not found' };
+
+  my $cust_pkg = $svc_acct->cust_svc->cust_pkg
+    or return { 'error' => 'Account not found' };
+
+  my $cust_main = $cust_pkg->cust_main;
+
+  my %verify = (
+    'paymask' => sub { 
+      my( $p, $cust_main ) = @_;
+      $cust_main->payby =~ /^(CARD|DCRD|CHEK|DCHK)$/
+        && $p->{'paymask'} eq substr($cust_main->paymask, -4)
+    },
+    'amount'  => sub {
+      my( $p, $cust_main ) = @_;
+      my $cust_pay = qsearchs({
+        'table' => 'cust_pay',
+        'hashref' => { 'custnum' => $cust_main->custnum },
+        'order_by' => 'ORDER BY _date DESC LIMIT 1',
+      })
+        or return 0;
+
+      $p->{'amount'} == $cust_pay->paid;
+    },
+    'zip'     => sub {
+      my( $p, $cust_main ) = @_;
+      $p->{'zip'} eq $cust_main->zip
+        || ( $cust_main->ship_zip && $p->{'zip'} eq $cust_main->ship_zip );
+    },
+  );
+
+  foreach my $verify ( split(',', $verification) ) {
+
+    &{ $verify{$verify} }( $p, $cust_main )
+      or return { 'error' => 'Account not found' };
+
+  }
+
+  #we're verified.  now what?
+
+  return { 'error' => '' };
+}
+
+
 sub create_ticket {
   my $p = shift;
   my($context, $session, $custnum) = _custoragent_session_custnum($p);
index 2913ffd..b909519 100644 (file)
@@ -66,6 +66,7 @@ sub ss2clientapi {
   'login_info'                => 'MyAccount/login_info',
   'login'                     => 'MyAccount/login',
   'logout'                    => 'MyAccount/logout',
+  'switch_acct'               => 'MyAccount/switch_acct',
   'customer_info'             => 'MyAccount/customer_info',
   'customer_info_short'       => 'MyAccount/customer_info_short',
   'edit_info'                 => 'MyAccount/edit_info',     #add to ss cgi!
@@ -107,6 +108,7 @@ sub ss2clientapi {
   'provision_external'        => 'MyAccount/provision_external',
   'unprovision_svc'           => 'MyAccount/unprovision_svc',
   'myaccount_passwd'          => 'MyAccount/myaccount_passwd',
+  'reset_passwd'              => 'MyAccount/reset_passwd',
   'create_ticket'             => 'MyAccount/create_ticket',
   'get_ticket'                => 'MyAccount/get_ticket',
   'adjust_ticket_priority'    => 'MyAccount/adjust_ticket_priority',
index 831b80f..e04ab1a 100644 (file)
@@ -2465,6 +2465,16 @@ and customer address. Include units.',
     'type'        => 'select-part_svc',
     'multiple'    => 1,
   },
+
+  {
+    'key'         => 'selfservice-password_reset_verification',
+    'section'     => 'self-service',
+    'description' => 'If enabled, specifies the type of verification required for self-service password resets.',
+    'type'        => 'select',
+    'select_hash' => [ '' => 'Password reset disabled',
+                       'paymask,amount,zip' => 'Verify with credit card (or bank account) last 4 digits, payment amount and zip code',
+                     ],
+  },
   
   {
     'key'         => 'selfservice-recent-did-age',
index 3567846..89796b7 100644 (file)
@@ -28,6 +28,7 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'login_info'                => 'MyAccount/login_info',
   'login'                     => 'MyAccount/login',
   'logout'                    => 'MyAccount/logout',
+  'switch_acct'               => 'MyAccount/switch_acct',
   'customer_info'             => 'MyAccount/customer_info',
   'customer_info_short'       => 'MyAccount/customer_info_short',
   'edit_info'                 => 'MyAccount/edit_info',     #add to ss cgi!
@@ -69,6 +70,7 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'provision_external'        => 'MyAccount/provision_external',
   'unprovision_svc'           => 'MyAccount/unprovision_svc',
   'myaccount_passwd'          => 'MyAccount/myaccount_passwd',
+  'reset_passwd'              => 'MyAccount/reset_passwd',
   'create_ticket'             => 'MyAccount/create_ticket',
   'get_ticket'                => 'MyAccount/get_ticket',
   'adjust_ticket_priority'    => 'MyAccount/adjust_ticket_priority',