Exemple #1
0
def update_user():
    data = json.loads(request.data.decode())

    user = User.query.filter_by(token=data['token']).first()

    if check_token(user):
        return {"status": "Error", "massage": "Authenticate"}, 401

    if not (data['new_login'] == user.login):
        user_new = User.query.filter_by(login=data["new_login"]).first()
        if user_new is not None:
            return {
                "status": "Error",
                "massage": "Already exists this login"
            }, 422

    passes = user.posts.all()

    for a in passes:
        a.password = password_encrypt(a.non_hash_password().encode(),
                                      data['new_password'])

    user.login = data['new_login']
    user.password = password_encrypt(data['new_password'].encode(),
                                     data['token'])

    db.session.commit()

    return {"status": "Success"}
Exemple #2
0
def update():
    data = json.loads(request.data.decode())

    user = User.query.filter_by(token=data['token']).first()

    if check_token(user):
        return {"status": "Error", "massage": "Authenticate"}, 401

    passes = user.posts.filter_by(name_place=data['name_place']).filter_by(
        login=data["login"]).first()

    if passes is None:
        return {
            "status": "Error",
            "massage": "Invalid name_place or login"
        }, 422

    if not (data['new_login'] == data['login']):
        passes_new = user.posts.filter_by(
            name_place=data['name_place']).filter_by(
                login=data["new_login"]).first()
        if passes_new is not None:
            return {
                "status": "Error",
                "massage": "Already exists this login"
            }, 422

    passes.login = data['new_login']
    passes.password = password_encrypt(data['new_password'].encode(),
                                       user.non_hash_password())
    passes.tag = data['new_tag']

    db.session.commit()
    return {"status": "Success"}
Exemple #3
0
def get_all():
    data = json.loads(request.data.decode())

    user = User.query.filter_by(token=data['token']).first()

    if check_token(user):
        return {"status": "Error", "massage": "Authenticate"}, 401

    passes = user.posts.all()

    return {"status": "Success", "result": list(map(Password.printer, passes))}
Exemple #4
0
def delete_user():
    data = json.loads(request.data.decode())

    user = User.query.filter_by(token=data['token']).first()

    if check_token(user):
        return {"status": "Error", "massage": "Authenticate"}, 401

    passes = user.posts.all()

    for _pass in passes:
        db.session.delete(_pass)

    db.session.delete(user)
    db.session.commit()
    return {"status": "Success"}
Exemple #5
0
def delete():
    data = json.loads(request.data.decode())

    user = User.query.filter_by(token=data['token']).first()

    if check_token(user):
        return {"status": "Error", "massage": "Authenticate"}, 401

    passes = user.posts.filter_by(name_place=data['name_place']).filter_by(
        login=data['login']).first()

    if passes is None:
        return {
            "status": "Error",
            "massage": "Not found name_place or login"
        }, 422

    db.session.delete(passes)
    db.session.commit()
    return {"status": "Success"}
Exemple #6
0
def get_on_tag():
    data = json.loads(request.data.decode())

    user = User.query.filter_by(token=data['token']).first()

    if check_token(user):
        return {"status": "Error", "massage": "Authenticate"}, 401

    passes = user.posts.filter_by(tag=data['tag']).all()

    return {
        "status":
        "Success",
        "result":
        list(
            map(
                lambda a: {
                    "name_place": a.name_place,
                    "login": a.login,
                    "password": a.non_hash_password()
                }, passes))
    }
Exemple #7
0
def insert():
    data = json.loads(request.data.decode())

    user = User.query.filter_by(token=data['token']).first()

    if check_token(user):
        return {"status": "Error", "massage": "Authenticate"}, 401

    passes = user.posts.filter_by(name_place=data['name_place']).filter_by(
        login=data["login"]).first()

    if passes is not None:
        return {"status": "Error", "massage": "Already exists"}, 422

    db.session.add(
        Password(name_place=data['name_place'],
                 login=data["login"],
                 password=data["password"],
                 author=user))
    db.session.commit()

    return {"status": "Success"}