added hased password
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
export default function passwordRand(length: number): string {
|
||||
const characters =
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
let pass = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
pass += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
}
|
||||
|
||||
return pass;
|
||||
}
|
||||
@@ -3,6 +3,9 @@ import { JwtService } from '@nestjs/jwt';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Persona } from './entities/persona.entity';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
|
||||
import passwordRand from './password';
|
||||
@Injectable()
|
||||
export class PersonaService {
|
||||
constructor(
|
||||
@@ -36,7 +39,7 @@ export class PersonaService {
|
||||
let persona = await this.findByEmail(data.email);
|
||||
|
||||
if (!persona) {
|
||||
const apellidoArray = data.apellido.trim().split(' ');
|
||||
const apellidoArray = data.apellido.split(' ');
|
||||
const apellidoP = data.apellido[0] || '';
|
||||
const apellidoM = data.apellido[1] || '';
|
||||
const nombre = apellidoArray.slice(2).join(' ') || '';
|
||||
@@ -44,19 +47,21 @@ export class PersonaService {
|
||||
// Número identificador del correo
|
||||
const numeroIdentificar = data.email.split('@')[0];
|
||||
|
||||
const password = await passwordRand(12);
|
||||
let hash = await bcrypt.hashSync(password, 13);
|
||||
|
||||
persona = await this.create({
|
||||
nombre: nombre || '',
|
||||
apellidoP: apellidoP || '',
|
||||
apellidoM: apellidoM || '',
|
||||
password: '',
|
||||
passwordTem: '',
|
||||
password: hash,
|
||||
fechaPasswordTem: new Date(),
|
||||
correo: data.email,
|
||||
carreraAds: '',
|
||||
carreraAds: 'Mac',
|
||||
cantidadCuenta: 0,
|
||||
usuario: '',
|
||||
usuario: numeroIdentificar || '',
|
||||
numeroIdentificar: numeroIdentificar || '',
|
||||
tipoUsuario: '',
|
||||
tipoUsuario: 'Alumno',
|
||||
correoEnviado: false,
|
||||
fechaRegistro: new Date(),
|
||||
cambioPasswordReq: true,
|
||||
|
||||
Reference in New Issue
Block a user