new user page
This commit is contained in:
		@@ -81,6 +81,23 @@ app:get("user", "/:username", function(self)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  self.stats = db.query([[
 | 
			
		||||
    SELECT
 | 
			
		||||
      COUNT(posts.id) AS post_count,
 | 
			
		||||
      COUNT(DISTINCT threads.id) AS thread_count,
 | 
			
		||||
      MAX(threads.title) FILTER (WHERE threads.created_at = latest.created_at) AS latest_thread_title,
 | 
			
		||||
      MAX(threads.slug) FILTER (WHERE threads.created_at = latest.created_at) AS latest_thread_slug
 | 
			
		||||
    FROM users
 | 
			
		||||
    LEFT JOIN posts ON posts.user_id = users.id
 | 
			
		||||
    LEFT JOIN threads ON threads.user_id = users.id
 | 
			
		||||
    LEFT JOIN (
 | 
			
		||||
      SELECT user_id, MAX(created_at) AS created_at
 | 
			
		||||
      FROM threads
 | 
			
		||||
      GROUP BY user_id
 | 
			
		||||
    ) latest ON latest.user_id = users.id
 | 
			
		||||
    WHERE users.id = ?
 | 
			
		||||
  ]], user.id)[1]
 | 
			
		||||
  
 | 
			
		||||
  self.latest_posts = db.query([[
 | 
			
		||||
    SELECT
 | 
			
		||||
      posts.id, posts.created_at, post_history.content, post_history.edited_at, threads.title AS thread_title, topics.name as topic_name, threads.slug as thread_slug
 | 
			
		||||
 
 | 
			
		||||
@@ -145,6 +145,10 @@ body {
 | 
			
		||||
  overflow: hidden;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.post-content.wider {
 | 
			
		||||
  margin-right: 12.5%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.post-inner {
 | 
			
		||||
  height: 100%;
 | 
			
		||||
}
 | 
			
		||||
@@ -218,35 +222,43 @@ blockquote {
 | 
			
		||||
  background-color: rgb(135.1928346457, 145.0974015748, 123.0025984252);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-posts {
 | 
			
		||||
.user-info {
 | 
			
		||||
  display: grid;
 | 
			
		||||
  grid-template-columns: 200px 1fr;
 | 
			
		||||
  grid-template-columns: 300px 1fr;
 | 
			
		||||
  grid-template-rows: 1fr;
 | 
			
		||||
  gap: 0;
 | 
			
		||||
  grid-auto-flow: row;
 | 
			
		||||
  grid-template-areas: "user-page-usercard user-posts-container";
 | 
			
		||||
  border: 2px outset rgb(135.1928346457, 145.0974015748, 123.0025984252);
 | 
			
		||||
  grid-template-areas: "user-page-usercard user-page-stats";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-page-usercard {
 | 
			
		||||
  grid-area: user-page-usercard;
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
  align-items: center;
 | 
			
		||||
  padding: 20px 10px;
 | 
			
		||||
  border: 4px outset rgb(217.26, 220.38, 213.42);
 | 
			
		||||
  background-color: rgb(143.7039271654, 144.3879625984, 142.8620374016);
 | 
			
		||||
  border-right: solid 2px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-posts-container {
 | 
			
		||||
  grid-area: user-posts-container;
 | 
			
		||||
  display: grid;
 | 
			
		||||
  grid-template-columns: 1fr;
 | 
			
		||||
  grid-template-rows: 0.2fr 2.5fr;
 | 
			
		||||
  gap: 0px 0px;
 | 
			
		||||
  grid-auto-flow: row;
 | 
			
		||||
  grid-template-areas: "post-info" "post-content";
 | 
			
		||||
.user-page-stats {
 | 
			
		||||
  grid-area: user-page-stats;
 | 
			
		||||
  padding: 20px 30px;
 | 
			
		||||
  border: 1px solid black;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-stats-list {
 | 
			
		||||
  list-style: none;
 | 
			
		||||
  margin: 0 0 10px 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-page-posts {
 | 
			
		||||
  border-left: solid 1px black;
 | 
			
		||||
  border-right: solid 1px black;
 | 
			
		||||
  border-bottom: solid 1px black;
 | 
			
		||||
  background-color: #c1ceb1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-page-post-preview {
 | 
			
		||||
  max-height: 200px;
 | 
			
		||||
  mask-image: linear-gradient(180deg, #000 60%, transparent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.avatar {
 | 
			
		||||
 
 | 
			
		||||
@@ -189,6 +189,10 @@ body {
 | 
			
		||||
  overflow: hidden;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.post-content.wider {
 | 
			
		||||
  margin-right: 12.5%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.post-inner {
 | 
			
		||||
  height: 100%;
 | 
			
		||||
}
 | 
			
		||||
@@ -264,38 +268,44 @@ blockquote {
 | 
			
		||||
  background-color: $dark2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-posts {
 | 
			
		||||
.user-info {
 | 
			
		||||
  display: grid;
 | 
			
		||||
  grid-template-columns: 200px 1fr;
 | 
			
		||||
  grid-template-columns: 300px 1fr;
 | 
			
		||||
  grid-template-rows: 1fr;
 | 
			
		||||
  gap: 0;
 | 
			
		||||
  grid-auto-flow: row;
 | 
			
		||||
  grid-template-areas:
 | 
			
		||||
    "user-page-usercard user-posts-container";
 | 
			
		||||
  border: 2px outset $dark2;
 | 
			
		||||
    "user-page-usercard user-page-stats";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-page-usercard {
 | 
			
		||||
  grid-area: user-page-usercard;
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
  align-items: center;
 | 
			
		||||
  padding: 20px 10px;
 | 
			
		||||
  border: 4px outset $light;
 | 
			
		||||
  background-color: $dark_bg;
 | 
			
		||||
  border-right: solid 2px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-posts-container {
 | 
			
		||||
  grid-area: user-posts-container;
 | 
			
		||||
  display: grid;
 | 
			
		||||
  grid-template-columns: 1fr;
 | 
			
		||||
  grid-template-rows: 0.2fr 2.5fr;
 | 
			
		||||
  gap: 0px 0px;
 | 
			
		||||
  grid-auto-flow: row;
 | 
			
		||||
  grid-template-areas:
 | 
			
		||||
    "post-info"
 | 
			
		||||
    "post-content";
 | 
			
		||||
.user-page-stats {
 | 
			
		||||
  grid-area: user-page-stats;
 | 
			
		||||
  padding: 20px 30px;
 | 
			
		||||
  border: 1px solid black;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-stats-list {
 | 
			
		||||
  list-style: none;
 | 
			
		||||
  margin: 0 0 10px 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-page-posts {
 | 
			
		||||
  border-left: solid 1px black;
 | 
			
		||||
  border-right: solid 1px black;
 | 
			
		||||
  border-bottom: solid 1px black;
 | 
			
		||||
  background-color: $accent_color;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.user-page-post-preview {
 | 
			
		||||
  max-height: 200px;
 | 
			
		||||
  mask-image: linear-gradient(180deg,#000 60%,transparent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.avatar {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,7 @@
 | 
			
		||||
  <% render("views.common.infobox", infobox) %>
 | 
			
		||||
<% end %>
 | 
			
		||||
<div class="darkbg">
 | 
			
		||||
  <h1 class="thread-title">Latest posts by <i><%= user.username %></i></h1>
 | 
			
		||||
  <div>
 | 
			
		||||
  User permission: <i><%= PermissionLevelString[user.permission] %></i>
 | 
			
		||||
  </div>
 | 
			
		||||
  <h1 class="thread-title"><i><%= user.username %></i>'s profile</h1>
 | 
			
		||||
  <% if user_is_me then -%>
 | 
			
		||||
  <div class="user-actions">
 | 
			
		||||
    <a class="linkbutton" href="<%= url_for("user_settings", {username = user.username}) %>">Settings</a>
 | 
			
		||||
@@ -13,61 +10,81 @@
 | 
			
		||||
      <input class="warn" type="submit" value="Log out">
 | 
			
		||||
    </form>
 | 
			
		||||
  </div>
 | 
			
		||||
    <% if user:is_guest() then %>
 | 
			
		||||
      <h2>You are a guest. A Moderator needs to approve your account before you will be able to post.</h2>
 | 
			
		||||
    <% end %>
 | 
			
		||||
  <% end %>
 | 
			
		||||
  <% if me:is_mod() and not user:is_system() then %>
 | 
			
		||||
      <h1 class="thread-title">Moderator controls</h1>
 | 
			
		||||
      <% if user:is_guest() then %>
 | 
			
		||||
        <p>This user is a guest. They signed up on <% render("views.common.timestamp", {timestamp = user.created_at}) -%>.</p>
 | 
			
		||||
        <form class="modform" method="post" action="<%= url_for("confirm_user", {user_id = user.id}) %>">
 | 
			
		||||
          <input type="submit" value="Confirm user">
 | 
			
		||||
        </form>
 | 
			
		||||
      <% else %> <% --[[ user is not guest ]] %>
 | 
			
		||||
        <p>This user signed up on <% render("views.common.timestamp", {timestamp = user.created_at}) -%> and was confirmed on <% render("views.common.timestamp", {timestamp = user.confirmed_on}) %>.</p>
 | 
			
		||||
        <% if user.permission < me.permission then %>
 | 
			
		||||
        <form class="modform" method="post" action="<%= url_for("guest_user", {user_id = user.id}) %>">
 | 
			
		||||
          <input class="warn" type="submit" value="Demote user to guest (soft ban)">
 | 
			
		||||
        </form>
 | 
			
		||||
        <% end %>
 | 
			
		||||
        <% if me:is_admin() and not user:is_mod() then %>
 | 
			
		||||
          <form class="modform" method="post" action="<%= url_for("mod_user", {user_id = user.id}) %>">
 | 
			
		||||
            <input class="warn" type="submit" value="Promote user to moderator">
 | 
			
		||||
          </form>
 | 
			
		||||
        <% elseif user:is_mod() and user.permission < me.permission then %>
 | 
			
		||||
          <form class="modform" method="post" action="<%= url_for("demod_user", {user_id = user.id}) %>">
 | 
			
		||||
            <input class="critical" type="submit" value="Demote user to regular user">
 | 
			
		||||
          </form>
 | 
			
		||||
        <% end %>
 | 
			
		||||
      <% end %>
 | 
			
		||||
  <% end %>
 | 
			
		||||
</div>
 | 
			
		||||
<% --[[ duplicating code, maybe i'll refactor the post subview later to work anywhere <clown emoji>]] %>
 | 
			
		||||
<% for i, post in ipairs(latest_posts) do %>
 | 
			
		||||
  <div class="user-posts">
 | 
			
		||||
    <div class="user-page-usercard">
 | 
			
		||||
 | 
			
		||||
<div class="user-info">
 | 
			
		||||
  <div class="user-page-usercard">
 | 
			
		||||
    <div class="usercard-inner">
 | 
			
		||||
      <img class="avatar" src="<%= avatar_url(user) %>">
 | 
			
		||||
      <b class="big"><%= user.username %></b>
 | 
			
		||||
      <em class="user-status"><%= user.status %></em>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="user-posts-container">
 | 
			
		||||
      <div class="post-info">
 | 
			
		||||
        <div><a href="<%= url_for("thread", {slug = post.thread_slug}, {after = post.id}) .. "#post-" .. post.id %>" title="Permalink"><i>
 | 
			
		||||
        <% if tonumber(post.edited_at) > tonumber(post.created_at) then -%>
 | 
			
		||||
            Edited in <%= post.thread_title %> at <% render("views.common.timestamp", {timestamp = post.edited_at}) -%>
 | 
			
		||||
          <% else -%>
 | 
			
		||||
            Posted in <%= post.thread_title %> on <% render("views.common.timestamp", {timestamp = post.created_at}) -%>
 | 
			
		||||
          <% end -%>
 | 
			
		||||
      </i></a></div>
 | 
			
		||||
      </div>
 | 
			
		||||
      <div class="post-content">
 | 
			
		||||
        <%- post.content %>
 | 
			
		||||
      </div>
 | 
			
		||||
      <strong class="big"><%= user.username %></strong>
 | 
			
		||||
      <% if user.status ~= "" then %>
 | 
			
		||||
        <em class="user-status"><%= user.status %></em>
 | 
			
		||||
      <% end %>
 | 
			
		||||
      <% if user.signature_rendered ~= "" then %>
 | 
			
		||||
        Signature:
 | 
			
		||||
        <div>
 | 
			
		||||
          <%- user.signature_rendered %>
 | 
			
		||||
        </div>
 | 
			
		||||
      <% end %>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
<% end %>
 | 
			
		||||
 | 
			
		||||
<% if user:is_guest() and user_is_me then %>
 | 
			
		||||
  <h2>You are a guest. A Moderator needs to approve your account before you will be able to post.</h2>
 | 
			
		||||
<% end %>
 | 
			
		||||
 | 
			
		||||
<% if me:is_mod() and not user:is_system() then %>
 | 
			
		||||
  <div class="darkbg">
 | 
			
		||||
    <h1>Moderator controls</h2>
 | 
			
		||||
    <% if user:is_guest() then %>
 | 
			
		||||
      <p>This user is a guest. They signed up on <% render("views.common.timestamp", {timestamp = user.created_at}) -%>.</p>
 | 
			
		||||
      <form class="modform" method="post" action="<%= url_for("confirm_user", {user_id = user.id}) %>">
 | 
			
		||||
        <input type="submit" value="Confirm user">
 | 
			
		||||
      </form>
 | 
			
		||||
    <% else %> <% --[[ user is not guest ]] %>
 | 
			
		||||
      <p>This user signed up on <% render("views.common.timestamp", {timestamp = user.created_at}) -%> and was confirmed on <% render("views.common.timestamp", {timestamp = user.confirmed_on}) %>.</p>
 | 
			
		||||
      <% if user.permission < me.permission then %>
 | 
			
		||||
      <form class="modform" method="post" action="<%= url_for("guest_user", {user_id = user.id}) %>">
 | 
			
		||||
        <input class="warn" type="submit" value="Demote user to guest (soft ban)">
 | 
			
		||||
      </form>
 | 
			
		||||
  <div class="user-page-stats">
 | 
			
		||||
    <ul class="user-stats-list">
 | 
			
		||||
      <li>Permission: <%= PermissionLevelString[user.permission] %></li>
 | 
			
		||||
      <li>Posts created: <%= stats.post_count %></li>
 | 
			
		||||
      <li>Threads started: <%= stats.thread_count %></li>
 | 
			
		||||
      <% if stats.latest_thread_title then %>
 | 
			
		||||
        <li>Latest started thread: <a href="<%= url_for("thread", {slug = stats.latest_thread_slug}) %>"><%= stats.latest_thread_title %></a></li>
 | 
			
		||||
      <% end %>
 | 
			
		||||
      <% if me:is_admin() and not user:is_mod() then %>
 | 
			
		||||
        <form class="modform" method="post" action="<%= url_for("mod_user", {user_id = user.id}) %>">
 | 
			
		||||
          <input class="warn" type="submit" value="Promote user to moderator">
 | 
			
		||||
        </form>
 | 
			
		||||
      <% elseif user:is_mod() and user.permission < me.permission then %>
 | 
			
		||||
        <form class="modform" method="post" action="<%= url_for("demod_user", {user_id = user.id}) %>">
 | 
			
		||||
          <input class="critical" type="submit" value="Demote user to regular user">
 | 
			
		||||
        </form>
 | 
			
		||||
    </ul>
 | 
			
		||||
    Latest posts:
 | 
			
		||||
    <div class="user-page-posts">
 | 
			
		||||
      <% for _, post in ipairs(latest_posts) do %>
 | 
			
		||||
        <div class="post-content-container">
 | 
			
		||||
          <div class="post-info">
 | 
			
		||||
            <% local post_url = get_post_url(post.id) %>
 | 
			
		||||
            <a href="<%= post_url %>" title="Permalink"><i>
 | 
			
		||||
              <% if tonumber(post.edited_at) > tonumber(post.created_at) then -%>
 | 
			
		||||
                Edited at <% render("views.common.timestamp", {timestamp = post.edited_at}) -%> in <%= post.thread_title %>
 | 
			
		||||
              <% else -%>
 | 
			
		||||
                Posted on <% render("views.common.timestamp", {timestamp = post.created_at}) -%> in <%= post.thread_title %>
 | 
			
		||||
              <% end -%>
 | 
			
		||||
            </i></a>
 | 
			
		||||
          </div>
 | 
			
		||||
          <div class="post-content wider user-page-post-preview">
 | 
			
		||||
            <div class="post-inner"><%- post.content %></div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
      <% end %>
 | 
			
		||||
    <% end %>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
<% end %>
 | 
			
		||||
</div>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user