[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[4990] trunk



Revision: 4990
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4990&view=rev
Author:   einhverfr
Date:     2012-07-14 14:17:56 +0000 (Sat, 14 Jul 2012)
Log Message:
-----------
Bringing back inactity-based logouts
Also refactoring trial balance code

Modified Paths:
--------------
    trunk/Changelog
    trunk/LedgerSMB/Session.pm
    trunk/LedgerSMB.pm
    trunk/UI/logout.html
    trunk/bin/pw.pl
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Fixes.sql
    trunk/sql/modules/Session.sql
    trunk/sql/modules/trial_balance.sql

Modified: trunk/Changelog
===================================================================
--- trunk/Changelog	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/Changelog	2012-07-14 14:17:56 UTC (rev 4990)
@@ -23,6 +23,7 @@
 * Added file attachments to parts (Chris T)
 * Added file attachments to customers, vendors, employees, leads etc (Chris T)
 * LaTeX format detection now run-time call, not configured (Chris T)
+* Bringing back inactivity-based logouts (Chris T)
 
 New RESTful Web Services Framework
 * Supports XML and JSON as input formats

Modified: trunk/LedgerSMB/Session.pm
===================================================================
--- trunk/LedgerSMB/Session.pm	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/LedgerSMB/Session.pm	2012-07-14 14:17:56 UTC (rev 4990)
@@ -67,13 +67,14 @@
     $checkQuery->execute( $sessionID, $token)
       || $form->dberror(
         __FILE__ . ':' . __LINE__ . ': Looking for session: ' );
-    my $sessionValid = $checkQuery->rows;
+    my $sessionValid = $checkQuery->fetchrow_hashref('NAME_lc');
+    my ($session_ref) = $sessionValid;
+    $sessionValid = $sessionValid->{session_id};
     $dbh->commit;
 
     if ($sessionValid) {
+       
 
-        #user has a valid session cookie, now check the user
-        my ( $session_ref) =  $checkQuery->fetchrow_hashref('NAME_lc');
 
         my $login = $form->{login};
 
@@ -97,13 +98,6 @@
         }
         else {
 
-            my $sessionDestroy = $dbh->prepare("");
-
-            #delete the cookie in the browser
-            if ($ENV{SERVER_PORT} == 443){
-                 $secure = ' Secure;';
-            }
-            print qq|Set-Cookie: ${LedgerSMB::Sysconfig::cookie_name}=; path=$path;$secure\n|;
             return 0;
         }
 

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/LedgerSMB.pm	2012-07-14 14:17:56 UTC (rev 4990)
@@ -443,7 +443,12 @@
 sub _get_password {
     my ($self) = shift @_;
     $self->{sessionexpired} = shift @_;
-    LedgerSMB::Auth::credential_prompt();
+    if ($self->{sessionexpired}){
+        my $q = new CGI::Simple;
+        print $q->redirect('login.pl?action=logout&reason=timeout');
+    } else {
+        LedgerSMB::Auth::credential_prompt();
+    }
     exit;
 }
 

Modified: trunk/UI/logout.html
===================================================================
--- trunk/UI/logout.html	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/UI/logout.html	2012-07-14 14:17:56 UTC (rev 4990)
@@ -1,7 +1,12 @@
 <?lsmb INCLUDE 'ui-header.html' include_script = scripts ?> 
 <?lsmb PROCESS elements.html ?> 
 <body>
-<h1 class="info"><?lsmb text('Logout Successful')?></h1>
-<p><a href="login.pl"><?lsmb text('Return to the login screen.') ?></a>
+<h1 class="info">
+   <?lsmb IF reason == 'timeout';
+            text('Logged out due to inactivity');
+          ELSE;
+            text('Logout Successful');
+          END; ?></h1>
+<p><a href="login.pl" target='top'><?lsmb text('Return to the login screen.') ?></a>
 </body>
 </html>

Modified: trunk/bin/pw.pl
===================================================================
--- trunk/bin/pw.pl	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/bin/pw.pl	2012-07-14 14:17:56 UTC (rev 4990)
@@ -34,31 +34,14 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 #======================================================================
 
-use LedgerSMB::Template;
+use CGI::Simple;
 
 1;
 
 # end of main
 
 sub getpassword {
-    $form->{sessionexpired} = shift @_;
-    @{$form->{hidden}};
-    for (keys %$form){
-        next if $_ =~ /(^script$|^endsession$|^password$)/;
-        my $attr = {};
-        $attr->{name} = $_;
-        $attr->{value} = $form->{$_};
-        push @{$form->{hidden}}, $attr;
-    }
-    my $template = LedgerSMB::Template->new(
-        user => \%myconfig, 
-        locale => $locale,
-        path => 'UI',
-        template => 'get_password',
-        format => 'HTML'
-    );
-    $template->render($form);
-    $template->output('http');
-    $form->finalize_request();
+    my $q = new CGI::Simple;
+    print $q->redirect('login.pl?action=logout&reason=timeout');
 }
 

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/sql/Pg-database.sql	2012-07-14 14:17:56 UTC (rev 4990)
@@ -4708,5 +4708,40 @@
  This reasoning is hacky and i hope it can dissapear when we get to 1.4 - D.M.
 $$;
 
+CREATE TABLE trial_balance__yearend_types (
+    type text primary key
+);
+INSERT INTO trial_balance__yearend_types (type) 
+     VALUES ('none'), ('all'), ('last');
+
+
+CREATE TABLE trial_balance (
+    id serial primary key,
+    date_from date, 
+    date_to date,
+    description text NOT NULL,
+    yearend text not null references trial_balance__yearend_types(type)
+);
+
+CREATE TABLE trial_balance__account_to_report (
+    report_id int not null references trial_balance(id),
+    account_id int not null references account(id)
+);
+
+CREATE TABLE trial_balance__heading_to_report (
+    report_id int not null references trial_balance(id),
+    heading_id int not null references account_heading(id)
+);
+
+CREATE TYPE trial_balance__entry AS (
+    id int,
+    date_from date,
+    date_to date,
+    description text,
+    yearend text,
+    heading_id int,
+    accounts int[]
+);
+
 ALTER TABLE cr_report_line ADD FOREIGN KEY(ledger_id) REFERENCES acc_trans(entry_id);
 commit;

Modified: trunk/sql/modules/Fixes.sql
===================================================================
--- trunk/sql/modules/Fixes.sql	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/sql/modules/Fixes.sql	2012-07-14 14:17:56 UTC (rev 4990)
@@ -27,3 +27,45 @@
 );
 
 COMMIT;
