diff options
author | Yorhel <git@yorhel.nl> | 2008-10-31 12:04:08 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2008-10-31 12:04:08 +0100 |
commit | d5bc5cf2169116a9a4b30377ef2e28603fc4e3ea (patch) | |
tree | c79c61fbee5376ef9919e3ea671680ab0afa5e29 /lib/VNDB/DB | |
parent | f266cd214111a1c71f705edbc9243d8625693003 (diff) |
Added some authentication and user functions
Diffstat (limited to 'lib/VNDB/DB')
-rw-r--r-- | lib/VNDB/DB/Misc.pm | 1 | ||||
-rw-r--r-- | lib/VNDB/DB/Users.pm | 44 |
2 files changed, 45 insertions, 0 deletions
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm index 50a12a4b..61b1223c 100644 --- a/lib/VNDB/DB/Misc.pm +++ b/lib/VNDB/DB/Misc.pm @@ -13,6 +13,7 @@ our @EXPORT = qw| # Arguments: array of elements to get stats from, options: # vn, producers, releases, users, threads, posts # Returns: hashref, key = element, value = number of entries +# TODO: caching, see http://www.varlena.com/GeneralBits/120.php sub dbStats { my $s = shift; return { map { diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm new file mode 100644 index 00000000..9e83ea2b --- /dev/null +++ b/lib/VNDB/DB/Users.pm @@ -0,0 +1,44 @@ + +package VNDB::DB::Users; + +use Exporter 'import'; + +our @EXPORT = 'dbUserGet'; + + +# %options->{ username passwd order uid results page } +sub dbUserGet { + my $s = shift; + my %o = ( + order => 'username ASC', + page => 1, + results => 10, + what => '', + @_ + ); + + my %where = ( + $o{username} ? ( + 'username = ?' => $o{username} ) : (), + $o{passwd} ? ( + 'passwd = decode(?, \'hex\')' => $o{passwd} ) : (), + $o{uid} ? ( + 'id = ?' => $o{uid} ) : (), + !$o{uid} && !$o{username} ? ( + 'id > 0' => 1 ) : (), + ); + + my($r, $np) = $s->dbPage(\%o, q| + SELECT * + FROM users u + !W + ORDER BY !s|, + \%where, + $o{order} + ); + + return wantarray ? ($r, $np) : $r; +} + + +1; |