diff options
author | 3dB <3db@3decibels.net> | 2009-07-27 20:17:58 -0400 |
---|---|---|
committer | 3dB <3db@3decibels.net> | 2009-07-27 20:17:58 -0400 |
commit | b0eb9d6fa3d3d11e4218f98cb78d13acc8cf962d (patch) | |
tree | f2b02d2a857c4e7c4751758528ae5008bbd358af /lib/VNDB | |
parent | a1fc2a9a103e0f426ac4e496200408a2deccaaf0 (diff) |
Applied small adjustments and reorganized DB library code.
-- Removed "ON UPDATE" from sessions.uid column FK
-- Fixed dbSessionCheck to work as described
-- Merged DB/Sessions.pm into DB/Users.pm
Diffstat (limited to 'lib/VNDB')
-rw-r--r-- | lib/VNDB/DB/Sessions.pm | 43 | ||||
-rw-r--r-- | lib/VNDB/DB/Users.pm | 34 |
2 files changed, 33 insertions, 44 deletions
diff --git a/lib/VNDB/DB/Sessions.pm b/lib/VNDB/DB/Sessions.pm deleted file mode 100644 index 031c5ac3..00000000 --- a/lib/VNDB/DB/Sessions.pm +++ /dev/null @@ -1,43 +0,0 @@ - -package VNDB::DB::Sessions; - -use strict; -use warnings; -use Exporter 'import'; - -our @EXPORT = qw| dbSessionAdd dbSessionDel dbSessionCheck |; - - -# uid, 40 character session token, expiration time (int) -sub dbSessionAdd { - my($s, @o) = @_; - $s->dbExec(q|INSERT INTO sessions (uid, token, expiration) VALUES(?, ?, ?)|, - @o[0..2]); -} - - -# Deletes session(s) from the database -# If no token is supplied, all sessions for the uid are destroyed -# uid, token (optional) -sub dbSessionDel { - my($s, @o) = @_; - if (defined $o[1]) { - $s->dbExec(q|DELETE FROM sessions WHERE uid = ? AND token = ?|, - @o[0..1]); - } else { - $s->dbExec(q|DELETE FROM sessions WHERE uid = ?|, - $o[0]); - } -} - - -# Queries the database for the validity of a session -# Returns 1 if corresponding session found, 0 if not -# uid, token -sub dbSessionCheck { - my($s, @o) = @_; - return $s->dbRow(q|SELECT count(uid) AS count FROM sessions WHERE uid = ? AND token = ? LIMIT 1|, @o); -} - - -1; diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm index d5cdcc6c..1ea8daf5 100644 --- a/lib/VNDB/DB/Users.pm +++ b/lib/VNDB/DB/Users.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Exporter 'import'; -our @EXPORT = qw|dbUserGet dbUserEdit dbUserAdd dbUserDel|; +our @EXPORT = qw|dbUserGet dbUserEdit dbUserAdd dbUserDel dbSessionAdd dbSessionDel dbSessionCheck|; # %options->{ username passwd mail order uid ip registered search results page what } @@ -111,4 +111,36 @@ sub dbUserDel { } +# uid, 40 character session token, expiration time (int) +sub dbSessionAdd { + my($s, @o) = @_; + $s->dbExec(q|INSERT INTO sessions (uid, token, expiration) VALUES(?, ?, ?)|, + @o[0..2]); +} + + +# Deletes session(s) from the database +# If no token is supplied, all sessions for the uid are destroyed +# uid, token (optional) +sub dbSessionDel { + my($s, @o) = @_; + if (defined $o[1]) { + $s->dbExec(q|DELETE FROM sessions WHERE uid = ? AND token = ?|, + @o[0..1]); + } else { + $s->dbExec(q|DELETE FROM sessions WHERE uid = ?|, + $o[0]); + } +} + + +# Queries the database for the validity of a session +# Returns 1 if corresponding session found, 0 if not +# uid, token +sub dbSessionCheck { + my($s, @o) = @_; + return $s->dbRow(q|SELECT count(uid) AS count FROM sessions WHERE uid = ? AND token = ? LIMIT 1|, @o)->{count}||0; +} + + 1; |