diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index a4037ec2..5baf85b5 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -530,6 +530,7 @@ impl NewBlog { title: String, summary: String, instance_id: i32, + custom_domain: Option, ) -> Result { let (pub_key, priv_key) = sign::gen_keypair(); Ok(NewBlog { @@ -539,6 +540,7 @@ impl NewBlog { instance_id, public_key: String::from_utf8(pub_key).or(Err(Error::Signature))?, private_key: Some(String::from_utf8(priv_key).or(Err(Error::Signature))?), + custom_domain, ..NewBlog::default() }) } @@ -566,6 +568,7 @@ pub(crate) mod tests { "Blog name".to_owned(), "This is a small blog".to_owned(), Instance::get_local().unwrap().id, + None, ) .unwrap(), ) @@ -577,6 +580,7 @@ pub(crate) mod tests { "My blog".to_owned(), "Welcome to my blog".to_owned(), Instance::get_local().unwrap().id, + Some(Host::new("blog.myname.me")), ) .unwrap(), ) @@ -588,6 +592,7 @@ pub(crate) mod tests { "Why I like Plume".to_owned(), "In this blog I will explay you why I like Plume so much".to_owned(), Instance::get_local().unwrap().id, + None, ) .unwrap(), ) @@ -648,6 +653,7 @@ pub(crate) mod tests { "Some name".to_owned(), "This is some blog".to_owned(), Instance::get_local().unwrap().id, + Some(Host::new("some.blog.com")), ) .unwrap(), ) @@ -676,6 +682,7 @@ pub(crate) mod tests { "Some name".to_owned(), "This is some blog".to_owned(), Instance::get_local().unwrap().id, + None, ) .unwrap(), ) @@ -687,6 +694,7 @@ pub(crate) mod tests { "Blog".to_owned(), "I've named my blog Blog".to_owned(), Instance::get_local().unwrap().id, + Some(Host::new("named.example.blog")), ) .unwrap(), ) @@ -779,6 +787,7 @@ pub(crate) mod tests { "Some name".to_owned(), "This is some blog".to_owned(), Instance::get_local().unwrap().id, + None, ) .unwrap(), ) @@ -803,6 +812,7 @@ pub(crate) mod tests { "Some name".to_owned(), "This is some blog".to_owned(), Instance::get_local().unwrap().id, + Some(Host::new("some.blog.com")), ) .unwrap(), ) @@ -841,6 +851,7 @@ pub(crate) mod tests { "Some name".to_owned(), "This is some blog".to_owned(), Instance::get_local().unwrap().id, + None, ) .unwrap(), ) @@ -852,6 +863,7 @@ pub(crate) mod tests { "Blog".to_owned(), "I've named my blog Blog".to_owned(), Instance::get_local().unwrap().id, + Some(Host::new("my.blog.com")), ) .unwrap(), ) diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index b5edf6c5..53a3cc18 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -136,6 +136,7 @@ pub fn new_auth(i18n: I18n) -> Flash { pub struct NewBlogForm { #[validate(custom(function = "valid_slug", message = "Invalid name"))] pub title: String, + pub custom_domain: String, } fn valid_slug(title: &str) -> Result<(), ValidationError> { @@ -154,6 +155,12 @@ pub fn create(form: LenientForm, rockets: PlumeRocket) -> RespondOr let intl = &rockets.intl.catalog; let user = rockets.user.clone().unwrap(); + let custom_domain = if *(&form.custom_domain.is_empty()) { + None + } else { + Some(Host::new(*(&form.custom_domain))) + }; + let mut errors = match form.validate() { Ok(_) => ValidationErrors::new(), Err(e) => e, @@ -185,6 +192,7 @@ pub fn create(form: LenientForm, rockets: PlumeRocket) -> RespondOr Instance::get_local() .expect("blog::create: instance error") .id, + custom_domain, ) .expect("blog::create: new local error"), ) diff --git a/templates/blogs/new.rs.html b/templates/blogs/new.rs.html index b9a186b1..6a22f734 100644 --- a/templates/blogs/new.rs.html +++ b/templates/blogs/new.rs.html @@ -11,5 +11,8 @@
@input!(ctx.1, title (text), "Title", form, errors, "required minlength=\"1\"") + + @input!(ctx.1, custom_domain (optional text), "Custom Domain", form, errors.clone(), "") +
})