mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: define interface for username registration"
This commit is contained in:
@@ -26,6 +26,15 @@ pub enum DBError {
|
|||||||
/// errors that are specific to a database implementation
|
/// errors that are specific to a database implementation
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
DBError(#[source] BoxDynError),
|
DBError(#[source] BoxDynError),
|
||||||
|
/// Username is taken
|
||||||
|
#[error("Username is taken")]
|
||||||
|
UsernameTaken,
|
||||||
|
/// Email is taken
|
||||||
|
#[error("Email is taken")]
|
||||||
|
EmailTaken,
|
||||||
|
/// Secret is taken
|
||||||
|
#[error("Secret is taken")]
|
||||||
|
SecretTaken,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience type alias for grouping driver-specific errors
|
/// Convenience type alias for grouping driver-specific errors
|
||||||
|
|||||||
@@ -58,12 +58,28 @@ pub mod dev {
|
|||||||
pub use async_trait::async_trait;
|
pub use async_trait::async_trait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
|
/// Data required to register a new user
|
||||||
|
pub struct Register<'a> {
|
||||||
|
/// username of new user
|
||||||
|
pub username: &'a str,
|
||||||
|
/// secret of new user
|
||||||
|
pub secret: &'a str,
|
||||||
|
/// hashed password of new use
|
||||||
|
pub hash: &'a str,
|
||||||
|
/// Optionally, email of new use
|
||||||
|
pub email: Option<&'a str>,
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
/// mCaptcha's database requirements. To implement support for $Database, kindly implement this
|
/// mCaptcha's database requirements. To implement support for $Database, kindly implement this
|
||||||
/// trait.
|
/// trait.
|
||||||
pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
||||||
/// ping DB
|
/// ping DB
|
||||||
async fn ping(&self) -> bool;
|
async fn ping(&self) -> bool;
|
||||||
|
|
||||||
|
/// register a new user
|
||||||
|
async fn register(&self, p: &Register) -> DBResult<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait to clone MCDatabase
|
/// Trait to clone MCDatabase
|
||||||
|
|||||||
@@ -197,7 +197,12 @@ impl From<CredsError> for ServiceError {
|
|||||||
impl From<DBError> for ServiceError {
|
impl From<DBError> for ServiceError {
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn from(e: DBError) -> ServiceError {
|
fn from(e: DBError) -> ServiceError {
|
||||||
ServiceError::DBError(DBErrorWrapper(e))
|
match e{
|
||||||
|
DBError::UsernameTaken => ServiceError::UsernameTaken,
|
||||||
|
DBError::SecretTaken => ServiceError::InternalServerError,
|
||||||
|
DBError::EmailTaken => ServiceError::EmailTaken,
|
||||||
|
_ => ServiceError::DBError(DBErrorWrapper(e))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user