summaryrefslogtreecommitdiff
path: root/FS/FS/ClientAPI/passwd.pm
blob: 29606227d33c8105146ac9692be1da8c4dd1e8c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package FS::ClientAPI::passwd;

use strict;
use FS::Record qw(qsearchs);
use FS::svc_acct;
#use FS::svc_domain;

use FS::ClientAPI; #hmm
FS::ClientAPI->register_handlers(
  'passwd/passwd' => \&passwd,
  'passwd/chfn' => \&chfn,
  'passwd/chsh' => \&chsh,
);

sub passwd {
  my $packet = shift;

  #my $domain = qsearchs('svc_domain', { 'domain' => $packet->{'domain'} } )
  #  or return { error => "Domain $domain not found" };

  my $old_password = $packet->{'old_password'};
  my $new_password = $packet->{'new_password'};
  my $new_gecos = $packet->{'new_gecos'};
  my $new_shell = $packet->{'new_shell'};

#false laziness w/FS::ClientAPI::MyAccount::login (needs to handle encrypted pw)
  my $svc_acct =
    ( length($old_password) < 13
      && qsearchs( 'svc_acct', { 'username'  => $packet->{'username'},
                                 #'domsvc'    => $svc_domain->svcnum,
                                 '_password' => $old_password } )
    )
    || qsearchs( 'svc_acct', { 'username'  => $packet->{'username'},
                               #'domsvc'    => $svc_domain->svcnum,
                               '_password' => $old_password } );

  unless ( $svc_acct ) { return { error => 'Incorrect password.' } }

  my %hash = $svc_acct->hash;
  my $new_svc_acct = new FS::svc_acct ( \%hash );
  $new_svc_acct->setfield('_password', $new_password ) 
    if $new_password && $new_password ne $old_password;
  $new_svc_acct->setfield('finger',$new_gecos) if $new_gecos;
  $new_svc_acct->setfield('shell',$new_shell) if $new_shell;
  my $error = $new_svc_acct->replace($svc_acct);

  return { error => $error };

}

sub chfn {}

sub chsh {}

1;