Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NODE_ENV=development
# EMAIL
EMAIL_USER=seuemail@gmail.com
EMAIL_PASS=sua_senha_de_app
JWT_SECRET=uma_chave_aqui

# DEEP LINKING (Substitua SEU_IP_LOCAL pelo IP IPv4 da sua máquina, ex: 192.168.1.15)
API_URL="http://SEU_IP_LOCAL:3000"
Expand Down
2 changes: 1 addition & 1 deletion backend/model.nlp

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@nestjs/common": "^11.0.1",
"@nestjs/config": "^4.0.3",
"@nestjs/config": "^4.0.4",
"@nestjs/core": "^11.0.1",
"@nestjs/jwt": "^11.0.2",
"@nestjs/mongoose": "^11.0.4",
Expand Down
9 changes: 2 additions & 7 deletions backend/src/modules/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@ import { Module } from '@nestjs/common';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { UserModule } from '../user/user.module';
import { JwtModule } from '@nestjs/jwt';
import { JwtGuard } from './guards/jwt.guard';
import { JwtStrategy } from './guards/jwt.strategy';
import { EmailModule } from '../email/email.module';
import { SharedModule } from '../shared/shared.module';

@Module({
imports: [
UserModule,
EmailModule,
JwtModule.registerAsync({
useFactory: () => ({
secret: 'secret',
//signOptions: {expiresIn:"3600s"},
}),
}),
SharedModule,
],
controllers: [AuthController],
providers: [AuthService, JwtGuard, JwtStrategy],
Expand Down
2 changes: 1 addition & 1 deletion backend/src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class AuthService {
try {
const payload = await this.jwtService.verifyAsync(token);

if (payload.type !== 'reset-password') {
if (payload.type !== 'reset-password' && payload.type !== 'create-password') {
throw new BadRequestException('Token inválido');
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/modules/auth/guards/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: true,
secretOrKey: 'secret',
secretOrKey: process.env.JWT_SECRET!,
});
}

Expand Down
18 changes: 18 additions & 0 deletions backend/src/modules/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ export class EmailService {
`,
});
}

async sendCreatePasswordEmail(email: string, token: string) {
const apiUrl = process.env.API_URL || 'http://localhost:3000';
const createLink = `${apiUrl}/ProDeskApi/auth/redirect-app?token=${token}`;

await this.transporter.sendMail({
to: email,
subject: 'Criação de senha',
html: `
<h2>Bem-vindo!</h2>
<p>Sua conta foi aprovada.</p>
<p>Clique no link abaixo para criar sua senha:</p>
<a href="${createLink}">Criar senha</a>
<p>Se não abrir, copie o link:</p>
<p>${createLink}</p>
`,
});
}
}
18 changes: 18 additions & 0 deletions backend/src/modules/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { EmailModule } from '../email/email.module';
import { ConfigService } from '@nestjs/config';

@Module({
imports: [
JwtModule.registerAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
secret: configService.get<string>('JWT_SECRET'),
}),
}),
EmailModule,
],
exports: [JwtModule, EmailModule],
})
export class SharedModule {}
26 changes: 26 additions & 0 deletions backend/src/modules/user/accessRequest.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type AccessRequestDocument = AccessRequest & Document;

@Schema({ timestamps: true })
export class AccessRequest {
@Prop({ required: true })
name: string;

@Prop({ required: true })
email: string;

@Prop({ required: true })
cnpj: string;

@Prop({
type: String,
enum: ['PENDING', 'APPROVED', 'REJECTED'],
default: 'PENDING',
})
status: string;
}

export const AccessRequestSchema =
SchemaFactory.createForClass(AccessRequest);
39 changes: 39 additions & 0 deletions backend/src/modules/user/dtos/filterAccessRequestDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString, IsEnum, IsEmail } from 'class-validator';

export enum AccessRequestStatus {
PENDING = 'PENDING',
APPROVED = 'APPROVED',
REJECTED = 'REJECTED',
}

export class FilterAccessRequestDTO {
@ApiPropertyOptional({ example: 'João' })
@IsOptional()
@IsString()
name?: string;

@ApiPropertyOptional({ example: 'email@email.com' })
@IsOptional()
@IsString()
@IsEmail()
email?: string;

@ApiPropertyOptional({ example: '12345678000100' })
@IsOptional()
@IsString()
cnpj?: string;

@ApiPropertyOptional({ enum: AccessRequestStatus })
@IsOptional()
@IsEnum(AccessRequestStatus)
status?: AccessRequestStatus;

@ApiPropertyOptional({ example: 1 })
@IsOptional()
page?: number;

@ApiPropertyOptional({ example: 10 })
@IsOptional()
limit?: number;
}
18 changes: 18 additions & 0 deletions backend/src/modules/user/dtos/requestAccessDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, Length, Matches } from 'class-validator';

export class RequestAccessDTO {
@ApiProperty({ example: 'João Silva' })
@IsNotEmpty()
name: string;

@ApiProperty({ example: 'joao@email.com' })
@IsEmail()
email: string;

@ApiProperty({ example: '12345678000100' })
@IsNotEmpty()
@Length(14, 14)
@Matches(/^\d+$/, { message: 'CNPJ deve conter apenas números' })
cnpj: string;
}
Loading
Loading