change format name
This commit is contained in:
@@ -44,10 +44,12 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
|||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const email = profile.emails?.[0]?.value || '';
|
const email = profile.emails?.[0]?.value || '';
|
||||||
|
const nombre = profile.name?.givenName || '';
|
||||||
const apellido = profile.name?.familyName || '';
|
const apellido = profile.name?.familyName || '';
|
||||||
|
|
||||||
const user = await this.personaService.validateOrCreateGoogleUser({
|
const user = await this.personaService.validateOrCreateGoogleUser({
|
||||||
email,
|
email,
|
||||||
|
nombre,
|
||||||
apellido,
|
apellido,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -52,32 +52,42 @@ export class PersonaService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateOrCreateGoogleUser(data: { email: string; apellido: string }) {
|
async validateOrCreateGoogleUser(data: {
|
||||||
|
email: string;
|
||||||
|
nombre: string;
|
||||||
|
apellido: string;
|
||||||
|
}) {
|
||||||
let persona = await this.findByEmail(data.email);
|
let persona = await this.findByEmail(data.email);
|
||||||
|
|
||||||
if (!persona) {
|
if (!persona) {
|
||||||
const apellidoArray = data.apellido.split(' ');
|
const apellidoArray = data.apellido.split(' ');
|
||||||
|
|
||||||
const apellidoP = apellidoArray[0] || '';
|
const apellidoP = apellidoArray[0] || '';
|
||||||
const apellidoM = apellidoArray[1] || '';
|
const apellidoM = apellidoArray[1] || '';
|
||||||
const nombre = apellidoArray.slice(2).join(' ') || '';
|
let realName;
|
||||||
|
|
||||||
const numeroIdentificar = data.email.split('@')[0];
|
const numeroIdentificar = data.email.split('@')[0];
|
||||||
|
|
||||||
const password = await passwordRand(12);
|
let tipo;
|
||||||
let hash = await bcrypt.hashSync(password, 13);
|
if (Number(numeroIdentificar) === 9) {
|
||||||
|
tipo = 'Alumno';
|
||||||
|
realName = apellidoArray.slice(2).join(' ') || '';
|
||||||
|
} else {
|
||||||
|
tipo = 'Academico';
|
||||||
|
realName = data.nombre;
|
||||||
|
}
|
||||||
|
|
||||||
persona = await this.create({
|
persona = await this.create({
|
||||||
nombre: nombre || '',
|
nombre: realName || '',
|
||||||
apellidoP: apellidoP || '',
|
apellidoP: apellidoP || '',
|
||||||
apellidoM: apellidoM || '',
|
apellidoM: apellidoM || '',
|
||||||
password: hash,
|
password: '',
|
||||||
fechaPasswordTem: new Date(),
|
fechaPasswordTem: new Date(),
|
||||||
correo: data.email,
|
correo: data.email,
|
||||||
carreraAds: 'Mac',
|
carreraAds: '',
|
||||||
cantidadCuenta: 0,
|
cantidadCuenta: 0,
|
||||||
usuario: numeroIdentificar || '',
|
usuario: numeroIdentificar,
|
||||||
numeroIdentificar: numeroIdentificar || '',
|
numeroIdentificar: numeroIdentificar || '',
|
||||||
tipoUsuario: 'Alumno',
|
tipoUsuario: tipo,
|
||||||
correoEnviado: false,
|
correoEnviado: false,
|
||||||
fechaRegistro: new Date(),
|
fechaRegistro: new Date(),
|
||||||
cambioPasswordReq: true,
|
cambioPasswordReq: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user