mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 02:25:41 +00:00
addressing clippy lints
This commit is contained in:
@@ -58,7 +58,7 @@ async fn delete_account(
|
||||
}
|
||||
}
|
||||
Err(RowNotFound) => return Err(ServiceError::UsernameNotFound),
|
||||
Err(_) => return Err(ServiceError::InternalServerError)?,
|
||||
Err(_) => return Err(ServiceError::InternalServerError),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,14 +74,14 @@ async fn set_email(
|
||||
)
|
||||
.execute(&data.db)
|
||||
.await;
|
||||
if !res.is_ok() {
|
||||
if res.is_err() {
|
||||
if let Err(sqlx::Error::Database(err)) = res {
|
||||
if err.code() == Some(Cow::from("23505"))
|
||||
&& err.message().contains("mcaptcha_users_email_key")
|
||||
{
|
||||
Err(ServiceError::EmailTaken)?
|
||||
return Err(ServiceError::EmailTaken);
|
||||
} else {
|
||||
Err(sqlx::Error::Database(err))?
|
||||
return Err(sqlx::Error::Database(err).into());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ pub mod routes {
|
||||
pub struct Account {
|
||||
pub delete: &'static str,
|
||||
pub email_exists: &'static str,
|
||||
pub update_email: &'static str,
|
||||
pub get_secret: &'static str,
|
||||
pub update_email: &'static str,
|
||||
pub update_secret: &'static str,
|
||||
pub username_exists: &'static str,
|
||||
}
|
||||
@@ -47,12 +47,13 @@ pub mod routes {
|
||||
let username_exists = "/api/v1/account/username/exists";
|
||||
let update_email = "/api/v1/account/email/update";
|
||||
Account {
|
||||
get_secret,
|
||||
update_secret,
|
||||
username_exists,
|
||||
update_email,
|
||||
delete,
|
||||
email_exists,
|
||||
|
||||
get_secret,
|
||||
update_email,
|
||||
update_secret,
|
||||
username_exists,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,16 +71,14 @@ async fn update_user_secret(
|
||||
.await;
|
||||
if res.is_ok() {
|
||||
break;
|
||||
} else {
|
||||
if let Err(sqlx::Error::Database(err)) = res {
|
||||
if err.code() == Some(Cow::from("23505"))
|
||||
&& err.message().contains("mcaptcha_users_secret_key")
|
||||
{
|
||||
continue;
|
||||
} else {
|
||||
Err(sqlx::Error::Database(err))?;
|
||||
}
|
||||
};
|
||||
} else if let Err(sqlx::Error::Database(err)) = res {
|
||||
if err.code() == Some(Cow::from("23505"))
|
||||
&& err.message().contains("mcaptcha_users_secret_key")
|
||||
{
|
||||
continue;
|
||||
} else {
|
||||
return Err(sqlx::Error::Database(err).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(HttpResponse::Ok())
|
||||
|
||||
@@ -28,8 +28,8 @@ use crate::AppData;
|
||||
|
||||
pub mod routes {
|
||||
pub struct Auth {
|
||||
pub login: &'static str,
|
||||
pub logout: &'static str,
|
||||
pub login: &'static str,
|
||||
pub register: &'static str,
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ pub mod routes {
|
||||
let logout = "/logout";
|
||||
let register = "/api/v1/signup";
|
||||
Auth {
|
||||
login,
|
||||
logout,
|
||||
login,
|
||||
register,
|
||||
}
|
||||
}
|
||||
@@ -48,16 +48,9 @@ pub mod routes {
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
// protect_get!(cfg, V1_API_ROUTES.auth.logout, signout);
|
||||
|
||||
cfg.service(signup);
|
||||
cfg.service(signin);
|
||||
cfg.service(signout);
|
||||
|
||||
// define_resource!(cfg, V1_API_ROUTES.auth.register, Methods::Post, signup);
|
||||
// define_resource!(cfg, V1_API_ROUTES.auth.logout, Methods::ProtectGet, signout);
|
||||
// define_resource!(cfg, V1_API_ROUTES.auth.login, Methods::Post, signin);
|
||||
//post!(cfg, V1_API_ROUTES.auth.login, signin);
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
@@ -85,10 +78,10 @@ async fn signup(
|
||||
data: AppData,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
if !crate::SETTINGS.server.allow_registration {
|
||||
Err(ServiceError::ClosedForRegistration)?
|
||||
return Err(ServiceError::ClosedForRegistration);
|
||||
}
|
||||
|
||||
if &payload.password != &payload.confirm_password {
|
||||
if payload.password != payload.confirm_password {
|
||||
return Err(ServiceError::PasswordsDontMatch);
|
||||
}
|
||||
let username = data.creds.username(&payload.username)?;
|
||||
@@ -127,22 +120,20 @@ async fn signup(
|
||||
}
|
||||
if res.is_ok() {
|
||||
break;
|
||||
} else {
|
||||
if let Err(sqlx::Error::Database(err)) = res {
|
||||
if err.code() == Some(Cow::from("23505")) {
|
||||
let msg = err.message();
|
||||
if msg.contains("mcaptcha_users_name_key") {
|
||||
Err(ServiceError::UsernameTaken)?;
|
||||
} else if msg.contains("mcaptcha_users_secret_key") {
|
||||
continue;
|
||||
} else {
|
||||
Err(ServiceError::InternalServerError)?;
|
||||
}
|
||||
} else if let Err(sqlx::Error::Database(err)) = res {
|
||||
if err.code() == Some(Cow::from("23505")) {
|
||||
let msg = err.message();
|
||||
if msg.contains("mcaptcha_users_name_key") {
|
||||
return Err(ServiceError::UsernameTaken);
|
||||
} else if msg.contains("mcaptcha_users_secret_key") {
|
||||
continue;
|
||||
} else {
|
||||
Err(sqlx::Error::Database(err))?;
|
||||
return Err(ServiceError::InternalServerError);
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return Err(sqlx::Error::Database(err).into());
|
||||
}
|
||||
};
|
||||
}
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
@@ -174,14 +165,14 @@ async fn signin(
|
||||
Err(ServiceError::WrongPassword)
|
||||
}
|
||||
}
|
||||
Err(RowNotFound) => return Err(ServiceError::UsernameNotFound),
|
||||
Err(_) => return Err(ServiceError::InternalServerError)?,
|
||||
Err(RowNotFound) => Err(ServiceError::UsernameNotFound),
|
||||
Err(_) => Err(ServiceError::InternalServerError),
|
||||
}
|
||||
}
|
||||
|
||||
#[my_codegen::get(path = "crate::V1_API_ROUTES.auth.logout", wrap = "crate::CheckLogin")]
|
||||
async fn signout(id: Identity) -> impl Responder {
|
||||
if let Some(_) = id.identity() {
|
||||
if id.identity().is_some() {
|
||||
id.forget();
|
||||
}
|
||||
HttpResponse::Found()
|
||||
|
||||
@@ -94,10 +94,10 @@ pub async fn add_mcaptcha_util(
|
||||
{
|
||||
continue;
|
||||
} else {
|
||||
Err(sqlx::Error::Database(err))?;
|
||||
return Err(sqlx::Error::Database(err).into());
|
||||
}
|
||||
}
|
||||
Err(e) => Err(e)?,
|
||||
Err(e) => return Err(e.into()),
|
||||
|
||||
Ok(_) => {
|
||||
resp = MCaptchaDetails {
|
||||
@@ -128,15 +128,13 @@ async fn update_token(
|
||||
let res = update_token_helper(&key, &payload.key, &username, &data).await;
|
||||
if res.is_ok() {
|
||||
break;
|
||||
} else {
|
||||
if let Err(sqlx::Error::Database(err)) = res {
|
||||
if err.code() == Some(Cow::from("23505")) {
|
||||
continue;
|
||||
} else {
|
||||
Err(sqlx::Error::Database(err))?;
|
||||
}
|
||||
};
|
||||
}
|
||||
} else if let Err(sqlx::Error::Database(err)) = res {
|
||||
if err.code() == Some(Cow::from("23505")) {
|
||||
continue;
|
||||
} else {
|
||||
return Err(sqlx::Error::Database(err).into());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let resp = MCaptchaDetails {
|
||||
@@ -19,7 +19,7 @@ use actix_identity::Identity;
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::api::v1::mcaptcha::mcaptcha::MCaptchaDetails;
|
||||
use crate::api::v1::mcaptcha::captcha::MCaptchaDetails;
|
||||
use crate::errors::*;
|
||||
use crate::AppData;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ use libmcaptcha::{defense::Level, DefenseBuilder};
|
||||
use log::debug;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::mcaptcha::add_mcaptcha_util;
|
||||
use crate::api::v1::mcaptcha::mcaptcha::MCaptchaDetails;
|
||||
use super::captcha::add_mcaptcha_util;
|
||||
use super::captcha::MCaptchaDetails;
|
||||
use crate::errors::*;
|
||||
use crate::AppData;
|
||||
|
||||
@@ -29,9 +29,9 @@ pub mod routes {
|
||||
|
||||
pub struct Levels {
|
||||
pub add: &'static str,
|
||||
pub update: &'static str,
|
||||
pub delete: &'static str,
|
||||
pub get: &'static str,
|
||||
pub update: &'static str,
|
||||
}
|
||||
|
||||
impl Levels {
|
||||
@@ -42,9 +42,9 @@ pub mod routes {
|
||||
let get = "/api/v1/mcaptcha/levels/get";
|
||||
Levels {
|
||||
add,
|
||||
delete,
|
||||
get,
|
||||
update,
|
||||
delete,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ async fn add_levels(
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
for level in payload.levels.iter() {
|
||||
defense.add_level(level.clone())?;
|
||||
defense.add_level(*level)?;
|
||||
}
|
||||
|
||||
defense.build()?;
|
||||
@@ -132,7 +132,7 @@ async fn update_levels(
|
||||
let mut defense = DefenseBuilder::default();
|
||||
|
||||
for level in payload.levels.iter() {
|
||||
defense.add_level(level.clone())?;
|
||||
defense.add_level(*level)?;
|
||||
}
|
||||
|
||||
// I feel this is necessary as both difficulty factor _and_ visitor threshold of a
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
pub mod captcha;
|
||||
pub mod duration;
|
||||
pub mod levels;
|
||||
pub mod mcaptcha;
|
||||
|
||||
pub fn get_random(len: usize) -> String {
|
||||
use std::iter;
|
||||
@@ -36,5 +36,5 @@ pub fn get_random(len: usize) -> String {
|
||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
duration::services(cfg);
|
||||
levels::services(cfg);
|
||||
mcaptcha::services(cfg);
|
||||
captcha::services(cfg);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ pub mod routes {
|
||||
async fn build_details() -> impl Responder {
|
||||
let build = BuildDetails {
|
||||
version: VERSION,
|
||||
git_commit_hash: &GIT_COMMIT_HASH,
|
||||
git_commit_hash: GIT_COMMIT_HASH,
|
||||
};
|
||||
HttpResponse::Ok().json(build)
|
||||
}
|
||||
@@ -68,7 +68,7 @@ async fn health(data: AppData) -> impl Responder {
|
||||
let mut resp_builder = HealthBuilder::default();
|
||||
resp_builder.db(false);
|
||||
if let Ok(mut con) = data.db.acquire().await {
|
||||
if let Ok(_) = con.ping().await {
|
||||
if con.ping().await.is_ok() {
|
||||
resp_builder.db(true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -128,7 +128,7 @@ mod tests {
|
||||
assert_eq!(notification.heading, HEADING);
|
||||
|
||||
let mark_read_payload = MarkReadReq {
|
||||
id: notification.id.clone(),
|
||||
id: notification.id,
|
||||
};
|
||||
let mark_read_resp = test::call_service(
|
||||
&mut app,
|
||||
|
||||
@@ -193,8 +193,8 @@ mod tests {
|
||||
.to_request(),
|
||||
)
|
||||
.await;
|
||||
// assert_eq!(get_config_resp.status(), StatusCode::OK);
|
||||
// let config: PoWConfig = test::read_body_json(get_config_resp).await;
|
||||
// assert_eq!(config.difficulty_factor, L1.difficulty_factor);
|
||||
assert_eq!(get_config_resp.status(), StatusCode::OK);
|
||||
let config: PoWConfig = test::read_body_json(get_config_resp).await;
|
||||
assert_eq!(config.difficulty_factor, L1.difficulty_factor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
use super::account::routes::Account;
|
||||
use super::auth::routes::Auth;
|
||||
use super::mcaptcha::captcha::routes::MCaptcha;
|
||||
use super::mcaptcha::duration::routes::Duration;
|
||||
use super::mcaptcha::levels::routes::Levels;
|
||||
use super::mcaptcha::mcaptcha::routes::MCaptcha;
|
||||
use super::meta::routes::Meta;
|
||||
use super::notifications::routes::Notifications;
|
||||
use super::pow::routes::PoW;
|
||||
|
||||
Reference in New Issue
Block a user