First login done

This commit is contained in:
victor
2024-12-06 00:27:27 +01:00
parent 28ac497c57
commit 13fe482956
4 changed files with 60 additions and 0 deletions

22
app/codes/user.py Normal file
View File

@@ -0,0 +1,22 @@
from flask import Blueprint, request, jsonify, current_app
import datetime
import jwt
login = Blueprint('login', __name__)
@login.route('/login', methods=['POST'])
def login_view():
data = request.get_json()
username = data.get('username')
password = data.get('password')
# Aquí se validan las credenciales (en este caso un ejemplo simple)
if username == 'admin' and password == 'password':
# Generar token
token = jwt.encode({
'username': username,
'exp': datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=1)
}, current_app.config['SECRET_KEY'], algorithm='HS256') # Usamos current_app para acceder a la configuración
return jsonify({'token': token})
return jsonify({'message': 'Credenciales inválidas'}), 401