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

SF.net SVN: ledger-smb:[5058] trunk/sql/modules/Session.sql



Revision: 5058
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5058&view=rev
Author:   einhverfr
Date:     2012-07-29 11:26:40 +0000 (Sun, 29 Jul 2012)
Log Message:
-----------
Session timeout and autologout settings now respected

Modified Paths:
--------------
    trunk/sql/modules/Session.sql

Modified: trunk/sql/modules/Session.sql
===================================================================
--- trunk/sql/modules/Session.sql	2012-07-29 10:23:48 UTC (rev 5057)
+++ trunk/sql/modules/Session.sql	2012-07-29 11:26:40 UTC (rev 5058)
@@ -98,14 +98,12 @@
 BEGIN
 	DELETE FROM session
 	 WHERE last_used < now() - coalesce((SELECT value FROM defaults
-                                    WHERE setting_key = 'timeout')::interval,
+                                    WHERE setting_key = 'session_timeout')::interval,
 	                            '90 minutes'::interval);
         UPDATE session 
            SET last_used = now()
          WHERE session_id = in_session_id
                AND token = in_token
-               AND last_used > now() - (SELECT value FROM defaults
-				WHERE setting_key = 'timeout')::interval
 	       AND users_id = (select id from users 
 			where username = SESSION_USER);
 	IF FOUND THEN
@@ -117,7 +115,24 @@
 		-- the above query also releases all discretionary locks by the
                 -- session
 
-                RETURN NULL;
+               PERFORM * 
+                  FROM defaults
+                 WHERE setting_key = 'auto_logout' and value = '1';
+
+                IF FOUND THEN
+                    RAISE NOTICE 'auto logout';
+                    RETURN NULL;
+                ELSE
+                    INSERT INTO session (users_id, token)
+                    SELECT id, md5(random()::text)
+                      FROM users 
+                     WHERE username = SESSION_USER;
+
+                    SELECT * INTO out_row FROM SESSION 
+                     WHERE users_id = (select id from users
+                                             where username = SESSION_USER);
+                    RETURN out_row;
+               END IF;
 	END IF;
 	RETURN out_row;
 END;

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