From d340ccd5ecbb731c273a07876ad0dfc0a9b33379 Mon Sep 17 00:00:00 2001 From: aurynn_cmd Date: Thu, 15 Nov 2007 23:10:31 +0000 Subject: Significant work on the Entity and Administrative code. It's buggy, so please test, etc. thoroughly. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1869 4979c152-3d1c-0410-bac9-87ea11338e46 --- scripts/admin.pl | 10 +++++--- scripts/customer.pl | 68 +++++++++++++++++++++++++++++++++++++++-------------- scripts/login.pl | 45 +++++++++++++++++++++++++++++++---- 3 files changed, 97 insertions(+), 26 deletions(-) (limited to 'scripts') diff --git a/scripts/admin.pl b/scripts/admin.pl index 18fb0ca8..2b8ca816 100644 --- a/scripts/admin.pl +++ b/scripts/admin.pl @@ -5,6 +5,7 @@ require 'lsmb-request.pl'; use LedgerSMB::Template; use LedgerSMB::DBObject::Admin; +use LedgerSMB::DBObject::User; sub new_user { @@ -23,7 +24,7 @@ sub new_user { my $template = LedgerSMB::Template->new( user => $user, - template => 'Admin/edit_user', language => $user->{language}, + template => 'Admin/edit_user', language => $user->{ language }, format => 'HTML', path=>'UI'); $template->render( @@ -153,11 +154,14 @@ sub __default { my ($class, $request) = @_; - # TODO: check for login stuff. my $template; + my $user = LedgerSMB::DBObject::User->new(base=>$request, copy=>'all'); + + $user->get_all_users(); + $template = LedgerSMB::Template->new( user=>$user, template=>'Admin/main', language=>$user->{language}, format=>'HTML', path=>'UI'); - $template->render(); + $template->render($user); } 1; \ No newline at end of file diff --git a/scripts/customer.pl b/scripts/customer.pl index 24fb04f6..7fc238da 100644 --- a/scripts/customer.pl +++ b/scripts/customer.pl @@ -44,11 +44,13 @@ of the customer informations. sub get { my ($request) = @_; - my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all'); - my $result = $customer->get($customer->{id}); + my $customer = LedgerSMB::DBObject::Company->new(base => $request, copy => 'all'); + + $customer->set( entity_class=> '2' ); + my $result = $customer->get(); my $template = LedgerSMB::Template->new( user => $user, - template => 'customer.html', language => $user->{language}, + template => 'Customer/customer.html', language => $user->{language}, format => 'html'); $template->render($results); @@ -68,10 +70,10 @@ This method creates a blank screen for entering a customer's information. sub add { my ($request) = @_; - my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all'); - + my $customer = LedgerSMB::DBObject::Company->new(base => $request, copy => 'all'); + $customer->set(entity_class=>2); my $template = LedgerSMB::Template->new( user => $user, - template => 'customer.html', language => $user->{language}, + template => 'Customer/customer.html', language => $user->{language}, format => 'html'); $template->render($results); } @@ -94,13 +96,30 @@ as well as customer/Company name. sub search { my ($request) = @_; - my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all'); - my $results = $customer->search($customer->{search_pattern}); - my $template = LedgerSMB::Template->new( user => $user, - template => 'customer_search.html', language => $user->{language}, - format => 'html'); - $template->render($results); + if ($request->type() eq 'POST') { + # assume it's asking us to do the search, now + + my $customer = LedgerSMB::DBObject::Company->new(base => $request, copy => 'all'); + $customer->set(entity_class=>2); + my $results = $customer->search($customer->{search_pattern}); + + my $template = LedgerSMB::Template->new( user => $user, + template => 'Customer/customer.html', language => $user->{language}, + format => 'html'); + $template->render($results); + + } + else { + + # grab the happy search page out. + + my $template = LedgerSMB::Template->new( user => $user, + template => 'Customer/customer_search.html', language => $user->{language}, + format => 'html'); + + $template->render(); + } } =pod @@ -119,13 +138,26 @@ customer as needed, and will generate a new Company ID for the customer if neede sub save { my ($request) = @_; - my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all'); - my $result = $customer->save_to_db(); - my $template = LedgerSMB::Template->new( user => $user, - template => 'customer.html', language => $user->{language}, - format => 'html'); - $template->render($result); + if ($request->type() == 'POST') { + + my $customer = LedgerSMB::DBObject::Customer->get(base=>$request, copy=>'all'); + + unless ($customer) { + + $customer = LedgerSMB::DBObject::Customer->new(base=>$reqest, copy=>'all'); + } + + my $result = $customer->save(); + + my $template = LedgerSMB::Template->new( user => $user, + template => 'Customer/customer.html', language => $user->{language}, + format => 'html'); + $template->render($result); + } + else { + + } } 1; diff --git a/scripts/login.pl b/scripts/login.pl index 1ce79587..537d8b61 100644 --- a/scripts/login.pl +++ b/scripts/login.pl @@ -7,13 +7,18 @@ use LedgerSMB::User; use LedgerSMB::Auth; use strict; +# this is kind of silly, as it doesn't check if someone IS trying to log in. +# If one looks at the login template (get_password.html), it does not post +# to any action, so this code will always get called, thereby preventing +# anyone from actually logging in. + sub __default { my ($request) = @_; my $locale; $locale = LedgerSMB::Locale->get_handle(${LedgerSMB::Sysconfig::language}) or $request->error( __FILE__ . ':' . __LINE__ . - ": Locale not loaded: $!\n" ); - my $template = LedgerSMB::Template->new( + ": Locale not loaded: $!\n" ); + my $template = LedgerSMB::Template->new( user =>$request->{_user}, locale => $locale, path => 'UI', @@ -23,6 +28,8 @@ sub __default { $template->render($request); } +# Directly printing like this is made of fail. + sub authenticate { my ($request) = @_; if (!$request->{dbh}){ @@ -33,10 +40,20 @@ sub authenticate { } my $path = $ENV{SCRIPT_NAME}; $path =~ s|[^/]*$||; - if ($request->{dbh} || $request->{log_out}){ + + if ($request->{dbh} && $request->{next}) { + + print "Content-Type: text/html\n"; + print "Set-Cookie: LedgerSMB=Login; path=$path\n"; + print "Status: 302 Found\n"; + print "Location: ".$path.$request->{next}."\n"; + print "\n"; + exit; + } + elsif ($request->{dbh} || $request->{log_out}){ print "Content-Type: text/html\n"; print "Set-Cookie: LedgerSMB=Login; path=$path\n"; - print "Status: 200 Success\n\n"; + print "Status: 200 Success\n\n"; if ($request->{log_out}){ exit; } @@ -44,7 +61,7 @@ sub authenticate { else { print "WWW-Authenticate: Basic realm=\"LedgerSMB\"\n"; print "Status: 401 Unauthorized\n\n"; - print "Please enter your credentials.\n"; + print "Please enter your credentials.\n"; exit; } } @@ -69,5 +86,23 @@ sub logout { print "Content-type: text/html\n\n"; exit; } + +sub continue { + + my ($request) = @_; + + if ($request->{next} && $request->{password}) { + + $request->{user} = "admin"; + + if (&authenticate($request)) { +# LedgerSMB::Handler::call_script(); + } + } + else { + # well, wtf? This is kind of useless. + $request->error("Cannot continue to a Nonexistent page."); + } +} 1; -- cgit v1.2.3