79 lines
2.6 KiB
Rust
79 lines
2.6 KiB
Rust
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
use argon2_creds::CredsError;
|
|
use derive_more::{Display, Error};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::identity::application::port::output::{
|
|
db::errors::OutDBPortError, phone::errors::OutPhonePortError,
|
|
};
|
|
|
|
pub type IdentityResult<V> = Result<V, IdentityError>;
|
|
|
|
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub enum IdentityError {
|
|
DuplicateUsername,
|
|
VerificationOTPNotFound,
|
|
VerificationSecretNotFound,
|
|
PhoneNumberVerificationFailed,
|
|
LoginOTPNotFound,
|
|
LoginFailed,
|
|
DuplicateEmail,
|
|
DuplicateEmployeeID,
|
|
DuplicatePhoneNumber,
|
|
DuplicateVerificationOTP,
|
|
InternalError,
|
|
PhoneNumberNotFound,
|
|
EmployeeNotFound,
|
|
InviteNotFound,
|
|
StoreNotFound,
|
|
}
|
|
|
|
pub type IdentityCommandResult<V> = Result<V, IdentityCommandError>;
|
|
|
|
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub enum IdentityCommandError {
|
|
BadUsername(String),
|
|
BadEmail,
|
|
BadPassowrd(String),
|
|
PasswordsDontMatch,
|
|
WrongPassword,
|
|
PermissionDenied,
|
|
}
|
|
|
|
impl From<CredsError> for IdentityCommandError {
|
|
fn from(v: CredsError) -> Self {
|
|
match v {
|
|
CredsError::NotAnEmail => Self::BadEmail,
|
|
CredsError::PasswordTooShort => Self::BadPassowrd(v.to_string()),
|
|
CredsError::PasswordTooLong => Self::BadPassowrd(v.to_string()),
|
|
_ => Self::BadUsername(v.to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<OutPhonePortError> for IdentityError {
|
|
fn from(v: OutPhonePortError) -> Self {
|
|
match v {
|
|
OutPhonePortError::InternalError => Self::InternalError,
|
|
}
|
|
}
|
|
}
|
|
impl From<OutDBPortError> for IdentityError {
|
|
fn from(v: OutDBPortError) -> Self {
|
|
match v {
|
|
OutDBPortError::InternalError => Self::InternalError,
|
|
OutDBPortError::DuplicateVerificationOTPSecret => Self::DuplicateVerificationOTP,
|
|
OutDBPortError::VerificationSecretNotFound => Self::VerificationSecretNotFound,
|
|
OutDBPortError::VerificationOTPNotFound => Self::VerificationOTPNotFound,
|
|
OutDBPortError::DuplicateEmpLoginOTP | OutDBPortError::DuplicateEmpVerificationOTP => {
|
|
Self::InternalError
|
|
}
|
|
OutDBPortError::PhoneNumberNotFound => Self::PhoneNumberNotFound,
|
|
OutDBPortError::EmpLoginOTPNotFound => Self::LoginOTPNotFound,
|
|
OutDBPortError::EmpVerificationOTPNotFound => Self::VerificationOTPNotFound,
|
|
}
|
|
}
|
|
}
|