Exemplo n.º 1
0
def register():
    flask.request.json["date"] = datetime.datetime.now()
    print(flask.request.json)
    user_controller = UserController()
    if user_controller.get_user(flask.request.json['username']) is None:
        user_controller.insert_user(flask.request.json)
        return "OK"
    else:
        return json.dumps({"msg": "User is already registered"}), 401
Exemplo n.º 2
0
def get_user():
    if GetRole() == "admin":
        user_controller = UserController()
        username = request.args.get('username')
        user_dict = user_controller.get_user(username)
        user_json = json.dumps(user_dict)
        return user_json
    else:
        return json.dumps({"msg": "Permission denied"}), 401
Exemplo n.º 3
0
def login():
    user_controller = UserController()
    username_password_dict = flask.request.json
    username_from_req = username_password_dict['username']

    user_from_db = user_controller.get_user(username_from_req)

    username = user_from_db['username']
    password = user_from_db['password']

    if username != username_password_dict[
            'username'] or password != username_password_dict['password']:
        return json.dumps({"msg": "Bad username or password"}), 401

    session["role"] = user_from_db["role"]
    return json.dumps({"msg": "Success"}), 200