|
@@ -25,17 +25,12 @@ pub async fn index(req: Request<()>) -> Result {
|
25
|
25
|
}
|
26
|
26
|
|
27
|
27
|
pub async fn create_post(mut req: Request<()>) -> Result {
|
28
|
|
- let logged_in: bool = req.session().get("logged_in").unwrap_or(false);
|
29
|
|
- if !logged_in {
|
30
|
|
- Ok(tide::Redirect::new("/login").into())
|
31
|
|
- } else {
|
32
|
|
- let mut post: Post = req.body_form().await?;
|
33
|
|
- post.id = Uuid::new_v4().to_string();
|
34
|
|
- post.date = Local::now().date().naive_local().to_string();
|
35
|
|
- post.body = post.body.trim().to_owned();
|
36
|
|
- post.save().await?;
|
37
|
|
- Ok(tide::Redirect::new("/").into())
|
38
|
|
- }
|
|
28
|
+ let mut post: Post = req.body_form().await?;
|
|
29
|
+ post.id = Uuid::new_v4().to_string();
|
|
30
|
+ post.date = Local::now().date().naive_local().to_string();
|
|
31
|
+ post.body = post.body.trim().to_owned();
|
|
32
|
+ post.save().await?;
|
|
33
|
+ Ok(tide::Redirect::new("/").into())
|
39
|
34
|
}
|
40
|
35
|
|
41
|
36
|
pub async fn single_post(req: Request<()>) -> Result {
|
|
@@ -50,17 +45,13 @@ pub async fn single_post(req: Request<()>) -> Result {
|
50
|
45
|
|
51
|
46
|
pub async fn edit_post(req: Request<()>) -> Result {
|
52
|
47
|
let logged_in: bool = req.session().get("logged_in").unwrap_or(false);
|
53
|
|
- if !logged_in {
|
54
|
|
- Ok(tide::Redirect::new("/login").into())
|
55
|
|
- } else {
|
56
|
|
- let mut context = Context::new();
|
57
|
|
- context.insert("logged_in", &logged_in);
|
58
|
|
- let post_id = req.param("id")?;
|
59
|
|
- let mut post = fs::get_one_post(post_id).await?;
|
60
|
|
- post.body = post.body.replace("<br>", "\n");
|
61
|
|
- context.insert("post", &post);
|
62
|
|
- render_response("edit.html", &context)
|
63
|
|
- }
|
|
48
|
+ let mut context = Context::new();
|
|
49
|
+ context.insert("logged_in", &logged_in);
|
|
50
|
+ let post_id = req.param("id")?;
|
|
51
|
+ let mut post = fs::get_one_post(post_id).await?;
|
|
52
|
+ post.body = post.body.replace("<br>", "\n");
|
|
53
|
+ context.insert("post", &post);
|
|
54
|
+ render_response("edit.html", &context)
|
64
|
55
|
}
|
65
|
56
|
|
66
|
57
|
pub async fn login_page(mut req: Request<()>) -> Result {
|