generated from Arquisoft/dede_0
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from Arquisoft/uo271411-login-backend
Login backend
- Loading branch information
Showing
12 changed files
with
141 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import mongoose, { ObjectId } from 'mongoose'; | ||
|
||
export interface IUsuario { | ||
username:String; | ||
password:String; | ||
} | ||
|
||
interface UsuarioDoc extends mongoose.Document { | ||
_id: ObjectId; | ||
username:String; | ||
password:String; | ||
} | ||
|
||
interface UsuarioModelInterface extends mongoose.Model<UsuarioDoc> { | ||
build(attr: IUsuario): UsuarioDoc | ||
} | ||
|
||
const usuarioSchema = new mongoose.Schema({ | ||
username: { | ||
type: String, | ||
required: true, | ||
trim: true | ||
}, | ||
password: { | ||
type: String, | ||
required: true, | ||
trim: true | ||
} | ||
}) | ||
|
||
usuarioSchema.statics.build = (attr: IUsuario) => { | ||
return new Usuario(attr) | ||
} | ||
|
||
const Usuario:UsuarioModelInterface = mongoose.model<UsuarioDoc,UsuarioModelInterface>('Usuario',usuarioSchema) | ||
|
||
export default Usuario | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import express, { Request, Response } from 'express'; | ||
import Usuario from '../modelos/usuarioModelo'; | ||
import "dotenv/config"; | ||
import {User} from '../../webapp/src/shared/shareddtypes'; | ||
|
||
//Obtenemos la url de la apirest de Heroku o utilizamos localhost por defecto | ||
let URL_BASE:string = `${process.env.API_REST_URL_BASE_LOCAL}` | ||
if(process.env.PORT) { | ||
URL_BASE = `${process.env.API_REST_URL_BASE_HEROKU}` | ||
} | ||
|
||
const router = express.Router() | ||
|
||
router.get('/users/login/:username/:password', async (req: Request, res: Response) => { | ||
let resultado:User[] = new Array<User>(); | ||
//Parametros | ||
const paramUser:string = req.params.username; | ||
const paramPass:string = req.params.password; | ||
//Realizamos la busqueda por referencia | ||
const user = await Usuario.findOne({username: paramUser, password: paramPass}) | ||
if(user){ | ||
let entrada = user; | ||
let salida: User = ({ username: "", password:""}); | ||
salida.username = entrada.username.toString(); | ||
salida.password = entrada.password.toString(); | ||
resultado.push(salida); | ||
return res.status(200).send(resultado); | ||
} else{ | ||
return res.status(500).json(); | ||
} | ||
|
||
}) | ||
|
||
export { router as usuarioRouter } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters