feat(service): expand service layer with new domain operations
- Add IM service modules: audit, channel roles, custom emojis, forum tags, integrations, invitations, repo links, slash commands, stages, voice, webhooks - Add PR service modules: review requests, templates - Add repo service modules: contributors, release assets, git extras (archive, branch rename, commit extras, diff/merge, tag, tree) - Add user service: social (follow/block) - Add internal auth service - Update existing service modules with expanded functionality - Remove deleted IM modules: articles, delivery trace, drafts, follows, messages, polls, presence, reactions, threads
This commit is contained in:
@@ -51,7 +51,7 @@ impl AuthService {
|
||||
}
|
||||
|
||||
let cooldown_key = format!("{}cooldown:{}", Self::REGISTER_EMAIL_CODE_PREFIX, email);
|
||||
if self.ctx.cache.exists(&cooldown_key) {
|
||||
if self.ctx.cache.exists(&cooldown_key).await {
|
||||
return Err(AppError::BadRequest(
|
||||
"verification code was sent recently; please try again later".into(),
|
||||
));
|
||||
@@ -66,6 +66,7 @@ impl AuthService {
|
||||
&code,
|
||||
Some(Duration::from_secs(Self::REGISTER_EMAIL_CODE_TTL_SECS)),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| AppError::InternalServerError(e.to_string()))?;
|
||||
self.ctx
|
||||
.cache
|
||||
@@ -74,6 +75,7 @@ impl AuthService {
|
||||
&true,
|
||||
Some(Duration::from_secs(Self::REGISTER_EMAIL_CODE_COOLDOWN_SECS)),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| AppError::InternalServerError(e.to_string()))?;
|
||||
|
||||
let mut mail = self
|
||||
@@ -101,17 +103,18 @@ impl AuthService {
|
||||
})
|
||||
}
|
||||
|
||||
fn auth_check_register_email_code(&self, email: &str, code: &str) -> Result<(), AppError> {
|
||||
async fn auth_check_register_email_code(&self, email: &str, code: &str) -> Result<(), AppError> {
|
||||
let cache_key = Self::register_email_code_key(email);
|
||||
let stored = self
|
||||
.ctx
|
||||
.cache
|
||||
.get::<String>(&cache_key)
|
||||
.await
|
||||
.ok_or(AppError::InvalidEmailCode)?;
|
||||
if !crate::service::util::constant_time_eq(stored.trim(), code.trim()) {
|
||||
return Err(AppError::InvalidEmailCode);
|
||||
}
|
||||
let _ = self.ctx.cache.delete(&cache_key);
|
||||
let _ = self.ctx.cache.delete(&cache_key).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -171,7 +174,7 @@ impl AuthService {
|
||||
return Err(AppError::AccountAlreadyExists);
|
||||
}
|
||||
|
||||
self.auth_check_register_email_code(&email, ¶ms.email_code)?;
|
||||
self.auth_check_register_email_code(&email, ¶ms.email_code).await?;
|
||||
|
||||
let user_id = uuid::Uuid::now_v7();
|
||||
let now = chrono::Utc::now();
|
||||
@@ -230,6 +233,7 @@ impl AuthService {
|
||||
|
||||
txn.commit().await.map_err(|_| AppError::TxnError)?;
|
||||
|
||||
context.renew();
|
||||
context.set_user(user_id);
|
||||
context.remove(Self::RSA_PRIVATE_KEY);
|
||||
context.remove(Self::RSA_PUBLIC_KEY);
|
||||
|
||||
Reference in New Issue
Block a user