commit
6668c43afc
|
@ -5,7 +5,6 @@
|
|||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "api-gateway",
|
||||
"version": "0.0.1",
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
|
|
|
@ -44,6 +44,14 @@ export class AppController {
|
|||
return this.appService.allUsers();
|
||||
}
|
||||
|
||||
@Post('user/loginUser')
|
||||
inicioSesion(
|
||||
@Body('email') pEmail: string,
|
||||
@Body('password') pPassword: string,
|
||||
) {
|
||||
return this.appService.inicioSesion(pEmail,pPassword);
|
||||
}
|
||||
|
||||
@Get('user/find/:dni')
|
||||
findUser(
|
||||
@Param('dni') paramUserDNI: string
|
||||
|
|
|
@ -71,6 +71,16 @@ export class AppService {
|
|||
);
|
||||
}
|
||||
|
||||
inicioSesion(pEmail: string, pPassword: string) {
|
||||
const pattern = { cmd: 'loginUser' };
|
||||
const payload = { email: pEmail, password: pPassword};
|
||||
return this.clientUserApp
|
||||
.send<string>(pattern, payload)
|
||||
.pipe(
|
||||
map((message: string) => ({ message })),
|
||||
);
|
||||
}
|
||||
|
||||
// ====================== COMMUNITIES ===============================
|
||||
|
||||
//POST parameter from API
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "katoikia-app",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -28,6 +28,9 @@
|
|||
"@nestjs/mongoose": "^9.1.1",
|
||||
"@nestjs/platform-express": "^8.0.0",
|
||||
"@nestjs/swagger": "^5.2.1",
|
||||
"buffer": "^5.7.1",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"md5-typescript": "^1.0.5",
|
||||
"mongoose": "^6.4.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
|
|
|
@ -38,4 +38,12 @@ export class UsersController {
|
|||
let dni = id['dni'];
|
||||
return this.userService.remove(dni);
|
||||
}
|
||||
|
||||
//inicio de sesion
|
||||
@MessagePattern({ cmd: 'loginUser' })
|
||||
findLogin(@Payload() body:string) {
|
||||
let pemail= body['email'];
|
||||
let ppassword= body['password'];
|
||||
return this.userService.findLogin(pemail,ppassword);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,14 @@ import { Injectable } from '@nestjs/common';
|
|||
import { Model } from 'mongoose';
|
||||
import { User, UserDocument } from '../schemas/user.schema';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import {Md5} from "md5-typescript";
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(
|
||||
@InjectModel(User.name) private readonly userModel: Model<UserDocument>,
|
||||
) {}
|
||||
|
||||
private publicKey: string;
|
||||
async create(user: UserDocument): Promise<User> {
|
||||
return this.userModel.create(user);
|
||||
}
|
||||
|
@ -37,4 +38,29 @@ export class UsersService {
|
|||
async remove(id: string) {
|
||||
return this.userModel.findByIdAndRemove({ _id: id }).exec();
|
||||
}
|
||||
|
||||
//inicio de sesion
|
||||
async findLogin(email: string, password: string) : Promise<User> {
|
||||
let repo1=this.userModel;
|
||||
let userReturn = new Promise<User>((resolve, reject) => {
|
||||
let repo =repo1;
|
||||
|
||||
repo.find({ email : email }).exec((err, res) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
let passwordEncriptada=Md5.init(password);
|
||||
if (res[0].password==passwordEncriptada) {
|
||||
resolve(res[0]);
|
||||
}
|
||||
else {
|
||||
resolve(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return userReturn;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue