summaryrefslogtreecommitdiff
path: root/lib/VNDB/Handler/Users.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-02 14:21:12 +0200
committerYorhel <git@yorhel.nl>2019-10-02 14:21:15 +0200
commit7d8274f0332b1c92825988c6393037bf7eb12af3 (patch)
treecdcc33c92f764b3199fffeef990d71e6085dff06 /lib/VNDB/Handler/Users.pm
parent1a9a4b4bdb8f3b6d7d0ad12032c17c44a8287a09 (diff)
v2rw: Convert user preferences form
And add a small 'formField' function to shrink the Elm form generation code a bit.
Diffstat (limited to 'lib/VNDB/Handler/Users.pm')
-rw-r--r--lib/VNDB/Handler/Users.pm129
1 files changed, 0 insertions, 129 deletions
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index 171b6b4f..2557b9d1 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -13,7 +13,6 @@ use PWLookup;
TUWF::register(
qr{u([1-9]\d*)} => \&userpage,
- qr{u([1-9]\d*)/edit} => \&edit,
qr{u([1-9]\d*)/posts} => \&posts,
qr{u([1-9]\d*)/del(/[od])?} => \&delete,
qr{u/(all|[0a-z])} => \&list,
@@ -138,134 +137,6 @@ sub userpage {
}
-sub edit {
- my($self, $uid) = @_;
-
- # are we allowed to edit this user?
- return $self->htmlDenied if !$self->authInfo->{id} || $self->authInfo->{id} != $uid && !$self->authCan('usermod');
-
- # fetch user info (cached if uid == loggedin uid)
- my $u = $self->dbUserGet(uid => $uid, what => 'extended prefs')->[0];
- return $self->resNotFound if !$u->{id};
-
- # check POST data
- my $frm;
- if($self->reqMethod eq 'POST') {
- return if !$self->authCheckCode;
- $frm = $self->formValidate(
- $self->authCan('usermod') ? (
- { post => 'usrname', template => 'uname' },
- { post => 'perms', required => 0, multi => 1, enum => [ keys %{$self->{permissions}} ] },
- { post => 'ign_votes', required => 0, default => 0 },
- ) : (),
- { post => 'mail', template => 'email' },
- { post => 'curpass', required => 0, minlength => 4, maxlength => 500, default => '' },
- { post => 'usrpass', required => 0, minlength => 4, maxlength => 500 },
- { post => 'usrpass2', required => 0, minlength => 4, maxlength => 500 },
- { post => 'hide_list', required => 0, default => 0, enum => [0,1] },
- { post => 'show_nsfw', required => 0, default => 0, enum => [0,1] },
- { post => 'traits_sexual', required => 0, default => 0, enum => [0,1] },
- { post => 'tags_all', required => 0, default => 0, enum => [0,1] },
- { post => 'tags_cat', required => 0, multi => 1, enum => [qw|cont ero tech|] },
- { post => 'spoilers', required => 0, default => 0, enum => [0..2] },
- { post => 'skin', required => 0, default => $self->{skin_default}, enum => [ keys %{$self->{skins}} ] },
- { post => 'customcss', required => 0, maxlength => 2000, default => '' },
- );
- push @{$frm->{_err}}, 'Passwords do not match'
- if ($frm->{usrpass} || $frm->{usrpass2}) && (!$frm->{usrpass} || !$frm->{usrpass2} || $frm->{usrpass} ne $frm->{usrpass2});
- push @{$frm->{_err}}, 'Your chosen password is in a database of leaked passwords, please choose another one'
- if $self->{password_db} && PWLookup::lookup($self->{password_db}, $frm->{usrpass});
-
- if(!$frm->{_err}) {
- $frm->{skin} = '' if $frm->{skin} eq $self->{skin_default};
- $self->dbUserPrefSet($uid, $_ => $frm->{$_}) for (qw|skin customcss show_nsfw traits_sexual tags_all hide_list spoilers|);
-
- my $tags_cat = join(',', sort @{$frm->{tags_cat}}) || 'none';
- $self->dbUserPrefSet($uid, tags_cat => $tags_cat eq $self->{default_tags_cat} ? '' : $tags_cat);
-
- my %o;
- if($self->authCan('usermod')) {
- $o{username} = $frm->{usrname} if $frm->{usrname};
- $o{ign_votes} = $frm->{ign_votes} ? 1 : 0;
-
- my $perm = 0;
- $perm |= $self->{permissions}{$_} for(@{ delete $frm->{perms} });
- $self->dbUserSetPerm($u->{id}, $self->authInfo->{id}, auth->token(), $perm);
- }
- $self->dbUserSetMail($u->{id}, $self->authInfo->{id}, auth->token(), $frm->{mail});
- $self->dbUserEdit($uid, %o);
- $self->authAdminSetPass($u->{id}, $frm->{usrpass}) if $frm->{usrpass} && $self->authInfo->{id} != $u->{id};
-
- if($frm->{usrpass} && $self->authInfo->{id} == $u->{id}) {
- # Bit ugly: On incorrect password, all other changes are still saved.
- my $ok = $self->authSetPass($u->{id}, $frm->{usrpass}, "/u$uid/edit?d=1", pass => $frm->{curpass});
- return if $ok;
- push @{$frm->{_err}}, 'Invalid password';
- } else {
- return $self->resRedirect("/u$uid/edit?d=1", 'post');
- }
- }
- }
-
- # fill out default values
- $frm->{usrname} ||= $u->{username};
- $frm->{mail} ||= $self->dbUserGetMail($u->{id}, $self->authInfo->{id}, auth->token);
- $frm->{perms} ||= [ grep $u->{perm} & $self->{permissions}{$_}, keys %{$self->{permissions}} ];
- $frm->{$_} //= $u->{prefs}{$_} for(qw|skin customcss show_nsfw traits_sexual tags_all hide_list spoilers|);
- $frm->{tags_cat} ||= [ split /,/, $u->{prefs}{tags_cat}||$self->{default_tags_cat} ];
- $frm->{ign_votes} = $u->{ign_votes} if !defined $frm->{ign_votes};
- $frm->{skin} ||= $self->{skin_default};
- $frm->{usrpass} = $frm->{usrpass2} = $frm->{curpass} = '';
-
- # create the page
- $self->htmlHeader(title => 'My account', noindex => 1);
- $self->htmlMainTabs('u', $u, 'edit');
- if($self->reqGet('d')) {
- div class => 'mainbox';
- h1 'Settings saved';
- div class => 'notice';
- p 'Settings successfully saved.';
- end;
- end
- }
- $self->htmlForm({ frm => $frm, action => "/u$uid/edit" }, useredit => [ 'My account',
- [ part => title => 'General info' ],
- $self->authCan('usermod') ? (
- [ input => short => 'usrname', name => 'Username' ],
- [ select => short => 'perms', name => 'Permissions', multi => 1, size => (scalar keys %{$self->{permissions}}), options => [
- map [ $_, $_ ], sort keys %{$self->{permissions}} ] ],
- [ check => short => 'ign_votes', name => 'Ignore votes in VN statistics' ],
- ) : (
- [ static => label => 'Username', content => $frm->{usrname} ],
- ),
- [ input => short => 'mail', name => 'Email' ],
-
- [ part => title => 'Change password' ],
- [ static => content => 'Leave blank to keep your current password' ],
- [ passwd => short => 'curpass', name => 'Current Password' ],
- [ passwd => short => 'usrpass', name => 'New Password' ],
- [ passwd => short => 'usrpass2', name => 'Confirm password' ],
-
- [ part => title => 'Options' ],
- [ check => short => 'hide_list', name =>
- qq{Don't allow other people to see my <a href="/u$uid/list">visual novel list</a>,
- <a href="/u$uid/votes">votes</a> and <a href="/u$uid/wish">wishlist</a>,
- and exclude these lists from the <a href="/d14">database dumps</a> and <a href="/d11">API</a>.} ],
- [ check => short => 'show_nsfw', name => 'Disable warnings for images that are not safe for work.' ],
- [ check => short => 'traits_sexual', name => 'Show sexual traits by default on character pages.' ],
- [ check => short => 'tags_all', name => 'Show all tags by default on visual novel pages.' ],
- [ select => short => 'tags_cat', name => 'Tag categories', multi => 1, size => 3,
- options => [ map [ $_, $TAG_CATEGORY{$_} ], keys %TAG_CATEGORY ] ],
- [ select => short => 'spoilers', name => 'Spoiler level', options => [
- [0, 'Hide spoilers'], [1, 'Show only minor spoilers'], [2, 'Show all spoilers'] ]],
- [ select => short => 'skin', name => 'Preferred skin', width => 300, options => [
- map [ $_, $self->{skins}{$_}[0].($self->debug?" [$_]":'') ], sort { $self->{skins}{$a}[0] cmp $self->{skins}{$b}[0] } keys %{$self->{skins}} ] ],
- [ textarea => short => 'customcss', name => 'Additional <a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets">CSS</a>' ],
- ]);
- $self->htmlFooter;
-}
-
-
sub posts {
my($self, $uid) = @_;