def wrap(*args, **kwargs): activity = ActivityLog.getInstance() if session.get("logged_in"): return f(*args, **kwargs) if not log_message == "": message = log_message.format(**kwargs) activity.logger.error(message) return jsonify(status="error", message="Session expired"), 401
def wrap(*args, **kwargs): activity = ActivityLog.getInstance() username = session["username"] usertypecode = session["usertypecode"] if usertypecode == 0: return f(*args, **kwargs) if not log_message == "": message = log_message.format(**kwargs) activity.logger.error("{0}: {1}".format(username, message)) return ( jsonify(status="error", message="You are not authorized this action"), 403, )
from flask import Blueprint, jsonify, session, request from decorators import is_user_logged_in from loggers import ActivityLog import controllers profile = Blueprint("profile", __name__) activity = ActivityLog.getInstance() @profile.route("/", methods=["GET"]) @is_user_logged_in("Illegal request to get your own information") def get_own_info(): user = controllers.get_user(session["username"]) print(user) return jsonify(status="success", user=user) @profile.route("/password/", methods=["PUT"]) @is_user_logged_in("Illegal request to change your own password.") def change_own_password(): username = session["username"] data = request.get_json() old_password = data.get("oldPassword") new_password = data.get("newPassword") if old_password == "" or new_password == "": return ( jsonify( status="error", message="Please enter valid value old password or new_password", ),
from flask import Blueprint, jsonify, request, g from decorators import is_user_logged_in from loggers import ActivityLog import controllers from models import User profile = Blueprint("profile", __name__) activity = ActivityLog.getInstance() @profile.route("/", methods=["GET"]) @is_user_logged_in("Illegal request to get your own information") def get_own_info(): user = controllers.get_user(g.user.username) print(user) return jsonify(status="success", user=user) @profile.route("/password/", methods=["PUT"]) @is_user_logged_in("Illegal request to change your own password.") def change_own_password(): username = g.user.username data = request.get_json() old_password = data.get("oldPassword") new_password = data.get("newPassword") if old_password == "" or new_password == "": return ( jsonify( status="error", message="Please enter valid value old password or new_password",