From 97316d268e5751a1d08a0a37e5a0456f2ce4815c Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 9 Aug 2006 10:47:18 +0000 Subject: [PATCH] self-service interface: add proper password changer and prevent "Setup my services" provisioner from showing broken links for services not handled yet --- FS/FS/ClientAPI/MyAccount.pm | 84 ++++++++++++++++++++++ FS/FS/svc_acct.pm | 5 ++ fs_selfservice/FS-SelfService/SelfService.pm | 5 +- .../FS-SelfService/cgi/change_password.html | 53 ++++++++++++++ .../FS-SelfService/cgi/myaccount_menu.html | 10 +-- .../cgi/process_change_password.html | 13 ++++ .../FS-SelfService/cgi/provision_list.html | 5 +- fs_selfservice/FS-SelfService/cgi/selfservice.cgi | 38 +++++++++- 8 files changed, 205 insertions(+), 8 deletions(-) create mode 100644 fs_selfservice/FS-SelfService/cgi/change_password.html create mode 100644 fs_selfservice/FS-SelfService/cgi/process_change_password.html 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; { diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 16ca48ec8..c3026fa13 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -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', - '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', #? @@ -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', + 'myaccount_passwd' => 'MyAccount/myaccount_passwd', '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 { + #warn scalar(@_). ": ". join(" / ", @_); $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 index 000000000..af7b45313 --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/change_password.html @@ -0,0 +1,53 @@ +MyAccount +MyAccount

+<%= $url = "$selfurl?session=$session_id;action="; ''; %> +<%= include('myaccount_menu') %> + + +Change password

+ +<%= if ( $error ) { + $OUT .= qq!$error

!; +} ''; %> + +
+ + + + + + + + + + + + + + + + + + + + +
Change password for account: + +
New password:
Re-enter new password:
+
+ + + +
+ + +
+powered by freeside + diff --git a/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html b/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html index f2e5e998e..aa22e7c9b 100644 --- a/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html +++ b/fs_selfservice/FS-SelfService/cgi/myaccount_menu.html @@ -35,9 +35,9 @@ push @menu, ( { 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=>' ' }, @@ -82,8 +82,8 @@ foreach my $item ( @menu ) { %> +

* coming soon + -(tempFIXME) Change password(s)

-* coming soon 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 index 000000000..4fdee79f3 --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/process_change_password.html @@ -0,0 +1,13 @@ +MyAccount +MyAccount

+<%= $url = "$selfurl?session=$session_id;action="; ''; %> +<%= include('myaccount_menu') %> + + +Password changed for <%= $value %> <%= $label %>. + + +
+powered by freeside + + diff --git a/fs_selfservice/FS-SelfService/cgi/provision_list.html b/fs_selfservice/FS-SelfService/cgi/provision_list.html index 0f68dfe3c..cd587f072 100644 --- a/fs_selfservice/FS-SelfService/cgi/provision_list.html +++ b/fs_selfservice/FS-SelfService/cgi/provision_list.html @@ -75,7 +75,10 @@ function areyousure(href, message) { $OUT .= "$td COLSPAN=3 ALIGN=center>". qq!!. 'Setup '. $part_svc->{'svc'}. ' '. '('. $part_svc->{'num_avail'}. ' available)'. - ''; + '' + #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; } diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index 034a684c6..4ab13090f 100644 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -13,6 +13,7 @@ use FS::SelfService qw( login customer_info invoice list_pkgs part_svc_info provision_acct provision_external unprovision_svc + list_svcs myaccount_passwd ); $template_dir = '.'; @@ -62,7 +63,7 @@ $session_id = $cgi->param('session'); #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; @@ -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 { -- 2.11.0