diff --git a/admin_frontend/assets/base.css b/admin_frontend/assets/base.css index 79e17dc5..5d849085 100644 --- a/admin_frontend/assets/base.css +++ b/admin_frontend/assets/base.css @@ -17,11 +17,10 @@ body { .button { border: none; border-radius: 4px; - margin: 4px 4px; + margin: 4px; padding: 4px 8px; font-size: 16px; cursor: pointer; - margin: auto; } .purple:hover { diff --git a/admin_frontend/src/response.rs b/admin_frontend/src/response.rs index 6bb32622..697a0ee1 100644 --- a/admin_frontend/src/response.rs +++ b/admin_frontend/src/response.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use axum::{response::IntoResponse, Json}; #[derive(serde::Serialize)] @@ -6,7 +8,7 @@ where T: serde::Serialize, { pub code: i16, - pub message: String, + pub message: Cow<'static, str>, pub data: T, } @@ -14,10 +16,10 @@ impl WebApiResponse where T: serde::Serialize, { - pub fn new(data: T) -> Self { + pub fn new(message: Cow<'static, str>, data: T) -> Self { Self { code: 0, - message: "success".to_owned(), + message, data, } } @@ -37,6 +39,12 @@ where T: serde::Serialize, { fn from(data: T) -> Self { - Self::new(data) + Self::new("success".into(), data) + } +} + +impl WebApiResponse<()> { + pub fn from_str(message: Cow<'static, str>) -> Self { + Self::new(message, ()) } } diff --git a/admin_frontend/src/web_api.rs b/admin_frontend/src/web_api.rs index a73db306..e04283b8 100644 --- a/admin_frontend/src/web_api.rs +++ b/admin_frontend/src/web_api.rs @@ -228,7 +228,7 @@ pub async fn login_handler( State(state): State, jar: CookieJar, Form(param): Form, -) -> Result<(CookieJar, HeaderMap), WebApiError<'static>> { +) -> Result<(CookieJar, HeaderMap, WebApiResponse<()>), WebApiError<'static>> { // Attempt to sign in with email and password let token_res = state .gotrue_client @@ -246,7 +246,7 @@ pub async fn login_handler( GoTrueError::ClientError(client_err) => { match ( client_err.error.as_str(), - client_err.error_description.as_ref().map(|s| s.as_str()), + client_err.error_description.as_deref(), ) { // Email not exist or wrong password ("invalid_grant", Some("Invalid login credentials")) => { @@ -261,10 +261,16 @@ pub async fn login_handler( SignUpResponse::Authenticated(token) => { session_login(State(state), token, jar).await }, - SignUpResponse::NotAuthenticated(user) => match user.identities { - Some(_identities) => todo!(), // new user - None => Err(err.into()), // user exists but sign in password not correct + Some(_identities) => { + // new user, awaiting email verification + Ok(( + jar, + HeaderMap::new(), + WebApiResponse::<()>::from_str("Email Verification Sent".into()), + )) + }, + None => Err(err.into()), // user exists but sign in password not correct }, }, Err(err) => Err(err.into()), @@ -313,7 +319,7 @@ async fn session_login( State(state): State, token: GotrueTokenResponse, jar: CookieJar, -) -> Result<(CookieJar, HeaderMap), WebApiError<'static>> { +) -> Result<(CookieJar, HeaderMap, WebApiResponse<()>), WebApiError<'static>> { let new_session_id = uuid::Uuid::new_v4(); let new_session = session::UserSession::new(new_session_id.to_string(), token); state.session_store.put_user_session(&new_session).await?; @@ -321,5 +327,6 @@ async fn session_login( Ok(( jar.add(new_session_cookie(new_session_id)), htmx_redirect("/web/home"), + ().into(), )) } diff --git a/admin_frontend/templates/components/admin_top_menu_bar.html b/admin_frontend/templates/components/admin_top_menu_bar.html index 88871fef..55bbc74b 100644 --- a/admin_frontend/templates/components/admin_top_menu_bar.html +++ b/admin_frontend/templates/components/admin_top_menu_bar.html @@ -22,7 +22,8 @@ }); - - {% include "components/logout.html" %} +
+ Logout +
diff --git a/admin_frontend/templates/components/logout.html b/admin_frontend/templates/components/logout.html deleted file mode 100644 index f706b65d..00000000 --- a/admin_frontend/templates/components/logout.html +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/admin_frontend/templates/components/top_menu_bar.html b/admin_frontend/templates/components/top_menu_bar.html index 8902ab3f..fb7f12d7 100644 --- a/admin_frontend/templates/components/top_menu_bar.html +++ b/admin_frontend/templates/components/top_menu_bar.html @@ -25,7 +25,8 @@ {% endif %} - - {% include "components/logout.html" %} +
+ Logout +
diff --git a/admin_frontend/templates/layouts/base.html b/admin_frontend/templates/layouts/base.html index f4064f47..6bea1e40 100644 --- a/admin_frontend/templates/layouts/base.html +++ b/admin_frontend/templates/layouts/base.html @@ -30,7 +30,7 @@ const xhr = detail.xhr; displayHttpFail(xhr.status, xhr.statusText, xhr.responseText); } else if (detail.target.id === "none") { - displaySuccess("Success"); + displaySuccess(JSON.parse(detail.xhr.responseText).message); } }); diff --git a/admin_frontend/templates/pages/login.html b/admin_frontend/templates/pages/login.html index d6e0ae64..61f1c9e2 100644 --- a/admin_frontend/templates/pages/login.html +++ b/admin_frontend/templates/pages/login.html @@ -20,7 +20,7 @@

Email Login

-
+
Email: