chore: add user get profile and check validity route

This commit is contained in:
mahyargdz
2025-01-22 09:50:03 +03:30
parent 7431dad85f
commit 72b6cb35a0
39 changed files with 874 additions and 127 deletions
@@ -16,4 +16,8 @@ export class CacheService {
async del(key: string) {
await this.cacheManager.del(key);
}
async getTtl(key: string) {
return await this.cacheManager.ttl(key);
}
}
+13 -8
View File
@@ -12,28 +12,33 @@ export class OTPService {
private generateOTP(): string {
return randomInt(10000, 99999).toString();
}
//
async generateAndSetInCache(identifier: string, cacheKey: OtpCacheKeyType) {
const otp = this.generateOTP();
const key = `${identifier}:${cacheKey}:OTP`;
await this.cacheService.set(key, otp);
return otp;
}
//
async verifyOtp(identifier: string, otpCode: string, cacheKey: OtpCacheKeyType) {
const key = `${identifier}:${cacheKey}:OTP`;
const codeInCache = await this.cacheService.get<string | null>(key);
return codeInCache && otpCode === codeInCache;
}
//
async delOtpFormCache(identifier: string, cacheKey: OtpCacheKeyType) {
const key = `${identifier}:${cacheKey}:OTP`;
await this.cacheService.del(key);
}
// async verify(identifier: string, otp: string): Promise<boolean> {
// // Here you would typically verify the OTP against stored value
// // and check if it's not expired
// return true; // Placeholder implementation
// }
async checkExistOtp(identifier: string, cacheKey: OtpCacheKeyType) {
const key = `${identifier}:${cacheKey}:OTP`;
const codeInCache = await this.cacheService.get<string | null>(key);
if (!codeInCache) return null;
const ttlInMsSeconds = await this.cacheService.getTtl(key);
return Math.floor((ttlInMsSeconds! - Date.now()) / 1000);
}
}
+3 -3
View File
@@ -5,7 +5,7 @@ import { CacheService } from "./providers/cache.service";
import { OTPService } from "./providers/otp.service";
import { PasswordService } from "./providers/password.service";
import { SmsService } from "./providers/sms.service";
import { SmsConfigs } from "../../configs/sms.config";
import { smsConfigs } from "../../configs/sms.config";
@Module({
providers: [
@@ -15,8 +15,8 @@ import { SmsConfigs } from "../../configs/sms.config";
SmsService,
{
provide: SMS_CONFIG,
useFactory: SmsConfigs().useFactory,
inject: SmsConfigs().inject,
useFactory: smsConfigs().useFactory,
inject: smsConfigs().inject,
},
],
exports: [SMS_CONFIG, OTPService, PasswordService, CacheService, SmsService],