summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/User.pm
blob: 62ae4e0b1c509d6eac9e910c0680f7e6a5a0269e (plain)
  1. package LedgerSMB::DBObject::User;
  2. use base qw/LedgerSMB::DBObject/;
  3. sub save {
  4. my $self = shift @_;
  5. my $user = $self->get();
  6. if ($user->{id} && $self->{is_a_user}) {
  7. # doesn't check for the password - that's done in the sproc.
  8. $self->{id} = @{ $self->exec_method(procname=>'admin_save_user',
  9. args=>[$user->{id}, $self->{username}, $self->{password}] ) }[0];
  10. else {
  11. return 0;
  12. }
  13. }
  14. elsif ($user && !$self->{is_a_user}) {
  15. # there WAS a user, and we've decided we want that user to go away now.
  16. $self->{id} = $user->{id};
  17. return $self->remove();
  18. }
  19. return 1;
  20. }
  21. sub get {
  22. my $self = shift @_;
  23. my ($user_id, $username) = @{ $self->exec_method(procname=>'admin_get_user',
  24. args=>[$self->{id}])};
  25. return {id=>$user_id, username=>$username};
  26. }
  27. sub remove {
  28. my $self = shift;
  29. my $code = $self->exec_method(procname=>"admin_delete_user", args=>[$self->{id}, $self->{username}]);
  30. $self->{id} = undef; # never existed..
  31. return $code->[0];
  32. }
  33. 1;