summaryrefslogtreecommitdiff
path: root/scripts/login.pl
blob: b07d9c3d72b1c425fa657b898e0ebac1573fd835 (plain)
  1. #!/usr/bin/perl
  2. package LedgerSMB::Scripts::login;
  3. our $VERSION = 0.1;
  4. use LedgerSMB::Locale;
  5. use LedgerSMB::Form; # Required for now to integrate with menu module.
  6. use LedgerSMB::User;
  7. use strict;
  8. sub __default {
  9. my ($request) = @_;
  10. my $locale;
  11. $locale = LedgerSMB::Locale->get_handle(${LedgerSMB::Sysconfig::language})
  12. or $request->error( __FILE__ . ':' . __LINE__ .
  13. ": Locale not loaded: $!\n" );
  14. my $template = LedgerSMB::Template->new(
  15. user =>$request->{_user},
  16. locale => $locale,
  17. path => 'UI',
  18. template => 'login',
  19. format => 'HTML'
  20. );
  21. $template->render($request);
  22. }
  23. sub login {
  24. my ($request) = @_;
  25. if (!$request->{_user}){
  26. __default($request);
  27. }
  28. our $user = new LedgerSMB::User($request->{login});
  29. our $form = new Form;
  30. for (keys %$request){
  31. $form->{$_} = $request->{$_};
  32. }
  33. my $menu_entrypoint;
  34. require "bin/menu.pl";
  35. if (($request->{_user}->{acs} !~ /Recurring Transactions/) ||
  36. $request->{_user}->{role} ne 'user'){
  37. if ($user->check_recurring($form) ) {
  38. $form->{main} = "recurring_transactions";
  39. }
  40. else {
  41. $form->{main} = "company_logo";
  42. }
  43. }
  44. else {
  45. $form->{main} = "company_logo";
  46. }
  47. &display;
  48. }
  49. sub logout {
  50. my ($request) = @_;
  51. $request->{callback} = "";
  52. $request->{endsession} = 1;
  53. Session::session_destroy($request);
  54. print "Location: login.pl\n";
  55. print "Content-type: text/html\n\n";
  56. exit;
  57. }
  58. 1;