diff --git a/src/api/routes.py b/src/api/routes.py index 9253ec024b..201a1efbc9 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -83,4 +83,25 @@ def login(): # # ESTE PROCESO DE DONDE SE GUARDA LOS LLEVA EL PERSONAL DE JWT except NoResultFound: - return jsonify ({"msg": "Bad password or email"}), 401 \ No newline at end of file + return jsonify ({"msg": "Bad password or email"}), 401 + + # Protect a route with jwt_required, which will kick out requests +# without a valid JWT present. +@api.route("/profile", methods=["GET"]) +# esto de abajo seria el portero de la analogia, entre la ruta y el metodo de autenticación +@jwt_required() +# cuando el corrobora el token entra a la funcion y especifica +def protected(): + # Access the identity of the current user with get_jwt_identity + # verifica la identidad ( de quien es el token ) , lo corrobora + current_user = get_jwt_identity() + + # con la identidad anterior nosotros hacemos una busqueda + + # user = db.session.execute(db.select(User).filter_by(email=current_user)).scalar_one() + + +#con la busqueda del señor anterior en la tabla favoritos fijate cuantos tiene y traemelos +# user = db.session.execute(db.select(User).filter_by(email=email)).scalar_one() + # la entidad verificada se guarda en el espacio de memoria + return jsonify(logged_in_as=current_user), 200 \ No newline at end of file diff --git a/src/front/js/pages/loginview.js b/src/front/js/pages/loginview.js index 7bc69160d1..8d5d7447c1 100644 --- a/src/front/js/pages/loginview.js +++ b/src/front/js/pages/loginview.js @@ -1,34 +1,45 @@ -import React, { useContext } from "react"; +import React, { useContext, useState } from "react"; import { Context } from "../store/appContext"; import "../../styles/home.css"; -import { Link } from "react-router-dom"; -import logo from "../store/logo-sin-fondo.jpg" +import { Link, useNavigate } from "react-router-dom"; +// import logo from "../store/logo-sin-fondo.jpg" export const Loginview = () => { - // const { store, actions } = useContext(Context); + const [email, setEmail] = useState("") + const [password, setPassword] = useState("") + const { store, actions } = useContext(Context); + let navigate = useNavigate(); + async function handleSubmit(e) { + e.preventDefault() + //console.log(email, password); + let logged = await actions.login(email, password) + if (logged === false) { + alert("email or password wrong") + }else{ + navigate("/profile") + } + } + // const { store, actions } = useContext(Context); return ( - -