Exemplo n.º 1
0
def createUser():
    data = request.get_json()
    name = data['name']
    surname = data['surname']
    email = data['email']
    password = data['password']
    
    result, u = user.SaveUser(name, surname, email, password)

    if result is not results.Result.OK:
        code = getErrorCode(result)
        return '', code
    else:
        return u, 201
Exemplo n.º 2
0
def createUser():
    data = request.get_json()
    name = data['name']
    surname = data['surname']
    email = data['email']
    password = data['password']

    res, dic = user.SaveUser(name, surname, email, password)

    if res is not statusLabels.Result.OK:
        code = getErrorCode(res)
        return '', code
    else:
        return dic, 201
Exemplo n.º 3
0
def manageUser():
    # POST
    if request.method == "POST":
        data = request.get_json()
        name = data['name']
        surname = data['surname']
        email = data['email']
        password = data['password']

        result, u = user.SaveUser(name, surname, email, password)

        if result is not user.Result.OK:
            code = getErrorCode(result)
            return '', code
        else:
            return u, 201

    # DELETE
    elif request.method == "DELETE":
        auth = request.authorization
        if auth is None:
            return '', 403

        email = auth['username']
        pwd = auth['password']
        authorized, usr = user.Login(email, pwd)

        if authorized is not user.Result.OK:
            code = getErrorCode(authorized)
            return '', code

        result = user.DeleteUser(usr['email'])
        if result is not user.Result.OK:
            code = getErrorCode(result)
            return '', code
        else:
            return '', 200

    # OTHER REQUESTS
    else:
        return '', 400