add user signatures
This commit is contained in:
		
							
								
								
									
										6
									
								
								app.lua
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								app.lua
									
									
									
									
									
								
							@@ -1,6 +1,8 @@
 | 
			
		||||
local lapis = require("lapis")
 | 
			
		||||
local app = lapis.Application()
 | 
			
		||||
local constants = require("constants")
 | 
			
		||||
local babycode = require("lib.babycode")
 | 
			
		||||
local html_escape = require("lapis.html").escape
 | 
			
		||||
 | 
			
		||||
local db = require("lapis.db")
 | 
			
		||||
-- sqlite starts without foreign key enforcement
 | 
			
		||||
@@ -26,6 +28,10 @@ local function inject_methods(req)
 | 
			
		||||
  req.infobox_message = function (_, s)
 | 
			
		||||
    return util.infobox_message(s)
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  req.babycode_to_html = function (_, bb)
 | 
			
		||||
    return babycode.to_html(bb, html_escape)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  util.pop_infobox(req)
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,6 @@
 | 
			
		||||
local app = require("lapis").Application()
 | 
			
		||||
local babycode = require("lib.babycode")
 | 
			
		||||
local html_escape = require("lapis.html").escape
 | 
			
		||||
 | 
			
		||||
local db = require("lapis.db")
 | 
			
		||||
local constants = require("constants")
 | 
			
		||||
