Settings: error messages

master
E. Almqvist 3 years ago
parent 75d86415d7
commit af5b2a8ecc
  1. 26
      src/app.rb
  2. 7
      src/config.rb
  3. 2
      src/func.rb
  4. BIN
      src/public/avatars/1.png
  5. BIN
      src/public/avatars/3.png
  6. 3
      src/views/stylesheets/style.sass
  7. 7
      src/views/user/settings.slim

@ -119,20 +119,28 @@ post "/login" do
end
end
get "/logout" do # TODO: make me post
post "/user/logout" do
session.clear
redirect "/"
end
post "/user/update" do
imgdata = params[:image][:tempfile]
save_image imgdata.read, "./public/avatars/#{session[:userid]}.png"
data = {
bio_text: params["bio"],
avatar_url: "/avatars/#{session[:userid]}.png"
}
User.update(data, "id = ?", session[:userid])
data = {}
if params[:image] then
imgdata = params[:image][:tempfile]
save_image imgdata.read, "./public/avatars/#{session[:userid]}.png"
data[:avatar_url] = "/avatars/#{session[:userid]}.png"
end
current_user = get_current_user
data[:bio_text] = params["bio"] unless params["bio"] == current_user.bio_text
if params["displayname"].length < MIN_NAME_LEN then
session[:error_msg] = SETTINGS_ERRORS[:name_len]
else
data[:name] = params["displayname"] unless params["displayname"] == current_user.name
end
User.update(data, "id = ?", session[:userid]) unless data.length < 1
redirect "/settings"
end

@ -1,6 +1,9 @@
# DB stuff
DB_PATH = "db/main.db"
# User settings stuff
AVATAR_SIZE = 1024
# Register stuff
MIN_PASSWORD_LEN = 8
MIN_NAME_LEN = 2
@ -19,6 +22,10 @@ REGISTER_ERRORS = {
email_fake: "Please use a valid email address"
}
SETTINGS_ERRORS = {
name_len: "Name length must be at least #{MIN_NAME_LEN}"
}
# Login stuff
LOGIN_ERRORS = {
fields: "Please fill all of the fields",

@ -28,6 +28,6 @@ def save_image imgdata, path
image = Magick::Image.from_blob(imgdata).first
image.format = "PNG"
File.open(path, 'wb') do |f|
image.resize_to_fill(512, 512).write(f)
image.resize_to_fill(AVATAR_SIZE, AVATAR_SIZE).write(f)
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

@ -337,6 +337,9 @@ ul.button-container
#settings
.form-container
.error_msg
margin-bottom: .8rem
color: $red_clr
form
background-color: $bg_alt_clr
border: $border_size solid $border_clr

@ -2,11 +2,14 @@
h1.tcenter = "#{session_user.name}'s Settings"
.form-container
form action="/user/update" method="post" enctype="multipart/form-data"
label.error_msg = error_msg
img.avatar_big src="#{session_user.avatar_url}" alt="Your avatar"
label Change avatar
input type="file" name="image" accept="image"
label Display name (min 2 chars)
input type="text" name="displayname" value="#{session_user.name}"
label Biography
textarea name="bio" cols="20" rows="5" placeholder="Tell us about yourself!" value="#{session_user.bio_text}"
textarea name="bio" cols="20" rows="5" placeholder="Tell us about yourself!" value="#{session_user.bio_text}" = session_user.bio_text
input type="submit" value="Update"

Loading…
Cancel
Save