feat: bootstrap owner web adapter handlers
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/pr/woodpecker Pipeline failed

This commit is contained in:
Aravinth Manivannan 2025-01-09 23:05:42 +05:30
parent 357419fed9
commit 671158b721
Signed by: realaravinth
GPG key ID: F8F50389936984FF
9 changed files with 551 additions and 0 deletions

View file

@ -0,0 +1,341 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// 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<impl Responder> {
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<OwnerLoginPayload>,
) -> WebJsonRepsonse<impl Responder> {
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<impl Responder> {
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<OwnerRegisterPayload>,
) -> WebJsonRepsonse<impl Responder> {
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<impl Responder> {
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<OwnerUpdateEmailPayload>,
) -> WebJsonRepsonse<impl Responder> {
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<impl Responder> {
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<OwnerChangePasswordPayload>,
) -> WebJsonRepsonse<impl Responder> {
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<impl Responder> {
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<OwnerChangePasswordPayload>,
) -> WebJsonRepsonse<impl Responder> {
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<impl Responder> {
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<impl Responder> {
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<impl Responder> {
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<impl Responder> {
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<String>,
}
#[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<OnwerAddStorePayload>,
) -> WebJsonRepsonse<impl Responder> {
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<impl Responder> {
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<String>,
}
#[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<OnwerUpdatetorePayload>,
) -> WebJsonRepsonse<impl Responder> {
let store = "";
Ok(HttpResponse::Ok().json(store))
}

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Store | Vanikam</title>
</head>
<body>
<form action="/owner/store" method="post">
<label for="name">
Store name
<input type="text" name="name" id="name" required>
</label>
<label for="address">
Address
<input type="text" name="address" id="address">
</label>
<button type="submit">Create Store</button>
</form>
</body>
</html>

View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Change Password | Vanikam</title>
</head>
<body>
<form action="/owner/user/password/change" method="post">
<label for="current_password">
Current password
<input type="password" name="current_password" id="current_password">
</label>
<label for="new_password">
New password
<input type="password" name="new_password" id="new_password">
</label>
<label for="confirm_new_password">
Confirm new password
<input type="password" name="confirm_new_password" id="confirm_new_password">
</label>
<button type="submit">Change password</button>
</form>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Delete account | Vanikam</title>
</head>
<body>
<form action="/owner/delete/user" method="post">
<label for="password">
Password
<input type="password" name="password" id="password">
</label>
<button type="submit">Delete account</button>
</form>
</body>
</html>

View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login | Vanikam</title>
</head>
<body>
<form action="/owner/login" method="post">
<label for="email">
Email
<input type="email" name="email" id="email">
</label>
<label for="password">
Password
<input type="password" name="password" id="password">
</label>
<button type="submit">Login</button>
</form>
<p>New here? Click <a href="/owner/register">here to register!</a></p>
</body>
</html>

View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register | Vanikam</title>
</head>
<body>
<form action="/owner/register" method="post">
<label for="first_name">
First Name
<input type="text" name="first_name" id="first_name">
</label>
<label for="last_name">
Last Name
<input type="text" name="last_name" id="last_name">
</label>
<label for="email">
Email
<input type="email" name="email" id="email">
</label>
<label for="password">
Password
<input type="password" name="password" id="password">
</label>
<label for="confirm_password">
Confirm Password
<input type="confirm_password" name="confirm_password" id="confirm_password">
</label>
<button type="submit">Register</button>
</form>
<p>Already have an account? Click <a href="/owner/login">here to log in!</a></p>
</body>
</html>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Email | Vanikam</title>
</head>
<body>
<form action="/owner/user/email/update" method="post">
<label for="email">
Email
<input type="email" name="email" id="email">
</label>
<label for="password">
Password
<input type="password" name="password" id="password">
</label>
<button type="submit">Update</button>
</form>
</body>
</html>

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Store | Vanikam</title>
</head>
<body>
<form action="/owner/store/update" method="post">
<label for="name">
Store name
<input type="text" name="name" id="name" required>
</label>
<label for="address">
Address
<input type="text" name="address" id="address">
</label>
<button type="submit">Update Store</button>
</form>
</body>
</html>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Verify email | Vanikam</title>
</head>
<body>
<form action="/owner/delete/user" method="post">
<button type="submit">Verify email</button>
</form>
</body>
</html>