@@ -225,11 +227,15 @@ app:post("user_settings", "/:username/settings", function(self)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  local status = self.params.status:sub(1, 100)
 | 
			
		||||
  local original_sig = self.params.signature or ""
 | 
			
		||||
  local rendered_sig = babycode.to_html(original_sig, html_escape)
 | 
			
		||||
 | 
			
		||||
  target_user:update({
 | 
			
		||||
    status = status,
 | 
			
		||||
    signature_original_markup = original_sig,
 | 
			
		||||
    signature_rendered = rendered_sig,
 | 
			
		||||
  })
 | 
			
		||||
  util.inject_infobox(self, "Status updated.")
 | 
			
		||||
  util.inject_infobox(self, "Settings updated.")
 | 
			
		||||
  return {redirect_to = self:url_for("user_settings", {username = self.params.username})}
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ Constants.PermissionLevel = {
 | 
			
		||||
 | 
			
		||||
Constants.FULL_POSTS_QUERY = [[
 | 
			
		||||
  SELECT
 | 
			
		||||
    posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup
 | 
			
		||||
    posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup, users.signature_rendered
 | 
			
		||||
  FROM
 | 
			
		||||
    posts
 | 
			
		||||
  JOIN
 | 
			
		||||
 
 | 
			
		||||
@@ -107,6 +107,12 @@ body {
 | 
			
		||||
  grid-area: post-content;
 | 
			
		||||
  padding: 20px;
 | 
			
		||||
  margin-right: 25%;
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.post-inner {
 | 
			
		||||
  height: 100%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pre code {
 | 
			
		||||
 
 | 
			
		||||
@@ -68,4 +68,9 @@ return {
 | 
			
		||||
    schema.add_column("post_history", "original_markup", types.text{null = false})
 | 
			
		||||
    schema.add_column("post_history", "markup_language", types.text{default = "babycode"})
 | 
			
		||||
  end,
 | 
			
		||||
  
 | 
			
		||||
  [10] = function ()
 | 
			
		||||
    schema.add_column("users", "signature_original_markup", types.text{default = ""})
 | 
			
		||||
    schema.add_column("users", "signature_rendered", types.text{default = ""})
 | 
			
		||||
  end,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -143,6 +143,12 @@ body {
 | 
			
		||||
  grid-area: post-content;
 | 
			
		||||
  padding: 20px;
 | 
			
		||||
  margin-right: 25%;
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.post-inner {
 | 
			
		||||
  height: 100%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pre code {
 | 
			
		||||
 
 | 
			
		||||
@@ -4,5 +4,5 @@
 | 
			
		||||
  <button type=button id="post-editor-strike" title="Insert Strikethrough">S</button>
 | 
			
		||||
  <button type=button id="post-editor-code" title="Insert Code block">Code</button>
 | 
			
		||||
</span>
 | 
			
		||||
<textarea class="babycode-editor" name="<%= ta_name %>" id="post_content" placeholder="Post body" required><%- prefill or "" %></textarea>
 | 
			
		||||
<textarea class="babycode-editor" name="<%= ta_name %>" id="<%= ta_id or "post_content" %>" placeholder="<%= ta_placeholder or "Post body"%>" <%= not optional and "required" or "" %>><%- prefill or "" %></textarea>
 | 
			
		||||
<script src="/static/js/post-editor.js"></script>
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,15 @@
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="post-content">
 | 
			
		||||
      <% if not edit then %>
 | 
			
		||||
        <div class="post-inner">
 | 
			
		||||
        <%- post.content %>
 | 
			
		||||
        </div>
 | 
			
		||||
        <% if render_sig and #post.signature_rendered > 0 then %>
 | 
			
		||||
          <div class="signature-container">
 | 
			
		||||
            <hr>
 | 
			
		||||
            <%- post.signature_rendered %>
 | 
			
		||||
          </div>
 | 
			
		||||
        <% end %>
 | 
			
		||||
      <% else %>
 | 
			
		||||
        <% render("views.common.babycode-editor", {
 | 
			
		||||
          cancel_url = post_url,
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@
 | 
			
		||||
    <span>Posted in <a href="<%= url_for("topic", {slug = topic.slug}) %>"><%= topic.name %></a></span>
 | 
			
		||||
  </nav>
 | 
			
		||||
  <% for i, post in ipairs(posts) do %>
 | 
			
		||||
    <% render("views.threads.post", {post = post, is_latest = i == #posts}) %>
 | 
			
		||||
    <% render("views.threads.post", {post = post, render_sig = true, is_latest = i == #posts}) %>
 | 
			
		||||
  <% end %>
 | 
			
		||||
</main>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@
 | 
			
		||||
    <img src="<%= avatar_url(me) %>">
 | 
			
		||||
    <input id="file" type="file" name="avatar" accept="image/*" required>
 | 
			
		||||
    <div>
 | 
			
		||||
    <input type="submit" value="Update avatar" <%= disable_avatar and "disabled=disabled" %>>
 | 
			
		||||
    <input type="submit" value="Upload avatar" <%= disable_avatar and "disabled=disabled" %>>
 | 
			
		||||
  <% if not me:is_default_avatar() then %>
 | 
			
		||||
    <input type="submit" value="Clear avatar" formaction="<%= url_for("user_clear_avatar", {username = me.username}) %>" formnovalidate>
 | 
			
		||||
  <% end %>
 | 
			
		||||
@@ -16,8 +16,10 @@
 | 
			
		||||
  </form>
 | 
			
		||||
  <form method="post" action="">
 | 
			
		||||
    <label for="status">Status</label>
 | 
			
		||||
    <input type="text" id="status" name="status" value="<%= me.status %>" maxlength="30">
 | 
			
		||||
    <input type="submit" value="Save status">
 | 
			
		||||
    <input type="text" id="status" name="status" value="<%= me.status %>" maxlength="70" placeholder="Will be shown under your username. Max 70 characters">
 | 
			
		||||
    <label for="signature">Signature</label><br>
 | 
			
		||||
    <% render("views.common.babycode-editor-component", {ta_name = "signature", ta_id = "signature", prefill = me.signature_original_markup, ta_placeholder = "Will be shown under each of your posts", optional = true}) %>
 | 
			
		||||
    <input type="submit" value="Save settings">
 | 
			
		||||
  </form>
 | 
			
		||||
  <div>
 | 
			
		||||
  <a class="linkbutton critical" href="<%= url_for("user_delete_confirm", {username = me.username}) %>">Delete account</a>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user