contact self-service pw changes, RT#37023
[freeside.git] / FS / FS / ClientAPI / passwd.pm
1 package FS::ClientAPI::passwd;
2
3 use strict;
4 use FS::Record qw(qsearchs);
5 use FS::svc_acct;
6 use FS::svc_domain;
7
8 sub passwd {
9   my $packet = shift;
10
11   my $domain = $FS::ClientAPI::domain || $packet->{'domain'};
12   my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } )
13     or return { error => "Domain $domain not found" };
14
15   my $old_password = $packet->{'old_password'};
16   my $new_password = $packet->{'new_password'};
17   my $new_gecos = $packet->{'new_gecos'};
18   my $new_shell = $packet->{'new_shell'};
19
20   #false laziness w/FS::ClientAPI::MyAccount::login
21
22   my $svc_acct = qsearchs( 'svc_acct', { 'username'  => $packet->{'username'},
23                                          'domsvc'    => $svc_domain->svcnum, }
24                          );
25   return { error => 'User not found.' } unless $svc_acct;
26
27   my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
28   return { error => "Can't change password for a suspended service" }
29     if $cust_pkg && $cust_pkg->status eq 'suspended';
30
31   return { error => 'Incorrect password.' }
32     unless $svc_acct->check_password($old_password);
33
34   my %hash = $svc_acct->hash;
35   my $new_svc_acct = new FS::svc_acct ( \%hash );
36   $new_svc_acct->setfield('_password', $new_password ) 
37     if $new_password && $new_password ne $old_password;
38   $new_svc_acct->setfield('finger',$new_gecos) if $new_gecos;
39   $new_svc_acct->setfield('shell',$new_shell) if $new_shell;
40   my $error = $new_svc_acct->replace($svc_acct);
41
42   return { error => $error };
43
44 }
45
46 sub chfn {}
47
48 sub chsh {}
49
50 1;
51