Creating import&export excel

This commit is contained in:
2026-09-15 17:33:05 +03:30
parent 9ae176bec0
commit 44f9849d0e
26 changed files with 3682 additions and 474 deletions
+13
View File
@@ -278,6 +278,9 @@ export class AuthService {
if (!user) {
throw new UnauthorizedException('اطلاعات ورود نادرست است');
}
if (user.isActive === false) {
throw new UnauthorizedException('حساب کاربری غیرفعال است');
}
const ok = await bcrypt.compare(dto.password, user.passwordHash);
if (!ok) {
@@ -298,6 +301,9 @@ export class AuthService {
if (!user) {
throw new UnauthorizedException('حسابی با این موبایل یافت نشد');
}
if (user.isActive === false) {
throw new UnauthorizedException('حساب کاربری غیرفعال است');
}
await this.throttleChallenges('login', user.email, mobile);
@@ -352,6 +358,9 @@ export class AuthService {
if (!user) {
throw new UnauthorizedException();
}
if (user.isActive === false) {
throw new UnauthorizedException('حساب کاربری غیرفعال است');
}
const now = new Date();
await this.prisma.authChallenge.update({
@@ -600,6 +609,10 @@ export class AuthService {
organizationId: user.organizationId,
role: user.role,
};
await this.prisma.user.update({
where: { id: user.id },
data: { lastLoginAt: new Date() },
});
return {
accessToken: this.jwt.sign(payload),
user: await this.toAuthUserDto(user),
+16 -5
View File
@@ -2,6 +2,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PrismaService } from '../prisma/prisma.service';
export type JwtPayload = {
sub: string;
@@ -11,7 +12,10 @@ export type JwtPayload = {
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(config: ConfigService) {
constructor(
config: ConfigService,
private readonly prisma: PrismaService,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
@@ -19,14 +23,21 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
});
}
validate(payload: JwtPayload & { typ?: string; mobile?: string }) {
async validate(payload: JwtPayload & { typ?: string; mobile?: string }) {
if (payload.typ === 'portal') {
throw new UnauthorizedException();
}
const user = await this.prisma.user.findUnique({
where: { id: payload.sub },
select: { id: true, organizationId: true, role: true, isActive: true },
});
if (!user || user.isActive === false) {
throw new UnauthorizedException();
}
return {
userId: payload.sub,
organizationId: payload.organizationId,
role: payload.role,
userId: user.id,
organizationId: user.organizationId,
role: user.role,
};
}
}