User: Settings page & style refactor

master
E. Almqvist 3 years ago
parent d502f2816e
commit 5aad900122
  1. 12
      src/app.rb
  2. 5
      src/db_models.rb
  3. 5
      src/lib/database.rb
  4. 8
      src/views/stylesheets/style.sass
  5. 9
      src/views/user/settings.slim

@ -119,8 +119,18 @@ post "/login" do
end end
end end
post "/logout" do get "/logout" do
session.clear session.clear
redirect "/" redirect "/"
end end
post "/user/update" do
data = {
bio_text: params["bio"],
avatar_url: params["avatar_url"]
}
User.update(data, "id = ?", session[:userid])
redirect "/settings"
end

@ -46,7 +46,7 @@ class User < EntityModel
return "#{sign}#{@reputation}" return "#{sign}#{@reputation}"
end end
def reputation= val def reputation=(val)
val = val.clamp MIN_REP, MAX_REP val = val.clamp MIN_REP, MAX_REP
@reputation = val @reputation = val
self.update({reputation: val}, "id = ?", @id) self.update({reputation: val}, "id = ?", @id)
@ -113,7 +113,6 @@ class User < EntityModel
end end
end end
# Log in user # Log in user
# Returns: success?, user id # Returns: success?, user id
def self.login(email, password) def self.login(email, password)
@ -158,7 +157,7 @@ class Role < EntityModel
end end
def self.edit(roleid, data) def self.edit(roleid, data)
self.update data, "id = ?", roleid self.update data, "id = #{roleid}"
end end
end end

@ -25,7 +25,8 @@ class EntityModel
end end
def self.gen_update_query(vars) # generates part of the update query string def self.gen_update_query(vars) # generates part of the update query string
vars.join "= ?, " out = vars.join " = ?, "
out += " = ?"
end end
def self.gen_insert_query(vars) # generates part of the insert query string def self.gen_insert_query(vars) # generates part of the insert query string
@ -41,6 +42,7 @@ class EntityModel
end end
def self.query(q, *args) # query table with query string def self.query(q, *args) # query table with query string
Console.debug("Running SQL -> #{q}", *args)
db.execute( q, *args ) db.execute( q, *args )
end end
@ -54,7 +56,6 @@ class EntityModel
def self.update(data, filter="", *args) # Updates the table with specified data hash def self.update(data, filter="", *args) # Updates the table with specified data hash
q = "UPDATE #{self.name} SET #{self.gen_update_query(data.keys)}" q = "UPDATE #{self.name} SET #{self.gen_update_query(data.keys)}"
q = apply_filter(q, filter) q = apply_filter(q, filter)
self.query(q, *data.values, *args) self.query(q, *data.values, *args)
end end

@ -180,6 +180,10 @@ ul.button-container
max-width: 400px max-width: 400px
border-radius: .4rem border-radius: .4rem
label
color: $fg_alt_clr
opacity: .8
a a
color: $special_clr color: $special_clr
padding: .2rem 0 padding: .2rem 0
@ -287,7 +291,7 @@ ul.button-container
width: 70% width: 70%
max-width: 12rem max-width: 12rem
height: auto height: auto
border: 2px solid $special_clr border: 2px solid $gray_clr
#roles #roles
margin-bottom: 1.75rem margin-bottom: 1.75rem
@ -312,3 +316,5 @@ ul.button-container
margin-bottom: 4rem margin-bottom: 4rem
padding-bottom: 2rem padding-bottom: 2rem
#settings

@ -1 +1,8 @@
h1 Settings h1.tcenter = "#{session_user.name}'s Settings"
.form-container
form action="/user/update" method="post"
label Avatar URL
input type="text" name="avatar_url" placeholder="/avatars/default.png" value="#{session_user.avatar_url}"
label Biography
input type="text" name="bio" placeholder="User Biography" value="#{session_user.bio_text}"
input type="submit" value="Update"

Loading…
Cancel
Save