eliminate dups, RT#85671
[freeside.git] / FS / FS / ClientAPI / MyAccount / contact.pm
index 099da29..dd3a40b 100644 (file)
@@ -26,12 +26,9 @@ sub contact_passwd {
 
   my $error = '';
 
-  # use these svc_acct length restrictions??
-  my $conf = new FS::Conf;
-  $error = 'Password too short.'
-    if length($p->{'new_password'}) < ($conf->config('passwordmin') || 6);
-  $error = 'Password too long.'
-    if length($p->{'new_password'}) > ($conf->config('passwordmax') || 8);
+  # length checks now in is_password_allowed
+
+  $error ||= $contact->is_password_allowed($p->{'new_password'});
 
   $error ||= $contact->change_password($p->{'new_password'});
 
@@ -82,7 +79,7 @@ sub list_contacts {
       #TODO: contact phone numbers
       'comment'            => $_->comment,
       'selfservice_access' => $_->selfservice_access,
-      'disabled'           => $contact->disabled,
+      #'disabled'           => $contact->disabled,
     };
   } $cust_main->cust_contact );
 
@@ -141,11 +138,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;