From b3a9130763879d60c0e413c724a759860bd396af Mon Sep 17 00:00:00 2001 From: Yorhel Date: Tue, 8 Oct 2019 18:16:46 +0200 Subject: rewards: Apply supporters badge and unicode name (almost) everywhere Only place where this isn't applied (yet?): Sorting user lists still goes by the old username and board names don't use the new unicode names. I have to say, I quite like the sql_user() and user_() pattern. It's not without problems when applied to everything, but it's good enough for several use cases. --- lib/VNWeb/Auth.pm | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lib/VNWeb/Auth.pm') diff --git a/lib/VNWeb/Auth.pm b/lib/VNWeb/Auth.pm index 7143f203..bd1fba49 100644 --- a/lib/VNWeb/Auth.pm +++ b/lib/VNWeb/Auth.pm @@ -11,7 +11,6 @@ # auth->logout; # # my $uid = auth->uid; -# my $username = auth->username; # my $wants_spoilers = auth->pref('spoilers'); # ..etc # @@ -56,17 +55,17 @@ TUWF::hook after => sub { $auth = __PACKAGE__->new() }; # have a lot of influence in this) TUWF::set log_format => sub { my(undef, $uri, $msg) = @_; - sprintf "[%s] %s %s: %s\n", scalar localtime(), $uri, auth ? auth->uid : '-', $msg; + sprintf "[%s] %s %s: %s\n", scalar localtime(), $uri, auth ? 'u'.auth->uid : '-', $msg; }; -use overload bool => sub { defined shift->{uid} }; +use overload bool => sub { defined shift->{user}{user_id} }; -sub uid { shift->{uid} } -sub username { shift->{username} } -sub perm { shift->{perm}||0 } -sub token { shift->{token} } +sub uid { shift->{user}{user_id} } +sub perm { shift->{user}{perm}||0 } +sub user { shift->{user} } +sub token { shift->{token} } @@ -150,18 +149,16 @@ sub _load_session { my($self, $uid, $token_db) = @_; my $user = $uid ? tuwf->dbRowi( - 'SELECT id, username, perm FROM users + 'SELECT perm, ', sql_user(), ' FROM users u WHERE id = ', \$uid, 'AND', sql_func(user_isvalidsession => 'id', sql_fromhex($token_db), \'web') ) : {}; # Drop the cookie if it's not valid - tuwf->resCookie(auth => undef) if !$user->{id} && tuwf->reqCookie('auth'); + tuwf->resCookie(auth => undef) if !$user->{user_id} && tuwf->reqCookie('auth'); - $self->{uid} = $user->{id}; - $self->{username} = $user->{username}; - $self->{perm} = $user->{perm}||0; - $self->{token} = $token_db; + $self->{user} = $user; + $self->{token} = $token_db; delete $self->{pref}; } @@ -279,7 +276,7 @@ sub csrfcheck { my @pref_columns = qw/ email_confirmed skin customcss filter_vn filter_release show_nsfw hide_list notify_dbedit notify_announce - vn_list_own vn_list_wish tags_all tags_cont tags_ero tags_tech spoilers traits_sexual + vn_list_own vn_list_wish tags_all tags_cont tags_ero tags_tech spoilers traits_sexual nodistract_can nodistract_nofancy /; # Returns a user preference column for the current user. Lazily loads all -- cgit v1.2.3