feat: migrate update username to use db_* interface

This commit is contained in:
realaravinth
2022-05-11 20:02:03 +05:30
parent f79d159468
commit 39ee2ad221
3 changed files with 30 additions and 33 deletions

View File

@@ -19,7 +19,6 @@ use actix_web::{web, HttpResponse, Responder};
use argon2_creds::Config;
use db_core::Login;
use serde::{Deserialize, Serialize};
use sqlx::Error::RowNotFound;
use crate::api::v1::auth::runners::Password;
use crate::errors::*;

View File

@@ -65,26 +65,10 @@ async fn set_username(
let processed_uname = data.creds.username(&payload.username)?;
let res = sqlx::query!(
"UPDATE mcaptcha_users set name = $1
WHERE name = $2",
&processed_uname,
&username,
)
.execute(&data.db)
.await;
data.dblib
.update_username(&username, &processed_uname)
.await?;
if res.is_err() {
if let Err(sqlx::Error::Database(err)) = res {
if err.code() == Some(Cow::from("23505"))
&& err.message().contains("mcaptcha_users_name_key")
{
return Err(ServiceError::UsernameTaken);
} else {
return Err(sqlx::Error::Database(err).into());
}
};
}
id.forget();
id.remember(processed_uname);