Allow editing blogs with custom_domain

n.b.: no validation yet
This commit is contained in:
Igor Galić 2019-08-20 12:24:36 +02:00
parent df47cddb87
commit 064dd79eef
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86
2 changed files with 13 additions and 1 deletions

View File

@ -8,8 +8,9 @@ use openssl::{
sign::{Signer, Verifier},
};
use rocket::{
http::RawStr,
outcome::IntoOutcome,
request::{self, FromRequest, Request},
request::{self, FromFormValue, FromRequest, Request},
};
use serde_json;
use url::Url;
@ -71,6 +72,15 @@ impl<'a, 'r> FromRequest<'a, 'r> for Host {
}
}
impl<'v> FromFormValue<'v> for Host {
type Error = &'v RawStr;
fn from_form_value(form_value: &'v RawStr) -> std::result::Result<Host, &'v RawStr> {
let val = String::from_form_value(form_value)?;
Ok(Host::new(&val))
}
}
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
#[changeset_options(treat_none_as_null = "true")]
pub struct Blog {

View File

@ -333,6 +333,7 @@ pub struct EditForm {
pub summary: String,
pub icon: Option<i32>,
pub banner: Option<i32>,
pub custom_domain: Option<Host>,
}
#[get("/~/<name>/edit")]
@ -359,6 +360,7 @@ pub fn edit(name: String, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
summary: blog.summary.clone(),
icon: blog.icon_id,
banner: blog.banner_id,
custom_domain: blog.custom_domain.clone(),
},
ValidationErrors::default()
)))