update du code
This commit is contained in:
@@ -1,6 +1 @@
|
||||
{
|
||||
"utilisateur":{
|
||||
"id" : "admin",
|
||||
"password" : "28e55d1d25cd6e50cf4933c85636299367813225cecd7fd73c88282ed9e2c0d8"
|
||||
}
|
||||
}
|
||||
{"utilisateur": {"id": "admin", "password": "9ac564e9a29c952a3ddeffd8635adb0c252dbd1d58f3efde265e028f7f808aa9"}}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"utilisateur":{
|
||||
"id" : "admin",
|
||||
"password" : "28e55d1d25cd6e50cf4933c85636299367813225cecd7fd73c88282ed9e2c0d8"
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -70,6 +70,24 @@ def update_password():
|
||||
'''
|
||||
current_app.logger.info("Mise à jour du mot de passe de l'utilisateur")
|
||||
current_user = get_jwt_identity()
|
||||
current_app.logger.debug("request: {}".format(request))
|
||||
# recuperation des attributs JSON de la requete
|
||||
data_req = request.get_json()
|
||||
current_app.logger.debug("request: {}".format(data_req))
|
||||
# load data from JSON database
|
||||
with open(current_app.config['DB_PATH'], 'r') as f:
|
||||
data = json.load(f)
|
||||
if 'old' in data_req:
|
||||
if data_req['old'] != data['utilisateur']['password']:
|
||||
abort(status.HTTP_406_NOT_ACCEPTABLE, description="Mauvais ancien mot de passe")
|
||||
else:
|
||||
abort(status.HTTP_406_NOT_ACCEPTABLE, description="Ancien mot de passe invalide")
|
||||
if 'new' in data_req:
|
||||
data['utilisateur']['password'] = data_req['new']
|
||||
with open(current_app.config['DB_PATH'], 'w') as f:
|
||||
json.dump(data, f)
|
||||
else:
|
||||
abort(status.HTTP_406_NOT_ACCEPTABLE, description="Nouveau mot de passe invalide")
|
||||
|
||||
content = {'message':'maj password successful!'}
|
||||
return content, status.HTTP_200_OK
|
||||
|
||||
|
||||
+5
-2
@@ -78,8 +78,11 @@ def configure_app(app=None, config=None):
|
||||
jwt = JWTManager(app)
|
||||
# setup the Flask-CORS extension for handling Cross Origin Resource Sharing
|
||||
CORS(app, resources={r"/api/*": {
|
||||
# "origins": ["http://localhost:4200","http://localhost:6000"],
|
||||
"origins": "*",
|
||||
"origins": ["http://localhost:4200",
|
||||
"http://localhost:6000",
|
||||
"http://127.0.0.1:4200",
|
||||
"http://127.0.0.1:6000"],
|
||||
# "origins": "*",
|
||||
"supports_credentials": True
|
||||
}})
|
||||
return True
|
||||
|
||||
+3
-2
@@ -65,7 +65,8 @@ def refresh_expiring_tokens(response):
|
||||
|
||||
@auth.route('/login', methods=['POST'])
|
||||
def login():
|
||||
''' Authenticate User '''
|
||||
''' Authenticate User
|
||||
'''
|
||||
auth = request.authorization
|
||||
current_app.logger.info("Connexion de l'utilisateur : {}".format(auth.username))
|
||||
if not auth or not auth.username or not auth.password:
|
||||
@@ -120,7 +121,7 @@ def current_user():
|
||||
|
||||
@auth.route('/userConnected', methods=['GET'])
|
||||
def user_connected():
|
||||
''' retourne "oui" si un utilisateur est déjà connecté sinon "non"
|
||||
''' retourne "oui" si un utilisateur est déjà connecté sinon "non"
|
||||
'''
|
||||
flag = False
|
||||
resp = 'non'
|
||||
|
||||
+3
-2
@@ -32,6 +32,7 @@ class BaseConfig(object):
|
||||
# This should always be True in production
|
||||
JWT_COOKIE_CSRF_PROTECT = True
|
||||
JWT_CSRF_IN_COOKIES = True
|
||||
JWT_COOKIE_SAMESITE = "None"
|
||||
|
||||
STATIC_FOLDER = os.path.join(os.getcwd(), 'static')
|
||||
UPLOAD_FOLDER = STATIC_FOLDER + '/upload'
|
||||
@@ -46,10 +47,10 @@ class DefaultConfig(BaseConfig):
|
||||
TESTING = True
|
||||
FLASK_ENV = 'development'
|
||||
|
||||
SECRET_KEY = "secretkey1"
|
||||
SECRET_KEY = "secretkey10"
|
||||
|
||||
# Setup the Flask-JWT-Extended extension
|
||||
JWT_SECRET_KEY = "secretkeyjwt1"
|
||||
JWT_SECRET_KEY = "secretkeyjwt10"
|
||||
JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(minutes=10)
|
||||
DELTA = datetime.timedelta(minutes=5) # in minutes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user