start modifying /blogs/new to add custom_domain to the form

This commit is contained in:
Igor Galić
2019-07-30 23:57:17 +02:00
committed by Igor Galić
parent b172a80e35
commit 2dedcdbc53
3 changed files with 23 additions and 0 deletions
+8
View File
@@ -136,6 +136,7 @@ pub fn new_auth(i18n: I18n) -> Flash<Redirect> {
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<NewBlogForm>, 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<NewBlogForm>, rockets: PlumeRocket) -> RespondOr
Instance::get_local()
.expect("blog::create: instance error")
.id,
custom_domain,
)
.expect("blog::create: new local error"),
)