Skip to content

Commit

Permalink
Merge pull request #73 from BiancaPaccola/main
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thiagorcode authored Jun 29, 2024
2 parents 995c621 + e8010c7 commit c867c4c
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit c867c4c

Please sign in to comment.