Exemple #1
0
def delete_user():
    data = request.get_json()
    uid_list = data["uids"]
    for uid in uid_list:
        logger.info(f"Deleting use with uid {uid}")
        AccountUser.delete(uid)
    return "deleteing user registration successful."
Exemple #2
0
def update_user():
    data = request.get_json()
    logger.info(data)
    uid = data["uid"]
    for attribute_name, value in data["update_data"].items():
        logger.info(f"Patching {attribute_name} with {value} for user {uid}")
        AccountUser.update(uid, attribute_name, value)
    return "updating registration successful."
Exemple #3
0
def add_user(data):
    logger.info(data)
    logger.info("Creating user.")
    newUser = AccountUser()
    newUser.username = data["username"]
    newUser.password_hash = data["password"]
    newUser.email = data["email"]

    if not "profile" in data:
        newUser.profile = getDefaultProfileObject()
    else:
        newUser.profile = Profile(profile_image = data["profile"]["profile_image"], about = data["profile"]["about"])

    newUser.create()
    return "user registration successful."
Exemple #4
0
 def inner(*args, **kwargs):
     logger.info("authenticating")
     # logger.info(request.headers)
     if "USER-API-KEY" in request.headers and "USERNAME" in request.headers:
         user = AccountUser.exists(request.headers.get("Username"),
                                   request.headers.get("User-Api-Key"))
         if user:
             logger.info("Authenticated!!")
         else:
             return "Unauthorized", 403
     else:
         return "Unauthorized", 403
     return content_func(*args, **kwargs)
Exemple #5
0
 def inner(*args, **kwargs):
     logger.debug("authenticating")
     logger.debug(request.headers)
     if "USER-API-KEY" in request.headers and "USERNAME" in request.headers:
         user = AccountUser.exists(request.headers.get("USER-API-KEY"), request.headers.get("USERNAME"))
         logger.info(user)
         if user:
             print("Authenticated!!")
             return "Unauthorized", 401
         else:
             return "Unauthorized", 401
     else:
         return "Unauthorized", 401
     return content_func(*args, **kwargs)
Exemple #6
0
def get_user():
    def formatify(ob):
        profile_ob = None
        if hasattr(ob, "profile"):
            profile_ob = formatify(ob.profile)
        
        ob = json.loads(json.dumps(dict(ob.__dict__), default=str))
        
        if profile_ob:
            ob.pop('profile')
            ob["profile"] = profile_ob
            
        ob.pop('id')
        ob.pop('_sa_instance_state')

        return ob

    out = [formatify(record) for record in AccountUser.get()]
    return jsonify(out)
Exemple #7
0
def loginUser():
    data = request.get_json()
    user = AccountUser.login(data["username"], data["password"])
    if user:
        return jsonify({"data":user})
    return jsonify({"message":"No such user or unauthorized."})
Exemple #8
0
def authorizeUser():
    data = request.get_json()
    isValid = AccountUser.exists(data["username"], data["apiKey"])
    return jsonify({"data":{"isValid":isValid}})