From 00e5f28d0b1b500b63e87441f31b91ec7979050c Mon Sep 17 00:00:00 2001 From: Bat Date: Mon, 23 Apr 2018 12:10:15 +0100 Subject: [PATCH] Require authentication for creating blog + Fix utils::make_actor_id --- src/routes/blogs.rs | 5 +++-- src/utils.rs | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 5b587cd4..9ddc6221 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -7,6 +7,7 @@ use utils; use db_conn::DbConn; use models::blogs::*; use models::instance::Instance; +use models::user::User; #[get("/~/")] fn details(name: String) -> String { @@ -14,7 +15,7 @@ fn details(name: String) -> String { } #[get("/blogs/new")] -fn new() -> Template { +fn new(_user: User) -> Template { Template::render("blogs/new", HashMap::::new()) } @@ -24,7 +25,7 @@ struct NewBlogForm { } #[post("/blogs/new", data = "")] -fn create(conn: DbConn, data: Form) -> Redirect { +fn create(conn: DbConn, data: Form, _user: User) -> Redirect { let inst = Instance::get_local(&*conn).unwrap(); let form = data.get(); let slug = utils::make_actor_id(form.title.to_string()); diff --git a/src/utils.rs b/src/utils.rs index 0c5495af..1b87bf66 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,11 @@ use heck::CamelCase; +/// Remove non alphanumeric characters and CamelCase a string pub fn make_actor_id(name: String) -> String { - name.as_str().to_camel_case() + name.as_str() + .to_camel_case() + .to_string() + .chars() + .filter(|c| c.is_alphanumeric()) + .collect() }