pub async fn signup(mut req: tide::Request<Database>) -> tide::Result {
    let form: SignupForm = match req.body_json().await {
        Ok(parsed) => parsed,
        Err(_) => {
            return Ok(Response::builder(StatusCode::BadRequest)
                .body("email and password are required")
                .build())
        }
    };

    let db = req.state();

    if Person::exists_by_email(db, &form.email).await? {
        return Ok(Response::builder(StatusCode::Forbidden)
            .body("That email is already in use")
            .build());
    }

    let mut person = Person::default();
    person.set_password(&form.password);
    person.exterior.username = form.username;
    person.interior.email = form.email;
    person.interior.zip_code = form.zip_code;
    person.interior.phone = form.phone;
    person.interior.newsletter = form.newsletter.unwrap_or(false);
    person.store(db).await?;

    let jwt = issue_jwt(&person.exterior.uid, &UI_AUDIENCE, SESSION_HOURS as u64)?;

    let mut p_json = person_json(&person, &jwt);
    p_json["num_partners"] = 0.into();

    common::log("ui-signup", &jwt);
    person.log(db, LogEvent::Signup).await?;

    okay_with_cookie(
        &p_json,
        Cookie::build(TOKEN_COOKIE, jwt)
            .path("/")
            .max_age(Duration::hours(SESSION_HOURS))
            //.domain(&*COOKIE_DOMAIN)
            .secure(cfg!(not(debug_assertions))) // Allow HTTP when in debug mode, require HTTPS in release mode
            .http_only(true)
            .same_site(tide::http::cookies::SameSite::Lax)
            .finish(),
    )
}
/// Create an account, if the validations pass.
///
/// Set a token cookie with the HttpOnly, SameSite=Lax, and (when
/// ```#[cfg(not(debug_assertions))]```) Secure flags, and also
/// return the token in the response body for script use.
Create an account, if the validations pass.
Create an account if the validations pass .
pub async fn signup(mut req: tide::Request<Database>) -> tide::Result {
    let form: SignupForm = match req.body_json().await {
        Ok(parsed) => parsed,
        Err(_) => {
            return Ok(Response::builder(StatusCode::BadRequest)
                .body("email and password are required")
                .build())
        }
    };
    let db = req.state();
    if Person::exists_by_email(db, &form.email).await? {
        return Ok(Response::builder(StatusCode::Forbidden)
            .body("That email is already in use")
            .build());
    }
    let mut person = Person::default();
    person.set_password(&form.password);
    person.exterior.username = form.username;
    person.interior.email = form.email;
    person.interior.zip_code = form.zip_code;
    person.interior.phone = form.phone;
    person.interior.newsletter = form.newsletter.unwrap_or(false);
    person.store(db).await?;
    let jwt = issue_jwt(&person.exterior.uid, &UI_AUDIENCE, SESSION_HOURS as u64)?;
    let mut p_json = person_json(&person, &jwt);
    p_json["num_partners"] = 0.into();
    common::log("ui-signup", &jwt);
    person.log(db, LogEvent::Signup).await?;
    okay_with_cookie(
        &p_json,
        Cookie::build(TOKEN_COOKIE, jwt)
            .path("/")
            .max_age(Duration::hours(SESSION_HOURS))
            //.domain(&*COOKIE_DOMAIN)
            .secure(cfg!(not(debug_assertions))) // Allow HTTP when in debug mode, require HTTPS in release mode
            .http_only(true)
            .same_site(tide::http::cookies::SameSite::Lax)
            .finish(),
    )
}
pub async fn signup ( mut req : tide :: Request < Database > ) -> tide :: Result { let form : SignupForm = match req . body_json ( ) . await { Ok ( parsed ) => parsed , Err ( _ ) => { return Ok ( Response :: builder ( StatusCode :: BadRequest ) . body ( " " ) . build ( ) ) } } ; let db = req . state ( ) ; if Person :: exists_by_email ( db , & form . email ) . await ? { return Ok ( Response :: builder ( StatusCode :: Forbidden ) . body ( " " ) . build ( ) ) ; } let mut person = Person :: default ( ) ; person . set_password ( & form . password ) ; person . exterior . username = form . username ; person . interior . email = form . email ; person . interior . zip_code = form . zip_code ; person . interior . phone = form . phone ; person . interior . newsletter = form . newsletter . unwrap_or ( false ) ; person . store ( db ) . await ? ; let jwt = issue_jwt ( & person . exterior . uid , & UI_AUDIENCE , SESSION_HOURS as u64 ) ? ; let mut p_json = person_json ( & person , & jwt ) ; p_json [ " " ] = 0 . into ( ) ; common :: log ( " " , & jwt ) ; person . log ( db , LogEvent :: Signup ) . await ? ; okay_with_cookie ( & p_json , Cookie :: build ( TOKEN_COOKIE , jwt ) . path ( " " ) . max_age ( Duration :: hours ( SESSION_HOURS ) ) //.domain(&*COOKIE_DOMAIN) . secure ( cfg ! ( not ( debug_assertions ) ) ) // Allow HTTP when in debug mode, require HTTPS in release mode . http_only ( true ) . same_site ( tide :: http :: cookies :: SameSite :: Lax ) . finish ( ) , ) }
Create an account, if the validations pass.
Create an account if the validations pass .
req
tide::Request<Database>
req
tide::Request<Database>