Compare commits
2 Commits
aa49d8e4b9
...
cf66336e78
Author | SHA1 | Date | |
---|---|---|---|
cf66336e78 | |||
8e646666d1 |
9
app.lua
9
app.lua
@ -17,8 +17,13 @@ app.layout = require "views.base"
|
|||||||
|
|
||||||
app.cookie_attributes = function (self, name, value)
|
app.cookie_attributes = function (self, name, value)
|
||||||
if name == config.session_name then
|
if name == config.session_name then
|
||||||
local expires = date(true):adddays(30):fmt("${http}")
|
if not self.session.queue_delete then
|
||||||
return "Expires="..expires.."; Path=/; HttpOnly; Secure"
|
local expires = date(true):adddays(30):fmt("${http}")
|
||||||
|
return "Expires="..expires.."; Path=/; HttpOnly; Secure"
|
||||||
|
else
|
||||||
|
local expires = date(true):addseconds(-30):fmt("${http}")
|
||||||
|
return "Expires="..expires.."; Path=/; HttpOnly; Secure"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@ app:get("thread", "/:slug", function(self)
|
|||||||
"WHERE posts.thread_id = ? ORDER BY posts.created_at ASC LIMIT ? OFFSET ?")
|
"WHERE posts.thread_id = ? ORDER BY posts.created_at ASC LIMIT ? OFFSET ?")
|
||||||
local posts = db.query(query, thread.id, POSTS_PER_PAGE, (self.page - 1) * POSTS_PER_PAGE)
|
local posts = db.query(query, thread.id, POSTS_PER_PAGE, (self.page - 1) * POSTS_PER_PAGE)
|
||||||
self.topic = Topics:find(thread.topic_id)
|
self.topic = Topics:find(thread.topic_id)
|
||||||
|
self.other_topics = db.query("SELECT topics.id, topics.name FROM topics")
|
||||||
self.me = util.get_logged_in_user_or_transient(self)
|
self.me = util.get_logged_in_user_or_transient(self)
|
||||||
self.posts = posts
|
self.posts = posts
|
||||||
|
|
||||||
@ -169,4 +170,40 @@ app:post("thread_sticky", "/:slug/sticky", function(self)
|
|||||||
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
app:post("thread_move", "/:slug/move", function(self)
|
||||||
|
local user = util.get_logged_in_user(self)
|
||||||
|
if not user then
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||||
|
end
|
||||||
|
|
||||||
|
if not user:is_mod() then
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||||
|
end
|
||||||
|
|
||||||
|
if not self.params.new_topic_id then
|
||||||
|
util.inject_err_infobox(self, "Thread already in this topic.")
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||||
|
end
|
||||||
|
|
||||||
|
local new_topic = Topics:find({id = self.params.new_topic_id})
|
||||||
|
if not new_topic then
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||||
|
end
|
||||||
|
local thread = Threads:find({slug = self.params.slug})
|
||||||
|
if not thread then
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||||
|
end
|
||||||
|
if new_topic.id == thread.topic_id then
|
||||||
|
util.inject_err_infobox(self, "Thread already in this topic.")
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||||
|
end
|
||||||
|
|
||||||
|
local old_topic = Topics:find({id = thread.topic_id})
|
||||||
|
|
||||||
|
thread:update({topic_id = new_topic.id})
|
||||||
|
util.inject_infobox(self, ("Thread moved from \"%s\" to \"%s\"."):format(old_topic.name, new_topic.name))
|
||||||
|
|
||||||
|
return {redirect_to = self:url_for("thread", {slug = self.params.slug})}
|
||||||
|
end)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
@ -126,8 +126,10 @@ app:post("user_delete", "/:username/delete", function(self)
|
|||||||
return {redirect_to = self:url_for("user_delete_confirm", {username = me.username})}
|
return {redirect_to = self:url_for("user_delete_confirm", {username = me.username})}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local session = Sessions:find({key = self.session.session_key})
|
||||||
|
session:delete()
|
||||||
|
self.session.queue_delete = true
|
||||||
util.transfer_and_delete_user(target_user)
|
util.transfer_and_delete_user(target_user)
|
||||||
util.inject_infobox(self, "Your account has been added to the deletion queue.")
|
|
||||||
return {redirect_to = self:url_for("user_signup")}
|
return {redirect_to = self:url_for("user_signup")}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -379,7 +381,7 @@ app:post("user_logout", "/logout", function (self)
|
|||||||
|
|
||||||
local session = Sessions:find({key = self.session.session_key})
|
local session = Sessions:find({key = self.session.session_key})
|
||||||
session:delete()
|
session:delete()
|
||||||
self.session = nil
|
self.session.queue_delete = true
|
||||||
return {redirect_to = self:url_for("user_login")}
|
return {redirect_to = self:url_for("user_login")}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -25,6 +25,15 @@
|
|||||||
<input type=hidden value="<%= not is_stickied %>" name="target_op">
|
<input type=hidden value="<%= not is_stickied %>" name="target_op">
|
||||||
<input class="warn" type="submit" value="<%= is_stickied and "Unsticky thread" or "Sticky thread" %>">
|
<input class="warn" type="submit" value="<%= is_stickied and "Unsticky thread" or "Sticky thread" %>">
|
||||||
</form>
|
</form>
|
||||||
|
<form class="modform" action="<%= url_for("thread_move", {slug = thread.slug}) %>" method="post">
|
||||||
|
<label for="new_topic_id">Move to topic:</label>
|
||||||
|
<select style="width:200px;" id="new_topic_id" name="new_topic_id" autocomplete="off">
|
||||||
|
<% for _, topic in ipairs(other_topics) do %>
|
||||||
|
<option value="<%= topic.id %>" <%- thread.topic_id == topic.id and "selected disabled" or "" %>><%= topic.name %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
<input class="warn" type="submit" value="Move thread">
|
||||||
|
</form>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
Loading…
Reference in New Issue
Block a user