mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-07-10 06:42:29 +00:00
handle libmcaptcha actor errors
This commit is contained in:
parent
6ef941f73d
commit
068c49080e
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -1560,9 +1560,9 @@ checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.8"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
|
||||
|
||||
[[package]]
|
||||
name = "mcaptcha"
|
||||
@ -1599,6 +1599,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
"sqlx",
|
||||
"tokio",
|
||||
"url",
|
||||
"validator",
|
||||
"yaml-rust",
|
||||
@ -3058,9 +3059,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.9.0"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b7b349f11a7047e6d1276853e612d152f5e8a352c61917887cc2169e2366b4c"
|
||||
checksum = "01cf844b23c6131f624accf65ce0e4e9956a8bb329400ea5bcc26ae3a5c20b0b"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bytes",
|
||||
@ -3173,12 +3174,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.5"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0"
|
||||
dependencies = [
|
||||
"matches",
|
||||
]
|
||||
checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
|
@ -31,7 +31,7 @@ members = [
|
||||
actix-web = "4.0.0-beta.8"
|
||||
actix = "0.12"
|
||||
actix-identity = "0.4.0-beta.2"
|
||||
actix-http = "3.0.0-beta.8"
|
||||
actix-http = "3.0.0-beta.9"
|
||||
actix-rt = "2"
|
||||
actix-cors = "0.6.0-beta.2"
|
||||
actix-service = "2.0.0"
|
||||
@ -42,6 +42,7 @@ rust-embed = "6.0.0"
|
||||
cache-buster = { git = "https://github.com/realaravinth/cache-buster" }
|
||||
|
||||
futures = "0.3.15"
|
||||
tokio = { version = "1", features = ["sync"]}
|
||||
|
||||
sqlx = { version = "0.5.5", features = [ "runtime-actix-rustls", "postgres", "time", "offline" ] }
|
||||
argon2-creds = { branch = "master", git = "https://github.com/realaravinth/argon2-creds"}
|
||||
|
@ -1,6 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS mcaptcha_users (
|
||||
name VARCHAR(100) NOT NULL UNIQUE,
|
||||
email VARCHAR(100) UNIQUE DEFAULT NULL,
|
||||
email_verified BOOLEAN DEFAULT NULL,
|
||||
secret varchar(50) NOT NULL UNIQUE,
|
||||
password TEXT NOT NULL,
|
||||
ID SERIAL PRIMARY KEY NOT NULL
|
||||
|
25
src/data.rs
25
src/data.rs
@ -41,6 +41,7 @@ use libmcaptcha::{
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::errors::ServiceResult;
|
||||
use crate::SETTINGS;
|
||||
|
||||
/// Represents mCaptcha cache and master system.
|
||||
@ -80,29 +81,29 @@ impl SystemGroup {
|
||||
}
|
||||
|
||||
/// utility function to AddSite
|
||||
pub async fn add_site(&self, msg: AddSite) -> CaptchaResult<()> {
|
||||
pub async fn add_site(&self, msg: AddSite) -> ServiceResult<()> {
|
||||
match self {
|
||||
Self::Embedded(val) => val.master.send(msg).await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?,
|
||||
};
|
||||
Self::Embedded(val) => val.master.send(msg).await?.await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?.await?,
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// utility function to rename captcha
|
||||
pub async fn rename(&self, msg: Rename) -> CaptchaResult<()> {
|
||||
pub async fn rename(&self, msg: Rename) -> ServiceResult<()> {
|
||||
match self {
|
||||
Self::Embedded(val) => val.master.send(msg).await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?,
|
||||
};
|
||||
Self::Embedded(val) => val.master.send(msg).await?.await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?.await?,
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// utility function to remove captcha
|
||||
pub async fn remove(&self, msg: RemoveCaptcha) -> CaptchaResult<()> {
|
||||
pub async fn remove(&self, msg: RemoveCaptcha) -> ServiceResult<()> {
|
||||
match self {
|
||||
Self::Embedded(val) => val.master.send(msg).await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?,
|
||||
};
|
||||
Self::Embedded(val) => val.master.send(msg).await?.await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?.await?,
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
use std::convert::From;
|
||||
|
||||
use actix::MailboxError;
|
||||
use actix_web::{
|
||||
dev::BaseHttpResponseBuilder as HttpResponseBuilder,
|
||||
error::ResponseError,
|
||||
@ -28,6 +29,7 @@ use derive_more::{Display, Error};
|
||||
use lettre::transport::smtp::Error as SmtpError;
|
||||
use libmcaptcha::errors::CaptchaError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::oneshot::error::RecvError;
|
||||
use url::ParseError;
|
||||
use validator::ValidationErrors;
|
||||
|
||||
@ -223,6 +225,24 @@ impl From<SmtpError> for ServiceError {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl From<RecvError> for ServiceError {
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
fn from(e: RecvError) -> Self {
|
||||
log::error!("{:?}", e);
|
||||
ServiceError::InternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl From<MailboxError> for ServiceError {
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
fn from(e: MailboxError) -> Self {
|
||||
log::error!("{:?}", e);
|
||||
ServiceError::InternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
pub type ServiceResult<V> = std::result::Result<V, ServiceError>;
|
||||
|
||||
|
@ -17,11 +17,10 @@
|
||||
use std::env;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
mod data;
|
||||
mod settings;
|
||||
|
||||
pub use data::Data;
|
||||
pub use settings::Settings;
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
@ -33,7 +32,11 @@ lazy_static! {
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
#[actix_rt::main]
|
||||
async fn main() {
|
||||
let data = Data::new().await;
|
||||
let db = PgPoolOptions::new()
|
||||
.max_connections(SETTINGS.database.pool)
|
||||
.connect(&SETTINGS.database.url)
|
||||
.await
|
||||
.expect("Unable to form database pool");
|
||||
|
||||
for arg in env::args() {
|
||||
if arg == "--build" {
|
||||
@ -42,7 +45,7 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
sqlx::migrate!("./migrations/").run(&data.db).await.unwrap();
|
||||
sqlx::migrate!("./migrations/").run(&db).await.unwrap();
|
||||
}
|
||||
|
||||
fn build() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user