Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: alterando o código do login para reenviar o email de confirmação após uma tentativa de login onde a conta ainda não foi confirmada #73

Merged
merged 2 commits into from
Jun 29, 2024
Merged
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
12 changes: 10 additions & 2 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import { InfoLoginDto } from './dtos/info-login.dto';
import { accessAttemptMessage } from './enums/message.enum';
import { UserRepository } from '../user/user.repository';
import { InfoEntity } from './entity/info.entity';
import { MailService } from '../mails/mail.service';
import { MentorEntity } from '../mentors/entities/mentor.entity';
import { UserEntity } from '../user/entities/user.entity';

@Injectable()
export class AuthService {
constructor(
private mentorRepository: MentorRepository,
private userRepository: UserRepository,
private jwt: JwtService,
private mailService: MailService,
) {}

async execute({ email, password, type}: InfoLoginDto) {
Expand All @@ -22,7 +26,7 @@ export class AuthService {
} else {
info = await this.userRepository.findUserByEmail(email)
}
this.infoConfirm(info);
await this.infoConfirm(info, type);

const passwordIsValid = await bcrypt.compare(password, info.password);

Expand Down Expand Up @@ -52,7 +56,7 @@ export class AuthService {
};
}

infoConfirm(info: InfoEntity) {
async infoConfirm(info: InfoEntity, type: string) {
if (!info || info.deleted == true) {

const message = "invalid e-mail or password"
Expand All @@ -63,6 +67,10 @@ export class AuthService {
if (!info.emailConfirmed) {

const message = 'Your account is not activated yet. Check your e-mail inbox for instructions'

if(type == 'mentor') await this.mailService.mentorSendCreationConfirmation(info as MentorEntity)
if(type == 'user') await this.mailService.userSendCreationConfirmation(info as UserEntity)

throw new HttpException({ message }, HttpStatus.NOT_FOUND)

}
Expand Down