Require authentication for creating blog + Fix utils::make_actor_id
This commit is contained in:
parent
9130f4d848
commit
00e5f28d0b
@ -7,6 +7,7 @@ use utils;
|
|||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blogs::*;
|
use models::blogs::*;
|
||||||
use models::instance::Instance;
|
use models::instance::Instance;
|
||||||
|
use models::user::User;
|
||||||
|
|
||||||
#[get("/~/<name>")]
|
#[get("/~/<name>")]
|
||||||
fn details(name: String) -> String {
|
fn details(name: String) -> String {
|
||||||
@ -14,7 +15,7 @@ fn details(name: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/blogs/new")]
|
#[get("/blogs/new")]
|
||||||
fn new() -> Template {
|
fn new(_user: User) -> Template {
|
||||||
Template::render("blogs/new", HashMap::<String, i32>::new())
|
Template::render("blogs/new", HashMap::<String, i32>::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ struct NewBlogForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/blogs/new", data = "<data>")]
|
#[post("/blogs/new", data = "<data>")]
|
||||||
fn create(conn: DbConn, data: Form<NewBlogForm>) -> Redirect {
|
fn create(conn: DbConn, data: Form<NewBlogForm>, _user: User) -> Redirect {
|
||||||
let inst = Instance::get_local(&*conn).unwrap();
|
let inst = Instance::get_local(&*conn).unwrap();
|
||||||
let form = data.get();
|
let form = data.get();
|
||||||
let slug = utils::make_actor_id(form.title.to_string());
|
let slug = utils::make_actor_id(form.title.to_string());
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
use heck::CamelCase;
|
use heck::CamelCase;
|
||||||
|
|
||||||
|
/// Remove non alphanumeric characters and CamelCase a string
|
||||||
pub fn make_actor_id(name: String) -> 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()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user