mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-14 13:08:27 +03:00
conditional registration blocking
This commit is contained in:
parent
16dd4125c3
commit
d1aea6c456
2 changed files with 9 additions and 21 deletions
|
@ -48,6 +48,9 @@ pub async fn signup(
|
|||
payload: web::Json<Register>,
|
||||
data: web::Data<Data>,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
if !crate::SETTINGS.server.allow_registration {
|
||||
Err(ServiceError::ClosedForRegistration)?
|
||||
}
|
||||
let username = data.creds.username(&payload.username)?;
|
||||
let hash = data.creds.password(&payload.password)?;
|
||||
data.creds.email(Some(&payload.email))?;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
use std::convert::From;
|
||||
|
||||
use actix_web::{
|
||||
client::SendRequestError,
|
||||
dev::HttpResponseBuilder,
|
||||
error::ResponseError,
|
||||
http::{header, StatusCode},
|
||||
|
@ -39,6 +38,11 @@ pub enum ServiceError {
|
|||
#[display(fmt = "internal server error")]
|
||||
InternalServerError,
|
||||
|
||||
#[display(
|
||||
fmt = "This server is is closed for registration. Contact admin if this is unexpecter"
|
||||
)]
|
||||
ClosedForRegistration,
|
||||
|
||||
#[display(fmt = "The value you entered for email is not an email")] //405j
|
||||
NotAnEmail,
|
||||
#[display(fmt = "The value you entered for URL is not a URL")] //405j
|
||||
|
@ -74,17 +78,12 @@ pub enum ServiceError {
|
|||
#[display(fmt = "Username not available")]
|
||||
UsernameTaken,
|
||||
/// when the a token name is already taken
|
||||
#[display(fmt = "token name not available")]
|
||||
TokenNameTaken,
|
||||
/// token not found
|
||||
#[display(fmt = "Token not found. Is token registered?")]
|
||||
TokenNotFound,
|
||||
|
||||
#[display(fmt = "{}", _0)]
|
||||
CaptchaError(CaptchaError),
|
||||
|
||||
#[display(fmt = "Couldn't reach your server. If Problem presists, contact support")]
|
||||
ClientServerUnreachable,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -107,6 +106,7 @@ impl ResponseError for ServiceError {
|
|||
#[cfg(not(tarpaulin_include))]
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
ServiceError::ClosedForRegistration => StatusCode::FORBIDDEN,
|
||||
ServiceError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
ServiceError::NotAnEmail => StatusCode::BAD_REQUEST,
|
||||
ServiceError::NotAUrl => StatusCode::BAD_REQUEST,
|
||||
|
@ -123,9 +123,7 @@ impl ResponseError for ServiceError {
|
|||
|
||||
ServiceError::UsernameTaken => StatusCode::BAD_REQUEST,
|
||||
|
||||
ServiceError::TokenNameTaken => StatusCode::BAD_REQUEST,
|
||||
ServiceError::TokenNotFound => StatusCode::NOT_FOUND,
|
||||
ServiceError::ClientServerUnreachable => StatusCode::SERVICE_UNAVAILABLE,
|
||||
ServiceError::CaptchaError(e) => match e {
|
||||
CaptchaError::MailboxError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
_ => StatusCode::BAD_REQUEST,
|
||||
|
@ -156,19 +154,6 @@ impl From<ValidationErrors> for ServiceError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<SendRequestError> for ServiceError {
|
||||
fn from(e: SendRequestError) -> ServiceError {
|
||||
debug!("{:?}", &e);
|
||||
match e {
|
||||
SendRequestError::Url(_) => ServiceError::NotAUrl,
|
||||
SendRequestError::Send(_) => ServiceError::InternalServerError,
|
||||
SendRequestError::Response(_) => ServiceError::InternalServerError,
|
||||
SendRequestError::Body(_) => ServiceError::InternalServerError,
|
||||
_ => ServiceError::ClientServerUnreachable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParseError> for ServiceError {
|
||||
fn from(_: ParseError) -> ServiceError {
|
||||
ServiceError::NotAUrl
|
||||
|
|
Loading…
Add table
Reference in a new issue