better delete
This commit is contained in:
parent
7a5391498b
commit
3d0108367a
5 changed files with 79 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -6,3 +6,5 @@
|
|||
/invites
|
||||
/webname.txt
|
||||
/root
|
||||
/banner.html
|
||||
/infotext.html
|
||||
|
|
|
|||
51
src/html/delete.html
Normal file
51
src/html/delete.html
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<!--
|
||||
placeholders:
|
||||
webname: holds the site name
|
||||
title: holds the post title
|
||||
editscreen: holds the edit screen html
|
||||
posts: holds the post list html
|
||||
|
||||
-->
|
||||
|
||||
<html>
|
||||
HEADER
|
||||
<body>
|
||||
<a href="/" class="homebtn button">Home</a>
|
||||
BANNER
|
||||
<div class="posts">
|
||||
<post>
|
||||
<div class=content>
|
||||
<h3> Delete account: USERNAME </h3>
|
||||
|
||||
<b>Warning: </b> This action cannot be undone.
|
||||
<p>
|
||||
The following will be deleted/invalidated:
|
||||
<ul>
|
||||
<li>All of your posts</li>
|
||||
<li>Your invite</li>
|
||||
<li>Your account data</li>
|
||||
</ul>
|
||||
The following will stay:
|
||||
<ul>
|
||||
<li>Everyone you invited</li>
|
||||
<li>A record of who invited you</li>
|
||||
<li>Your username (but only the admin can see it)</li>
|
||||
</ul>
|
||||
You or anyone else will not be able to create new accounts
|
||||
with your invite. A user with your username can never exist
|
||||
again.
|
||||
</div>
|
||||
</post>
|
||||
<post>
|
||||
<div class=content>
|
||||
<form method=POST>
|
||||
<label for=confirm>Click to delete your account:</label>
|
||||
<p>
|
||||
<input class=button name=confirm type=submit value="Delete account">
|
||||
</form>
|
||||
</div>
|
||||
</post>
|
||||
</div>
|
||||
<body>
|
||||
<html>
|
||||
|
||||
|
|
@ -12,6 +12,7 @@ const POST_PREVIEW: &str = include_str!("post_preview.html");
|
|||
const POSTVIEW: &str = include_str!("postview.html");
|
||||
const INDEX: &str = include_str!("index.html");
|
||||
const LOGIN: &str = include_str!("login.html");
|
||||
const DELETE: &str = include_str!("delete.html");
|
||||
|
||||
static WEBNAME: LazyLock<String> =
|
||||
LazyLock::new(|| fs::read_to_string("webname.txt").unwrap().trim().to_owned());
|
||||
|
|
@ -188,6 +189,20 @@ pub fn login(acct: Option<Account>, loginfail: bool, regfail: bool, inviteprefil
|
|||
.replace("INVITEPREFILL", inviteprefill)
|
||||
}
|
||||
|
||||
pub fn delete(acct: Option<Account>) -> String {
|
||||
prep(DELETE)
|
||||
.replace("SAFETITLE", "Delete account")
|
||||
.replace("TITLE", "Delete")
|
||||
.replace(
|
||||
"USERNAME",
|
||||
&if let Some(acct) = acct.as_ref() {
|
||||
acct.name.to_owned()
|
||||
} else {
|
||||
"- not logged in -".to_owned()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn index(acct: Option<Account>) -> String {
|
||||
prep(INDEX)
|
||||
.replace("SAFETITLE", "Index")
|
||||
|
|
|
|||
|
|
@ -80,14 +80,11 @@ impl ConnectionState for GetHandler {
|
|||
));
|
||||
}
|
||||
if path == "/delete" {
|
||||
if let Some(acct) = get_login(&cookies) {
|
||||
acct.delete();
|
||||
}
|
||||
return Some(Box::new(
|
||||
ResponseWriter::new()
|
||||
.with_header("Content-Type", "text/html")
|
||||
.with_header("Cache-Control", "max-age=0, must-revalidate")
|
||||
.with_body(html::index(get_login(&cookies)).into_bytes()),
|
||||
.with_body(html::delete(get_login(&cookies)).into_bytes()),
|
||||
));
|
||||
}
|
||||
if path == "/" {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,16 @@ impl ConnectionState for PostHandler {
|
|||
.map(|x| x.as_str())
|
||||
.unwrap_or(""),
|
||||
);
|
||||
if path == "/delete" {
|
||||
if let Some(acct) = get_login(&cookies) {
|
||||
acct.delete();
|
||||
}
|
||||
return Some(Box::new(
|
||||
ResponseWriter::new()
|
||||
.with_status(302, "Found")
|
||||
.with_header("Location", "/"),
|
||||
));
|
||||
}
|
||||
if let Some(account) = get_login(&cookies) {
|
||||
if let Some(parent) = Post::get_by_gid(query)
|
||||
&& let Some(title) = body.get("title")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue