diff --git a/src/identity/adapters/input/web/owner.rs b/src/identity/adapters/input/web/owner.rs new file mode 100644 index 0000000..35b88bc --- /dev/null +++ b/src/identity/adapters/input/web/owner.rs @@ -0,0 +1,341 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use actix_identity::Identity; +use actix_web::{get, http::header::ContentType, post, web, HttpRequest, HttpResponse, Responder}; +use derive_builder::Builder; +use serde::{Deserialize, Serialize}; +use url::Url; +use uuid::Uuid; + +use super::errors::*; +use super::types; +//use crate::utils::uuid::WebGetUUIDInterfaceObj; + +pub fn services(cfg: &mut web::ServiceConfig) { + cfg.service(login_ui_handler); + cfg.service(login_form_submission_handler); + + cfg.service(register_ui_handler); + cfg.service(register_form_submission_handler); + + cfg.service(update_email_ui_handler); + cfg.service(update_email_form_submission_handler); + + cfg.service(change_password_ui_handler); + cfg.service(change_password_form_submission_handler); + + cfg.service(delete_user_ui_handler); + cfg.service(delete_user_form_submission_handler); + + cfg.service(verify_email_ui_handler); + cfg.service(verify_email_form_submission_handler); + cfg.service(resend_verification_email); + + cfg.service(add_store_ui_handler); + cfg.service(add_store_form_submission_handler); + + cfg.service(update_store_ui_handler); + cfg.service(update_store_form_submission_handler); +} + +// login handlers + +#[allow(clippy::too_many_arguments)] +#[get("/owner/login")] +#[tracing::instrument(name = "login UI handler", skip())] +async fn login_ui_handler() -> WebJsonRepsonse { + const LOGIN_PAGE: &str = include_str!("./owner_login.html"); + + Ok(HttpResponse::Ok() + .insert_header(ContentType::html()) + .body(LOGIN_PAGE)) +} + +#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] +struct OwnerLoginPayload { + email: String, + password: String, +} + +#[allow(clippy::too_many_arguments)] +#[post("/owner/login")] +#[tracing::instrument( + name = "Login form submission handler" + skip(id, req, payload, identity_cqrs_exec) +)] +async fn login_form_submission_handler( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, + payload: web::Form, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} + +// register handlers + +#[allow(clippy::too_many_arguments)] +#[get("/owner/register")] +#[tracing::instrument(name = "register UI handler", skip())] +async fn register_ui_handler() -> WebJsonRepsonse { + const REGISTER_PAGE: &str = include_str!("./owner_register.html"); + + Ok(HttpResponse::Ok() + .insert_header(ContentType::html()) + .body(REGISTER_PAGE)) +} + +#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] +struct OwnerRegisterPayload { + password: String, + confirm_password: String, + first_name: String, + last_name: String, + email: String, +} + +#[allow(clippy::too_many_arguments)] +#[post("/owner/register")] +#[tracing::instrument( + name = "Register form submission handler" + skip(id, req, payload, identity_cqrs_exec) +)] +async fn register_form_submission_handler( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, + payload: web::Form, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} + +// update email handlers + +#[allow(clippy::too_many_arguments)] +#[get("/owner/user/email/update")] +#[tracing::instrument(name = "Update email UI handler", skip())] +async fn update_email_ui_handler() -> WebJsonRepsonse { + const UPDATE_EMAIL: &str = include_str!("./owner_update_email.html"); + + Ok(HttpResponse::Ok() + .insert_header(ContentType::html()) + .body(UPDATE_EMAIL)) +} + +#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] +struct OwnerUpdateEmailPayload { + password: String, + new_email: String, +} + +#[allow(clippy::too_many_arguments)] +#[post("/owner/user/email/update")] +#[tracing::instrument( + name = "Update email form submission handler" + skip(id, req, payload, identity_cqrs_exec) +)] +async fn update_email_form_submission_handler( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, + payload: web::Form, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} + +// change password handlers + +#[allow(clippy::too_many_arguments)] +#[get("/owner/user/password/update")] +#[tracing::instrument(name = "Change password UI handler", skip())] +async fn change_password_ui_handler() -> WebJsonRepsonse { + const CHANGE_PASSWORD: &str = include_str!("./owner_change_password.html"); + + Ok(HttpResponse::Ok() + .insert_header(ContentType::html()) + .body(CHANGE_PASSWORD)) +} + +#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] +struct OwnerChangePasswordPayload { + current_password: String, + new_password: String, + confirm_new_password: String, +} + +#[allow(clippy::too_many_arguments)] +#[post("/owner/user/email/update")] +#[tracing::instrument( + name = "Change password form submission handler" + skip(id, req, payload, identity_cqrs_exec) +)] +async fn change_password_form_submission_handler( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, + payload: web::Form, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} + +// Delete user handlers + +#[allow(clippy::too_many_arguments)] +#[get("/owner/user/delete")] +#[tracing::instrument(name = "Delete user UI handler", skip())] +async fn delete_user_ui_handler() -> WebJsonRepsonse { + const DELETE_USER: &str = include_str!("./owner_delete_user.html"); + + Ok(HttpResponse::Ok() + .insert_header(ContentType::html()) + .body(DELETE_USER)) +} + +#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] +struct OwnerDeleteUser { + password: String, +} + +#[allow(clippy::too_many_arguments)] +#[post("/owner/user/delete")] +#[tracing::instrument( + name = "Delete user form submission handler" + skip(id, req, payload, identity_cqrs_exec) +)] +async fn delete_user_form_submission_handler( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, + payload: web::Form, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} + +// Verify email handler + +#[allow(clippy::too_many_arguments)] +#[get("/owner/user/verify/email")] +#[tracing::instrument(name = "Verify email UI handler", skip())] +async fn verify_email_ui_handler() -> WebJsonRepsonse { + const VERIFY_EMAIL: &str = include_str!("./owner_verify_email.html"); + + Ok(HttpResponse::Ok() + .insert_header(ContentType::html()) + .body(VERIFY_EMAIL)) +} + +#[allow(clippy::too_many_arguments)] +#[post("/owner/user/verify/email")] +#[tracing::instrument( + name = "Verify email form submission handler" + skip(id, req, identity_cqrs_exec) +)] +async fn verify_email_form_submission_handler( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} + +#[allow(clippy::too_many_arguments)] +#[get("/owner/user/verify/email")] +#[tracing::instrument( + name = "Resend verification email handler", + skip(id, req, identity_cqrs_exec) +)] +async fn resend_verification_email( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} + +// add store handler + +#[allow(clippy::too_many_arguments)] +#[get("/owner/store")] +#[tracing::instrument(name = "Add store UI handler", skip())] +async fn add_store_ui_handler() -> WebJsonRepsonse { + const ADD_STORE: &str = include_str!("./owner_add_store.html"); + + Ok(HttpResponse::Ok() + .insert_header(ContentType::html()) + .body(ADD_STORE)) +} + +#[derive(Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)] +pub struct OnwerAddStorePayload { + name: String, + address: Option, +} + +#[allow(clippy::too_many_arguments)] +#[post("/owner/store")] +#[tracing::instrument( + name = "Add store form submission handler" + skip(id, req, identity_cqrs_exec) +)] +async fn add_store_form_submission_handler( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, + paylod: web::Form, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} + +// Update store handler + +#[allow(clippy::too_many_arguments)] +#[get("/owner/store/update")] +#[tracing::instrument(name = "Add store UI handler", skip())] +async fn update_store_ui_handler() -> WebJsonRepsonse { + const ADD_STORE: &str = include_str!("./owner_add_store.html"); + + Ok(HttpResponse::Ok() + .insert_header(ContentType::html()) + .body(ADD_STORE)) +} + +#[derive(Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)] +pub struct OnwerUpdatetorePayload { + name: String, + address: Option, +} + +#[allow(clippy::too_many_arguments)] +#[post("/owner/store/update")] +#[tracing::instrument( + name = "Update store form submission handler" + skip(id, req, identity_cqrs_exec) +)] +async fn update_store_form_submission_handler( + identity_cqrs_exec: types::WebIdentityCqrsExec, + req: HttpRequest, + id: Identity, + paylod: web::Form, +) -> WebJsonRepsonse { + let store = ""; + + Ok(HttpResponse::Ok().json(store)) +} diff --git a/src/identity/adapters/input/web/owner_add_store.html b/src/identity/adapters/input/web/owner_add_store.html new file mode 100644 index 0000000..e2e77bf --- /dev/null +++ b/src/identity/adapters/input/web/owner_add_store.html @@ -0,0 +1,25 @@ + + + + + + Create Store | Vanikam + + + +
+ + + + + +
+ + + diff --git a/src/identity/adapters/input/web/owner_change_password.html b/src/identity/adapters/input/web/owner_change_password.html new file mode 100644 index 0000000..242f9a6 --- /dev/null +++ b/src/identity/adapters/input/web/owner_change_password.html @@ -0,0 +1,31 @@ + + + + + + Change Password | Vanikam + + + +
+ + + + + + + + +
+ + + diff --git a/src/identity/adapters/input/web/owner_delete_user.html b/src/identity/adapters/input/web/owner_delete_user.html new file mode 100644 index 0000000..13d6e67 --- /dev/null +++ b/src/identity/adapters/input/web/owner_delete_user.html @@ -0,0 +1,20 @@ + + + + + + Delete account | Vanikam + + + +
+ + + + +
+ + diff --git a/src/identity/adapters/input/web/owner_login.html b/src/identity/adapters/input/web/owner_login.html new file mode 100644 index 0000000..095f9a7 --- /dev/null +++ b/src/identity/adapters/input/web/owner_login.html @@ -0,0 +1,27 @@ + + + + + + Login | Vanikam + + + +
+ + + + + +
+ +

New here? Click here to register!

+ + + diff --git a/src/identity/adapters/input/web/owner_register.html b/src/identity/adapters/input/web/owner_register.html new file mode 100644 index 0000000..94b5a43 --- /dev/null +++ b/src/identity/adapters/input/web/owner_register.html @@ -0,0 +1,43 @@ + + + + + + Register | Vanikam + + + +
+ + + + + + + + + + + + +
+ +

Already have an account? Click here to log in!

+ + + diff --git a/src/identity/adapters/input/web/owner_update_email.html b/src/identity/adapters/input/web/owner_update_email.html new file mode 100644 index 0000000..c205d3c --- /dev/null +++ b/src/identity/adapters/input/web/owner_update_email.html @@ -0,0 +1,25 @@ + + + + + + Update Email | Vanikam + + + +
+ + + + + +
+ + + diff --git a/src/identity/adapters/input/web/owner_update_store.html b/src/identity/adapters/input/web/owner_update_store.html new file mode 100644 index 0000000..9c58a96 --- /dev/null +++ b/src/identity/adapters/input/web/owner_update_store.html @@ -0,0 +1,25 @@ + + + + + + Update Store | Vanikam + + + +
+ + + + + +
+ + + diff --git a/src/identity/adapters/input/web/owner_verify_email.html b/src/identity/adapters/input/web/owner_verify_email.html new file mode 100644 index 0000000..3453545 --- /dev/null +++ b/src/identity/adapters/input/web/owner_verify_email.html @@ -0,0 +1,14 @@ + + + + + + Verify email | Vanikam + + + +
+ +
+ +