ClientAPI
[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 use FS::ClientAPI; #hmm
9 FS::ClientAPI->register_handlers(
10   'passwd/passwd' => \&passwd,
11   'passwd/chfn' => \&chfn,
12   'passwd/chsh' => \&chsh,
13 );
14
15 sub passwd {
16   my $packet = shift;
17
18   #my $domain = qsearchs('svc_domain', { 'domain' => $packet->{'domain'} } )
19   #  or return { error => "Domain $domain not found" };
20
21   my $old_password = $packet->{'old_password'};
22   my $new_password = $packet->{'new_password'};
23   my $new_gecos = $packet->{'new_gecos'};
24   my $new_shell = $packet->{'new_shell'};
25
26 #false laziness w/FS::ClientAPI::MyAccount::login (needs to handle encrypted pw)
27   my $svc_acct =
28     ( length($old_password) < 13
29       && qsearchs( 'svc_acct', { 'username'  => $packet->{'username'},
30                                  #'domsvc'    => $svc_domain->svcnum,
31                                  '_password' => $old_password } )
32     )
33     || qsearchs( 'svc_acct', { 'username'  => $packet->{'username'},
34                                #'domsvc'    => $svc_domain->svcnum,
35                                '_password' => $old_password } );
36
37   unless ( $svc_acct ) { return { error => 'Incorrect password.' } }
38
39   my %hash = $svc_acct->hash;
40   my $new_svc_acct = new FS::svc_acct ( \%hash );
41   $new_svc_acct->setfield('_password', $new_password ) 
42     if $new_password && $new_password ne $old_password;
43   $new_svc_acct->setfield('finger',$new_gecos) if $new_gecos;
44   $new_svc_acct->setfield('shell',$new_shell) if $new_shell;
45   my $error = $new_svc_acct->replace($svc_acct);
46
47   return { error => $error };
48
49 }
50
51 sub chfn {}
52
53 sub chsh {}
54
55 1;
56