+
+BEGIN;
+CREATE TABLE trial_balance__yearend_types (
+    type text primary key
+);
+INSERT INTO trial_balance__yearend_types (type) 
+     VALUES ('none'), ('all'), ('last');
+
+
+CREATE TABLE trial_balance (
+    id serial primary key,
+    date_from date, 
+    date_to date,
+    description text NOT NULL,
+    yearend text not null references trial_balance__yearend_types(type)
+);
+
+CREATE TABLE trial_balance__account_to_report (
+    report_id int not null references trial_balance(id),
+    account_id int not null references account(id)
+);
+
+CREATE TABLE trial_balance__heading_to_report (
+    report_id int not null references trial_balance(id),
+    heading_id int not null references account_heading(id)
+);
+
+CREATE TYPE trial_balance__entry AS (
+    id int,
+    date_from date,
+    date_to date,
+    description text,
+    yearend text,
+    heading_id int,
+    accounts int[]
+);
+
+ALTER TABLE cr_report_line ADD FOREIGN KEY(ledger_id) REFERENCES acc_trans(entry_id);
+
+COMMIT;
+
+

Modified: trunk/sql/modules/Session.sql
===================================================================
--- trunk/sql/modules/Session.sql	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/sql/modules/Session.sql	2012-07-14 14:17:56 UTC (rev 4990)
@@ -117,28 +117,14 @@
 		-- the above query also releases all discretionary locks by the
                 -- session
 
-		IF NOT FOUND THEN
-			PERFORM id FROM users WHERE username = SESSION_USER;
-			IF NOT FOUND THEN
-				RAISE EXCEPTION 'User Not Known';
-			END IF;
-			
-		END IF;
-		INSERT INTO session(users_id, token, last_used)
-		SELECT id, md5(random()::text), now()
-		  FROM users WHERE username = SESSION_USER;
-
-		SELECT * INTO out_row FROM session 
-		 WHERE session_id = currval('session_session_id_seq');
+                RETURN NULL;
 	END IF;
 	RETURN out_row;
 END;
 $$ LANGUAGE PLPGSQL;
 
 COMMENT ON FUNCTION session_check(int, text) IS 
-$$ Returns a session row.  If no session exists, creates one.
-The row returned is the current, active session.
- $$;
+$$ Returns a session row.  If no session exists, it returns null$$;
 
 CREATE OR REPLACE FUNCTION unlock_all() RETURNS BOOL AS
 $$

Modified: trunk/sql/modules/trial_balance.sql
===================================================================
--- trunk/sql/modules/trial_balance.sql	2012-07-14 13:01:26 UTC (rev 4989)
+++ trunk/sql/modules/trial_balance.sql	2012-07-14 14:17:56 UTC (rev 4990)
@@ -143,43 +143,7 @@
 $$ language plpgsql;
 
 
-CREATE TABLE trial_balance__yearend_types (
-    type text primary key
-);
-INSERT INTO trial_balance__yearend_types (type) VALUES ('none');
-INSERT INTO trial_balance__yearend_types (type) VALUES ('all');
-INSERT INTO trial_balance__yearend_types (type) VALUES ('last');
 
-
-CREATE TABLE trial_balance (
-    id serial primary key,
-    date_from date, 
-    date_to date,
-    description text NOT NULL,
-    yearend text not null references trial_balance__yearend_types(type)
-);
-
-CREATE TABLE trial_balance__account_to_report (
-    report_id int not null references trial_balance(id),
-    account_id int not null references account(id)
-);
-
-CREATE TABLE trial_balance__heading_to_report (
-    report_id int not null references trial_balance(id),
-    heading_id int not null references account_heading(id)
-);
-
-CREATE TYPE trial_balance__entry AS (
-    id int,
-    date_from date,
-    date_to date,
-    description text,
-    yearend text,
-    heading_id int,
-    accounts int[]
-);
-
-
 CREATE OR REPLACE FUNCTION trial_balance__get (
     in_report_id int
 ) RETURNS trial_balance__entry AS $body$

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.