Login done
This commit is contained in:
@@ -13,14 +13,14 @@ def login():
|
|||||||
username = data.get('username')
|
username = data.get('username')
|
||||||
password = data.get('password')
|
password = data.get('password')
|
||||||
|
|
||||||
# Aquí se validan las credenciales (en este caso un ejemplo simple)
|
if username and password:
|
||||||
if username == 'admin' and password == 'password':
|
user = User.query.filter_by(username=username).first()
|
||||||
# Generar token
|
if user and user.check_password(password):
|
||||||
token = jwt.encode({
|
token = jwt.encode({
|
||||||
'username': username,
|
'username': username,
|
||||||
'exp': datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=1)
|
'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
|
}, current_app.config['SECRET_KEY'], algorithm='HS256')
|
||||||
return jsonify({'token': token})
|
return jsonify({'token': token})
|
||||||
|
|
||||||
return jsonify({'message': 'Credenciales inválidas'}), 401
|
return jsonify({'message': 'Credenciales inválidas'}), 401
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user