diff --git a/requirements.txt b/requirements.txt index 4eac45f4f8..e3775bea35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,8 @@ flask-cors==3.0.10 flask-migrate==2.6.0 flask-sqlalchemy==2.4.4 flask-swagger==0.2.14 + + gunicorn==20.0.4 itsdangerous==1.1.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' jinja2==2.11.3; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' diff --git a/src/api/routes/user.py b/src/api/routes/user.py index 26a267e607..2d2dbeacdc 100644 --- a/src/api/routes/user.py +++ b/src/api/routes/user.py @@ -1,23 +1,50 @@ -from flask import Flask, request, jsonify, url_for, Blueprint # type: ignore +from flask import Flask, request, jsonify, url_for, Blueprint # type: ignore from api.models.User import User from api.database.db import db -import bcrypt # type: ignore -from flask_jwt_extended import create_access_token, jwt_required, get_jwt_identity # type: ignore +import bcrypt # type: ignore +from flask_jwt_extended import create_access_token, jwt_required, get_jwt_identity # type: ignore +from datetime import datetime, timedelta + +import secrets; + + + + api = Blueprint("api/user", __name__) -# MOSTRAR TODOS LOS USUARIOS -# @api.route("/users", methods = ["GET"]) -# def get_all_users(): -# users = User.query.all() -# if users is None: -# return jsonify("Error, no hemos encontrado ningun usuario"),404 -# users = list(map(lambda x : x.serialize(),users)) -# return jsonify({"all_users": users}),200 + + + +# ENVIAR EMAIL RESET PASSWORD +@api.route("/resetPassword", methods=["POST"]) +def forget_password(user): + body = request.get_json() + user = User.query.filter_by(email=body["email"]).first() + + if user is None: + return jsonify("La cuenta no existe"), 404 + + + + token = secrets.token_urlsafe(75) + user.reset_token = token + user.reset_token_expires = datetime.utcnow() + timedelta(minutes=30) + reset_url_password = f"https://jubilant-spork-7v5jg5r9r9p73xpqq-3001.app.github.dev/api/user/reset-password?token={token}" + db.session.commit() + + + + return jsonify("¡Correo electrónico enviado exitosamente!") + + + # REGISTRO DE UN NUEVO USER + + @api.route('/register', methods=["POST"]) def register_user(): body = request.get_json() @@ -30,7 +57,7 @@ def register_user(): return jsonify("Error, debes introducir los campos obligatorios"), 404 new_user = User() - + new_user.username = body["username"] new_user.email = body["email"] new_user.password = new_password.decode() @@ -39,9 +66,11 @@ def register_user(): db.session.add(new_user) db.session.commit() - return jsonify("Usuario creado"),200 + return jsonify("Usuario creado"), 200 # REALIZAR UN LOGIN DE UN USUARIO + + @api.route("/login", methods=["POST"]) def user_login(): body = request.get_json() @@ -59,15 +88,16 @@ def user_login(): return jsonify("contraseña no valida"), 400 -@api.route("/", methods = ["GET"]) + +@api.route("/", methods=["GET"]) @jwt_required() def get_user(): current_user = get_jwt_identity() user = User.query.get(current_user) if user is None: - return jsonify("El usuario no valido"),404 - + return jsonify("El usuario no valido"), 404 + return jsonify({"User": user.serialize()}) @@ -82,6 +112,3 @@ def get_user(): # db.session.commit() # return jsonify("El usuario ha sido eliminado correctamente"),200 - - - diff --git a/src/front/pages/login/Login.jsx b/src/front/pages/login/Login.jsx index 3c901246f7..453d3589bf 100644 --- a/src/front/pages/login/Login.jsx +++ b/src/front/pages/login/Login.jsx @@ -95,13 +95,18 @@ export const Login = () => {
-

¿No tienes cuenta? Registrate ya +

¿No tienes cuenta? Registrate ya

+ +

Has olvidado tu contraseña?Pincha aqui

+ + +
diff --git a/src/front/pages/recPassword/RecPassword.jsx b/src/front/pages/recPassword/RecPassword.jsx new file mode 100644 index 0000000000..19e224cee2 --- /dev/null +++ b/src/front/pages/recPassword/RecPassword.jsx @@ -0,0 +1,66 @@ +import useGlobalReducer from "../../hooks/useGlobalReducer"; + + + +export const RecPassword = () =>{ + + + + + + + + + + + return( +
+
+

Recuperar contraseña

+

+ Ingresa tu email y te enviaremos un enlace para restablecer tu contraseña +

+
+ +
+
+
+
+ +
+ +
+
+ +
+ +
+ +
+ + ← Volver al inicio de sesión + +
+
+
+
+
+ + + ) +} \ No newline at end of file diff --git a/src/front/pages/resetPassword/ResetPassword.jsx b/src/front/pages/resetPassword/ResetPassword.jsx new file mode 100644 index 0000000000..dee9c6b88d --- /dev/null +++ b/src/front/pages/resetPassword/ResetPassword.jsx @@ -0,0 +1,21 @@ +export const ResetPassword = () =>{ + return( +
+

Nueva contraseña

+
+
+ + +
+
+ +
+
+
+ + ) +} \ No newline at end of file diff --git a/src/front/routes.jsx b/src/front/routes.jsx index c877410bd0..47da69df4e 100644 --- a/src/front/routes.jsx +++ b/src/front/routes.jsx @@ -18,10 +18,16 @@ import { Addgame } from "./pages/addgame/Addgame.jsx"; import { DetailsGames } from "./pages/detailsGames/DetailsGames.jsx"; import { Carro } from "./pages/carro/Carro.jsx"; import { Historial } from "./pages/historial/Historial.jsx"; + +import { RecPassword } from "./pages/recPassword/RecPassword.jsx"; +import { ResetPassword } from "./pages/resetPassword/ResetPassword.jsx"; + + import { EditGames } from "./pages/editgames/EditGames.jsx"; + export const router = createBrowserRouter( createRoutesFromElements( // CreateRoutesFromElements function allows you to build route elements declaratively. @@ -46,10 +52,17 @@ export const router = createBrowserRouter( } /> {/* PAGINA DETALLES GAMES*/} } /> {/* PAGINA Carrito*/} } /> + + } /> + } /> + + + } /> {/* PAGINA DETALLES GAMES*/} + ) diff --git a/src/front/store.js b/src/front/store.js index d07ba391a2..fed943fc49 100644 --- a/src/front/store.js +++ b/src/front/store.js @@ -4,6 +4,7 @@ export const initialStore = () => { user: null, all_games: [], carro: [], // <- añadido + }; }; @@ -24,6 +25,7 @@ export default function storeReducer(store, action = {}) { todo.id === id ? { ...todo, background: color } : todo ), }; + case "setGames": return {