summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--elm/User/Edit.elm61
-rw-r--r--lib/VNWeb/User/Edit.pm26
-rw-r--r--util/sql/perms.sql7
-rw-r--r--util/sql/schema.sql11
-rw-r--r--util/updates/update_20191010.sql10
5 files changed, 90 insertions, 25 deletions
diff --git a/elm/User/Edit.elm b/elm/User/Edit.elm
index 51ef8be6..93eb407a 100644
--- a/elm/User/Edit.elm
+++ b/elm/User/Edit.elm
@@ -62,6 +62,11 @@ type Data
| TagsTech Bool
| Skin String
| Css String
+ | NoAds Bool
+ | NoFancy Bool
+ | Support Bool
+ | PubSkin Bool
+ | Uniname String
updateData : Data -> GUE.Send -> GUE.Send
@@ -81,6 +86,11 @@ updateData msg model =
TagsTech b -> { model | tags_tech = b }
Skin n -> { model | skin = n }
Css n -> { model | customcss = n }
+ NoAds b -> { model | nodistract_noads = b }
+ NoFancy b -> { model | nodistract_nofancy = b }
+ Support b -> { model | support_enabled = b }
+ PubSkin b -> { model | pubskin_enabled = b }
+ Uniname n -> { model | uniname = n }
type Msg
@@ -126,14 +136,16 @@ update msg model =
view : Model -> Html Msg
view model =
let
+ data = model.data
+
modform =
[ tr [ class "newpart" ] [ td [ colspan 2 ] [ text "Admin options" ] ]
- , formField "username::Username" [ inputText "username" model.data.username (Set << Username) GUE.valUsername ]
+ , formField "username::Username" [ inputText "username" data.username (Set << Username) GUE.valUsername ]
, formField "Permissions"
<| List.intersperse (br_ 1)
- <| List.map (\(n,s) -> label [] [ inputCheck "" (and model.data.perm n > 0) (Set << Perm n), text (" " ++ s) ])
+ <| List.map (\(n,s) -> label [] [ inputCheck "" (and data.perm n > 0) (Set << Perm n), text (" " ++ s) ])
GT.userPerms
- , formField "Other" [ label [] [ inputCheck "" model.data.ign_votes (Set << IgnVotes), text " Ignore votes in VN statistics" ] ]
+ , formField "Other" [ label [] [ inputCheck "" data.ign_votes (Set << IgnVotes), text " Ignore votes in VN statistics" ] ]
]
passform =
@@ -148,15 +160,30 @@ view model =
]
]
+ supportform =
+ [ tr [ class "newpart" ] [ td [ colspan 2 ] [ text "Supporter options" ] ]
+ , if not data.nodistract_can && not data.authmod then text ""
+ else formField "" [ label [] [ inputCheck "" data.nodistract_noads (Set << NoAds), text " Disable advertising and other distractions (doesn't hide affiliate links for the moment)" ] ]
+ , if not data.nodistract_can && not data.authmod then text ""
+ else formField "" [ label [] [ inputCheck "" data.nodistract_nofancy (Set << NoFancy), text " Disable supporters badges, custom usernames and profile skins" ] ]
+ , if not data.support_can && not data.authmod then text ""
+ else formField "" [ label [] [ inputCheck "" data.support_enabled (Set << Support), text " Display supporters badge" ] ]
+ , if not data.pubskin_can && not data.authmod then text ""
+ else formField "" [ label [] [ inputCheck "" data.pubskin_enabled (Set << PubSkin), text " Apply my skin and custom CSS when others visit my profile" ] ]
+ , if not data.uniname_can && not data.authmod then text ""
+ else formField "uniname::Display name" [ inputText "uniname" (if data.uniname == "" then data.username else data.uniname) (Set << Uniname) GUE.valUniname ]
+ ]
+
in Html.form [ onSubmit Submit ]
[ div [ class "mainbox" ]
- [ h1 [] [ text <| if model.data.authmod then "Edit " ++ model.data.username else "My preferences" ]
+ [ h1 [] [ text <| if data.authmod then "Edit " ++ data.username else "My preferences" ]
, table [ class "formtable" ] <|
[ tr [ class "newpart" ] [ td [ colspan 2 ] [ text "General" ] ]
- , formField "Username" [ text model.data.username ]
- , formField "email::E-Mail" [ inputText "email" model.data.email (Set << EMail) GUE.valEmail ]
+ , formField "Username" [ text data.username ]
+ , formField "email::E-Mail" [ inputText "email" data.email (Set << EMail) GUE.valEmail ]
]
- ++ (if model.data.authmod then modform else []) ++
+ ++ (if data.authmod then modform else [])
+ ++ (if data.authmod || data.nodistract_can || data.support_can || data.uniname_can || data.pubskin_can then supportform else []) ++
[ tr [ class "newpart" ] [ td [ colspan 2 ] [ text "Password" ] ]
, formField "" [ label [] [ inputCheck "" model.cpass CPass, text " Change password" ] ]
] ++ (if model.cpass then passform else [])
@@ -164,28 +191,28 @@ view model =
[ tr [ class "newpart" ] [ td [ colspan 2 ] [ text "Preferences" ] ]
, formField "Privacy"
[ label []
- [ inputCheck "" model.data.hide_list (Set << HideList)
+ [ inputCheck "" data.hide_list (Set << HideList)
, text " Don't allow others to see my visual novel list, vote list and wishlist and exclude these lists from the database dumps and API."
]
]
- , formField "NSFW" [ label [] [ inputCheck "" model.data.show_nsfw (Set << ShowNsfw), text " Show NSFW images by default" ] ]
- , formField "" [ label [] [ inputCheck "" model.data.traits_sexual (Set << TraitsSexual), text " Show sexual traits by default on character pages" ] ]
- , formField "Tags" [ label [] [ inputCheck "" model.data.tags_all (Set << TagsAll), text " Show all tags by default on visual novel pages (don't summarize)" ] ]
+ , formField "NSFW" [ label [] [ inputCheck "" data.show_nsfw (Set << ShowNsfw), text " Show NSFW images by default" ] ]
+ , formField "" [ label [] [ inputCheck "" data.traits_sexual (Set << TraitsSexual), text " Show sexual traits by default on character pages" ] ]
+ , formField "Tags" [ label [] [ inputCheck "" data.tags_all (Set << TagsAll), text " Show all tags by default on visual novel pages (don't summarize)" ] ]
, formField ""
[ text "Default tag categories on visual novel pages:", br_ 1
- , label [] [ inputCheck "" model.data.tags_cont (Set << TagsCont), text " Content" ], br_ 1
- , label [] [ inputCheck "" model.data.tags_ero (Set << TagsEro ), text " Sexual content" ], br_ 1
- , label [] [ inputCheck "" model.data.tags_tech (Set << TagsTech), text " Technical" ]
+ , label [] [ inputCheck "" data.tags_cont (Set << TagsCont), text " Content" ], br_ 1
+ , label [] [ inputCheck "" data.tags_ero (Set << TagsEro ), text " Sexual content" ], br_ 1
+ , label [] [ inputCheck "" data.tags_tech (Set << TagsTech), text " Technical" ]
]
, formField "spoil::Spoiler level"
- [ inputSelect "spoil" model.data.spoilers (Set << Spoilers) []
+ [ inputSelect "spoil" data.spoilers (Set << Spoilers) []
[ (0, "Hide spoilers")
, (1, "Show only minor spoilers")
, (2, "Show all spoilers")
]
]
- , formField "skin::Skin" [ inputSelect "skin" model.data.skin (Set << Skin) [ style "width" "300px" ] GT.skins ]
- , formField "css::Custom CSS" [ inputTextArea "css" model.data.customcss (Set << Css) ([ rows 5, cols 60 ] ++ GUE.valCustomcss) ]
+ , formField "skin::Skin" [ inputSelect "skin" data.skin (Set << Skin) [ style "width" "300px" ] GT.skins ]
+ , formField "css::Custom CSS" [ inputTextArea "css" data.customcss (Set << Css) ([ rows 5, cols 60 ] ++ GUE.valCustomcss) ]
]
]
diff --git a/lib/VNWeb/User/Edit.pm b/lib/VNWeb/User/Edit.pm
index 23302ee6..1083dc39 100644
--- a/lib/VNWeb/User/Edit.pm
+++ b/lib/VNWeb/User/Edit.pm
@@ -19,6 +19,16 @@ my $FORM = form_compile in => {
skin => { enum => tuwf->{skins} },
customcss => { required => 0, default => '', maxlength => 2000 },
+ nodistract_can => { anybool => 1 },
+ nodistract_noads => { anybool => 1 },
+ nodistract_nofancy => { anybool => 1 },
+ support_can => { anybool => 1 },
+ support_enabled => { anybool => 1 },
+ uniname_can => { anybool => 1 },
+ uniname => { required => 0, default => '', length => [ 2, 15 ] },
+ pubskin_can => { anybool => 1 },
+ pubskin_enabled => { anybool => 1 },
+
password => { _when => 'in', required => 0, type => 'hash', keys => {
old => { password => 1 },
new => { password => 1 }
@@ -41,8 +51,9 @@ sub _getmail {
TUWF::get qr{/$RE{uid}/edit}, sub {
my $u = tuwf->dbRowi(q{
- SELECT id, username, perm, ign_votes, hide_list, show_nsfw, traits_sexual,
- tags_all, tags_cont, tags_ero, tags_tech, spoilers, skin, customcss
+ SELECT id, username, perm, ign_votes, hide_list, show_nsfw, traits_sexual
+ , tags_all, tags_cont, tags_ero, tags_tech, spoilers, skin, customcss
+ , nodistract_can, nodistract_noads, nodistract_nofancy, support_can, support_enabled, uniname_can, uniname, pubskin_can, pubskin_enabled
FROM users WHERE id =}, \tuwf->capture('id')
);
@@ -74,6 +85,9 @@ json_api qr{/u/edit}, $FORM, sub {
return tuwf->resNotFound if !$username;
return elm_Unauth if !can_edit u => $data;
+ return elm_Taken if $data->{uniname}
+ && tuwf->dbVali('SELECT 1 FROM users WHERE id <>', \$data->{id}, 'AND username =', \lc($data->{uniname}));
+
if(auth->permUsermod) {
tuwf->dbExeci(update => users => set => {
username => $data->{username},
@@ -124,7 +138,13 @@ json_api qr{/u/edit}, $FORM, sub {
}
$data->{skin} = '' if $data->{skin} eq config->{skin_default};
- auth->prefSet($_, $data->{$_}, $data->{id}) for qw/hide_list show_nsfw traits_sexual tags_all tags_cont tags_ero tags_tech spoilers skin customcss/;
+ $data->{uniname} = '' if $data->{uniname} eq $data->{username};
+ tuwf->dbExeci('UPDATE users SET', { %{$data}{qw/
+ hide_list show_nsfw traits_sexual tags_all tags_cont tags_ero tags_tech spoilers skin customcss
+ nodistract_noads nodistract_nofancy support_enabled uniname pubskin_enabled
+ /} },
+ 'WHERE id =', \$data->{id}
+ );
$ret->();
};
diff --git a/util/sql/perms.sql b/util/sql/perms.sql
index 6bf43a63..5e0f5df3 100644
--- a/util/sql/perms.sql
+++ b/util/sql/perms.sql
@@ -64,10 +64,9 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON traits_parents TO vndb_site;
-- users table is special; The 'perm', 'passwd' and 'mail' columns are
-- protected and can only be accessed through the user_* functions.
-GRANT SELECT (id, username, registered, perm, c_votes, c_changes, ip, c_tags, ign_votes, 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),
- INSERT (id, username, mail, registered, c_votes, c_changes, ip, c_tags, ign_votes, 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),
- UPDATE ( username, registered, c_votes, c_changes, ip, c_tags, ign_votes, 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) ON users TO vndb_site;
-GRANT DELETE ON users TO vndb_site;
+GRANT SELECT (id, username, registered, perm, c_votes, c_changes, ip, c_tags, ign_votes, 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, nodistract_can, nodistract_noads, nodistract_nofancy, support_can, support_enabled, uniname_can, uniname, pubskin_can, pubskin_enabled),
+ INSERT (id, username, mail, registered, c_votes, c_changes, ip, c_tags, ign_votes, 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, nodistract_can, nodistract_noads, nodistract_nofancy, support_can, support_enabled, uniname_can, uniname, pubskin_can, pubskin_enabled),
+ UPDATE ( username, registered, c_votes, c_changes, ip, c_tags, ign_votes, 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, nodistract_can, nodistract_noads, nodistract_nofancy, support_can, support_enabled, uniname_can, uniname, pubskin_can, pubskin_enabled) ON users TO vndb_site;
GRANT SELECT, INSERT, UPDATE ON vn TO vndb_site;
GRANT SELECT, INSERT, DELETE ON vn_anime TO vndb_site;
diff --git a/util/sql/schema.sql b/util/sql/schema.sql
index 7db233d1..a3c65c7b 100644
--- a/util/sql/schema.sql
+++ b/util/sql/schema.sql
@@ -734,7 +734,16 @@ CREATE TABLE users (
tags_ero boolean NOT NULL DEFAULT FALSE,
tags_tech boolean NOT NULL DEFAULT TRUE,
spoilers smallint NOT NULL DEFAULT 0,
- traits_sexual boolean NOT NULL DEFAULT FALSE
+ traits_sexual boolean NOT NULL DEFAULT FALSE,
+ nodistract_can boolean NOT NULL DEFAULT FALSE,
+ nodistract_noads boolean NOT NULL DEFAULT FALSE,
+ nodistract_nofancy boolean NOT NULL DEFAULT FALSE,
+ support_can boolean NOT NULL DEFAULT FALSE,
+ support_enabled boolean NOT NULL DEFAULT FALSE,
+ uniname_can boolean NOT NULL DEFAULT FALSE,
+ uniname text NOT NULL DEFAULT '',
+ pubskin_can boolean NOT NULL DEFAULT FALSE,
+ pubskin_enabled boolean NOT NULL DEFAULT FALSE
);
-- vn
diff --git a/util/updates/update_20191010.sql b/util/updates/update_20191010.sql
new file mode 100644
index 00000000..1cdf898f
--- /dev/null
+++ b/util/updates/update_20191010.sql
@@ -0,0 +1,10 @@
+ALTER TABLE users ADD COLUMN nodistract_can boolean NOT NULL DEFAULT FALSE;
+ALTER TABLE users ADD COLUMN nodistract_noads boolean NOT NULL DEFAULT FALSE;
+ALTER TABLE users ADD COLUMN nodistract_nofancy boolean NOT NULL DEFAULT FALSE;
+ALTER TABLE users ADD COLUMN support_can boolean NOT NULL DEFAULT FALSE;
+ALTER TABLE users ADD COLUMN support_enabled boolean NOT NULL DEFAULT FALSE;
+ALTER TABLE users ADD COLUMN uniname_can boolean NOT NULL DEFAULT FALSE;
+ALTER TABLE users ADD COLUMN uniname text NOT NULL DEFAULT '';
+ALTER TABLE users ADD COLUMN pubskin_can boolean NOT NULL DEFAULT FALSE;
+ALTER TABLE users ADD COLUMN pubskin_enabled boolean NOT NULL DEFAULT FALSE;
+\i util/sql/perms.sql