From c3e3b2f062eb9f0ff020b446f1de4a99a480a82f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 5 Apr 2022 14:10:48 +0200 Subject: [PATCH] Stuff --- src/app.rb | 18 ++++++++++---- src/views/admin/users/edit.slim | 40 ++++++++++++++++++++------------ src/views/stylesheets/style.sass | 2 +- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/app.rb b/src/app.rb index d843ff8..f860f0a 100755 --- a/src/app.rb +++ b/src/app.rb @@ -245,7 +245,7 @@ get "/admin/users/:id/ban" do flash[:error] = "Banned user '#{user.name}'" - redirect "/admin" + redirect back end get "/admin/users/:id/unban" do @@ -256,7 +256,15 @@ get "/admin/users/:id/unban" do flash[:success] = "Unbanned user '#{user.name}'" - redirect "/admin" + redirect back +end + +get "/admin/users/:id/edit" do + auth_denied unless get_current_user.admin? + id = params[:id].to_i + user = User.find_by_id id + + serve :"admin/users/edit", {user: user} end # ADMIN ROLE MANAGEMENT @@ -272,7 +280,7 @@ get "/admin/roles/:id/delete" do Role.delete "id = ?", id flash[:success] = "Removed role." - redirect "/admin" + redirect back end get "/admin/roles/:id/edit" do @@ -331,7 +339,7 @@ post "/admin/roles/give" do promoted_user = User.find_by_id user_id flash[:success] = "Gave role '#{newrole.name}' to #{promoted_user.name}!" if resp - redirect "/admin" + redirect back else auth_denied "You are not permitted to give that role!", 403, "/admin" end @@ -354,5 +362,5 @@ post "/admin/roles" do else flash[:error] = resp end - redirect "/admin" + redirect back end diff --git a/src/views/admin/users/edit.slim b/src/views/admin/users/edit.slim index 5773629..3287dc2 100644 --- a/src/views/admin/users/edit.slim +++ b/src/views/admin/users/edit.slim @@ -1,19 +1,29 @@ -article.card.border - h2 = "Edit role '#{role.name}'" - .form-container - form action="/admin/roles/#{role.id}/update" method="post" - label Role name - input type="text" name="name" pattern="#{NAME_REGEX_STR}" maxlength="#{MAX_NAME_LEN}" oninput="this.reportValidity()" title="#{REGISTER_ERRORS[:name_desc]}" value="#{role.name}" +.border + h1.tcenter = "#{user.name} (id=#{user.id})" + nav.tcenter + - if user.banned? + a.green.inlbutton href="/admin/users/#{user.id}/unban" + | [UNBAN USER] + - else + a.red.inlbutton href="/admin/users/#{user.id}/ban" + | [BAN USER] + a.inlbutton href="/admin" + | [GO BACK] - label Role color - input type="color" name="color" value="#{role.color}" +.management-container + .border + h2.tcenter = "User Settings" + .form-container + form action="/user/update" method="post" enctype="multipart/form-data" + img.avatar_big src="#{user.avatar_url}" alt="Your avatar" + label Change avatar + input type="file" name="image" accept="image" - label Role flags int - input type="number" name="flags" value="#{role.flags}" + label Display name + input type="text" oninput="this.reportValidity()" title="May only contain alphabetical characters and must be between #{MIN_NAME_LEN} and #{MAX_NAME_LEN} characters long" maxlength="#{MAX_NAME_LEN}" name="displayname" value="#{user.name}" pattern="#{NAME_REGEX_STR}" + + label Biography + textarea name="bio" cols="20" rows="5" title="Content length must be between #{MIN_BIO_LEN} and #{MAX_BIO_LEN} characters" pattern="#{BIO_REGEX_STR}" maxlength="#{MAX_BIO_LEN}" placeholder="Tell us about yourself!" value="#{user.bio_text}" = user.bio_text + input type="submit" value="Update" - input type="submit" value="Update" - a.button href="/admin/roles/#{role.id}/delete" - | [DELETE ROLE] - a.button href="/admin" - | [GO BACK] diff --git a/src/views/stylesheets/style.sass b/src/views/stylesheets/style.sass index 5c0eeac..8a1682c 100644 --- a/src/views/stylesheets/style.sass +++ b/src/views/stylesheets/style.sass @@ -156,7 +156,7 @@ a.button:hover font-weight: bold animation: fade-in .9s ease-in alternate background: $bg_clr - transition: .4s opacity + transition: .1s opacity div:not(:last-child) margin-bottom: 1rem