|
@@ -7,14 +7,14 @@ import logging
|
|
import persistence
|
|
import persistence
|
|
import Model.isp_model as isp_model
|
|
import Model.isp_model as isp_model
|
|
import Model.model_manager as model_manager
|
|
import Model.model_manager as model_manager
|
|
-from werkzeug.security import check_password_hash
|
|
|
|
|
|
+from werkzeug.security import check_password_hash,generate_password_hash
|
|
import View.view_privilege as privileges
|
|
import View.view_privilege as privileges
|
|
import Modules.Inventory.inventory_view as inventory_view
|
|
import Modules.Inventory.inventory_view as inventory_view
|
|
from datetime import timedelta
|
|
from datetime import timedelta
|
|
import View.view_error_management as view_error_management
|
|
import View.view_error_management as view_error_management
|
|
from flask_limiter import Limiter
|
|
from flask_limiter import Limiter
|
|
from flask_limiter.util import get_remote_address
|
|
from flask_limiter.util import get_remote_address
|
|
-from flask_cors import CORS
|
|
|
|
|
|
+
|
|
|
|
|
|
logger = logging.getLogger(logger_name + ".VIEW")
|
|
logger = logging.getLogger(logger_name + ".VIEW")
|
|
|
|
|
|
@@ -32,6 +32,7 @@ limiter = Limiter(__app__,key_func=get_remote_address,default_limits=["500 per m
|
|
limiter.logger = logger
|
|
limiter.logger = logger
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
from werkzeug.serving import make_server
|
|
from werkzeug.serving import make_server
|
|
class ServerThread(threading.Thread):
|
|
class ServerThread(threading.Thread):
|
|
|
|
|
|
@@ -95,7 +96,7 @@ def after_request(response):
|
|
# for exemple origin cross origin is when website with javascript has it's server (origin 1)
|
|
# for exemple origin cross origin is when website with javascript has it's server (origin 1)
|
|
# and the javascript call some request on another server (origin 2), typically our API.
|
|
# and the javascript call some request on another server (origin 2), typically our API.
|
|
header['Access-Control-Allow-Origin'] = '*'
|
|
header['Access-Control-Allow-Origin'] = '*'
|
|
- header['Access-Control-Allow-Methods'] = 'GET,HEAD,OPTIONS,POST,PUT'
|
|
|
|
|
|
+ header['Access-Control-Allow-Methods'] = 'GET,DELETE,UPDATE,HEAD,OPTIONS,POST,PUT'
|
|
header['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
|
|
header['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
|
|
return response
|
|
return response
|
|
|
|
|
|
@@ -132,7 +133,6 @@ def login():
|
|
resp.status_code = 200
|
|
resp.status_code = 200
|
|
return resp
|
|
return resp
|
|
|
|
|
|
-
|
|
|
|
@__app__.route('/api/logout',methods = ['DELETE'])
|
|
@__app__.route('/api/logout',methods = ['DELETE'])
|
|
def logout():
|
|
def logout():
|
|
logger.info("account " + session["username"] + " logged OUT with id : " + session["client_id"])
|
|
logger.info("account " + session["username"] + " logged OUT with id : " + session["client_id"])
|
|
@@ -140,6 +140,24 @@ def logout():
|
|
return jsonify('logout')
|
|
return jsonify('logout')
|
|
|
|
|
|
|
|
|
|
|
|
+@__app__.route('/api/password',methods = ['POST'])
|
|
|
|
+def change_password():
|
|
|
|
+ _json = request.json
|
|
|
|
+ _old_password = _json['old_password']
|
|
|
|
+ _password = _json['new_password']
|
|
|
|
+ with persistence.get_Session_Instance() as sess :
|
|
|
|
+ Item : isp_model.user_account = sess.query(isp_model.user_account).filter(isp_model.user_account.id == session["user_account_id"]).first()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if not check_password_hash(Item.password,_password) :
|
|
|
|
+ raise Exception("old password is incorrect")
|
|
|
|
+
|
|
|
|
+ Item.password = generate_password_hash(_password)
|
|
|
|
+ sess.commit()
|
|
|
|
+
|
|
|
|
+ return jsonify('password changed')
|
|
|
|
+
|
|
|
|
+
|
|
@__app__.route('/routes',methods = ['GET'])
|
|
@__app__.route('/routes',methods = ['GET'])
|
|
@privileges.manager.require_authorization(required_role=inventory_view.inventory_admin_role,get_privilege_func=get_user_privilege)
|
|
@privileges.manager.require_authorization(required_role=inventory_view.inventory_admin_role,get_privilege_func=get_user_privilege)
|
|
def routes():
|
|
def routes():
|