X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FMyAccount%2Fcontact.pm;h=c893c105d12863bb5bd6e33b6862289f1521946e;hb=a68f2e9239ad5cde3bd25ca7aea6af7e0f2ce75f;hp=72226e2dcee638475aa9698abdda2cd7b59a0d97;hpb=6419542b10f8ebb0dada9dcb1a48cf78151ca82a;p=freeside.git diff --git a/FS/FS/ClientAPI/MyAccount/contact.pm b/FS/FS/ClientAPI/MyAccount/contact.pm index 72226e2dc..c893c105d 100644 --- a/FS/FS/ClientAPI/MyAccount/contact.pm +++ b/FS/FS/ClientAPI/MyAccount/contact.pm @@ -33,6 +33,8 @@ sub contact_passwd { $error = 'Password too long.' if length($p->{'new_password'}) > ($conf->config('passwordmax') || 8); + $error ||= $contact->is_password_allowed($p->{'new_password'}); + $error ||= $contact->change_password($p->{'new_password'}); return { 'error' => $error }; @@ -82,7 +84,7 @@ sub list_contacts { #TODO: contact phone numbers 'comment' => $_->comment, 'selfservice_access' => $_->selfservice_access, - 'disabled' => $contact->disabled, + #'disabled' => $contact->disabled, }; } $cust_main->cust_contact ); @@ -129,6 +131,9 @@ sub delete_contact { my($context, $session, $custnum) = _custoragent_session_custnum($p); return { 'error' => $session } if $context eq 'error'; + return { 'error' => 'Cannot delete the currently-logged in contact.' } + if $p->{contactnum} == $session->{contactnum}; + my $cust_contact = qsearchs('cust_contact', { contactnum => $p->{contactnum}, custnum => $custnum, }) or return { 'error' => 'Unknown contactnum' }; @@ -138,11 +143,32 @@ sub delete_contact { my $error = $cust_contact->delete; return { 'error' => $error } if $error; - unless ( $contact->cust_contact ) { + unless ( $contact->cust_contact || $contact->prospect_contact ) { $contact->delete; } return { 'error' => '', }; } +sub new_contact { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + #TODO: add phone numbers too + #TODO: specify a classnum by name and/or list_contact_classes method + + my $contact = new FS::contact { + 'custnum' => $custnum, + map { $_ => $p->{$_} } + qw( first last emailaddress classnum comment selfservice_access ) + }; + + $contact->change_password_fields($p->{_password}) if length($p->{_password}); + + my $error = $contact->insert; + return { 'error' => $error, }; +} + 1;