Exemplo n.º 1
0
def get_wallet(user_id):
    session = Session()
    try:
        wallet = session.query(Wallets).filter_by(user_id=int(user_id)).one()
    except:
        abort(404, description="Wallet not found")
    return WalletsSchema().dump(wallet)
Exemplo n.º 2
0
    def get(self, user_id):
        session = Session()

        user = auth.current_user()
        user_id = user.user_id
        exist = session.query(User).filter_by(user_id=user_id).first()
        if not exist:
            abort(404, message="Couldn`t find wallet with that id")
        return exist
Exemplo n.º 3
0
    def get(self):
        session = Session()
        user = auth.current_user()
        user_id = user.user_id
        exist = session.query(Wallets).filter_by(user_id=user_id).all()
        if not exist:
            abort(404, message="No each wallet in database")

        return exist
Exemplo n.º 4
0
def update_wallet(user_id):
    session = Session()

    try:
        wallet = session.query(Wallets).filter_by(user_id=int(user_id)).one()
    except:
        abort(404, description="Wallet not found")

    data = request.get_json()
    try:

        if data.get('name', None):
            wallet.name = data['name']

    except:
        abort(405, description="Invalid input")

    session.commit()

    return jsonify({"Success": "Wallet has been changed"}), 200
Exemplo n.º 5
0
 def post(self):
     session = Session()
     args = user_put_args.parse_args()
     exist = User(username=args['username'],
                  password=hash_password(args['password']))
     session.add(exist)
     session.commit()
     return exist, 201
Exemplo n.º 6
0
def delete_wallet(user_id):
    session = Session()
    try:
        wallet = session.query(Wallets).filter_by(user_id=int(user_id)).one()
    except:
        abort(404, description="Wallet not found")

    session.delete(wallet)

    session.commit()

    return jsonify({"Success": "Wallet has been deleted"}), 200
Exemplo n.º 7
0
    def delete(self):
        session = Session()
        # result = session.query(User).filter_by(id=user_id).first()
        exist = auth.current_user()
        if exist:
            print("User has been deleted")
        if not exist:
            abort(500, message="User doesn't exist, cannot delete")

        exist = session.merge(exist)
        session.delete(exist)
        session.commit()
        return "User deleted", 204
Exemplo n.º 8
0
    def post(self):
        session = Session()
        args = wallets_put_args.parse_args()
        user = auth.current_user()
        user_id = user.user_id

        wallet = Wallets(user_id=user_id, name=args['name'], uah=args['uah'])
        session.add(wallet)
        session.commit()
        return wallet, 200
Exemplo n.º 9
0
    def put(self):
        session = Session()
        args = user_update_args.parse_args()
        # result = session.query(User).filter_by(id=user_id).first()
        exist = auth.current_user()
        if not exist:
            abort(404, message="User doesn't exist, cannot update")
        if args['username']:
            exist.username = args['username']
        if args['password']:
            exist.password = hash_password(args['password'])

        exist = session.merge(exist)
        session.add(exist)
        session.commit()

        return exist
Exemplo n.º 10
0
def create_wallet():
    session = Session()

    data = request.get_json()

    try:
        wallet = Wallets(**data)
    except:
        return jsonify({"Message": "Invalid input"}), 405
    #  if not "owner_uid" != User.user_id:
    #     abort(404, description="Wallet owner not found")

    session.add(wallet)
    session.commit()

    return jsonify({"Success": "Wallet has been created"}), 200
Exemplo n.º 11
0
 def get(self, user_id):
     session = Session()
     exist = session.query(User).filter_by(user_id=user_id).first()
     if not exist:
         abort(404, message="Couldn`t find user with that id")
     return exist
Exemplo n.º 12
0
 def get(self):
     session = Session()
     exist = session.query(User).all()
     if not exist:
         abort(404, message="No one user in database")
     return exist
Exemplo n.º 13
0
def verify_user(username, password):
    session = Session()
    user = session.query(User).filter_by(username=username).first()
    if user and bcrypt.check_password_hash(user.password, password):
        return user