summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorivan <ivan>2006-08-09 10:47:18 +0000
committerivan <ivan>2006-08-09 10:47:18 +0000
commit97316d268e5751a1d08a0a37e5a0456f2ce4815c (patch)
treec4b7e57e0852ece5715f4f5ea5f6118ea5a5c3ef /FS/FS
parent95f4195da730f6d40faee94aa7a3108b82823d8d (diff)
self-service interface: add proper password changer and prevent "Setup my services" provisioner from showing broken links for services not handled yet
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/ClientAPI/MyAccount.pm84
-rw-r--r--FS/FS/svc_acct.pm5
2 files changed, 89 insertions, 0 deletions
diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 163718e13..54b8a9979 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -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;
@@ -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 {
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index c50dfd540..b201f2353 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -484,6 +484,11 @@ sub replace {
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;
{