summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/User.pm
blob: 3486fbd69405a9e606b97046b5bcda8c3b19ad48 (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} = shift @{ $self->exec_method(procname=>'admin_save_user',
  9. args=>[$user->{id}, $self->{username}, $self->{password}] ) };
  10. if (!$self->{id}) {
  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. elsif ($self->{is_a_user}) {
  20. # No user ID, meaning, creating a new one.
  21. $self->{id} = shift @{ $self->exec_method(procname=>'admin_save_user',
  22. args=>[undef, $self->{username}, $self->{password}] ) };
  23. }
  24. return 1;
  25. }
  26. sub get {
  27. my $self = shift @_;
  28. my ($user_id, $username) = @{ $self->exec_method(procname=>'admin_get_user',
  29. args=>[$self->{id}])};
  30. return {id=>$user_id, username=>$username};
  31. }
  32. sub remove {
  33. my $self = shift;
  34. my $code = $self->exec_method(procname=>"admin_delete_user", args=>[$self->{id}, $self->{username}]);
  35. $self->{id} = undef; # never existed..
  36. return $code->[0];
  37. }
  38. sub save_prefs {
  39. my $self = shift @_;
  40. my $pref_id = $self->exec_method(procname=>"admin_save_preferences",
  41. args=>[
  42. 'language',
  43. 'stylesheet',
  44. 'printer',
  45. 'dateformat',
  46. 'numberformat'
  47. ]
  48. );
  49. }
  50. sub get_all_users {
  51. my $self = shift @_;
  52. $self->{users} = $self->exec_method( procname=>"user_get_all_users" );
  53. }
  54. 1;