Add redirect response to signup success.

This commit is contained in:
Joe Ardent 2023-05-19 15:13:49 -07:00
parent fee7fff3df
commit ebfc759fa6
2 changed files with 20 additions and 4 deletions

View file

@ -4,7 +4,7 @@ use axum::{routing::get, Router};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use witch_watch::{
db,
users::{get_create_user, post_create_user},
users::{get_create_user, get_signup_success, post_create_user},
};
#[tokio::main]
@ -22,6 +22,7 @@ async fn main() {
// build our application with some routes
let app = Router::new()
.route("/signup", get(get_create_user).post(post_create_user))
.route("/signup_success", get(get_signup_success))
.with_state(pool);
tracing::debug!("binding to 0.0.0.0:3000");

View file

@ -8,7 +8,7 @@ use askama::Template;
use axum::{
extract::{Form, State},
http::StatusCode,
response::IntoResponse,
response::{IntoResponse, Response},
};
use sqlx::SqlitePool;
use unicode_segmentation::UnicodeSegmentation;
@ -76,7 +76,7 @@ pub async fn get_create_user() -> CreateUser {
pub async fn post_create_user(
State(pool): State<SqlitePool>,
Form(signup): Form<CreateUser>,
) -> Result<CreateUserSuccess, CreateUserError> {
) -> Result<Response, CreateUserError> {
let username = &signup.username;
let displayname = &signup.displayname;
let email = &signup.email;
@ -122,7 +122,22 @@ pub async fn post_create_user(
let user = create_user(username, displayname, email, password, &pool).await?;
tracing::debug!("created {user:?}");
Ok(CreateUserSuccess(user))
let mut resp = axum::response::Redirect::temporary("/signup_success").into_response();
resp.headers_mut().append(
"X-Witch-Success",
user.id.simple().to_string().parse().unwrap(),
);
Ok(resp)
}
pub async fn get_signup_success(
headers: axum::http::HeaderMap,
State(pool): State<SqlitePool>,
) -> CreateUserSuccess {
if let Some(id) = headers.get("X-Witch") {
todo!()
}
todo!()
}
async fn create_user(