Beispiel #1
0
def Order_by_id(current_user, id):
    try:
        user = UserSchema().dump(current_user)
        if request.method == 'GET':
            data = Order.query.filter_by(uniqueCode=id).first()
            if data:
                data = OrderSchema().dump(data).data
                response = jsonify({"result": data})
                return response
            return jsonify({'error':
                            "No Order found with id ({})".format(id)}), 400
        if request.method == 'POST':
            if user.data['isAdmin'] == True:
                ob = Order.query.filter_by(uniqueCode=id).first()
                if ob:
                    for key in request.json:
                        setattr(ob, key, request.json[key])
                    ob.update()
                    result = OrderSchema().dump(ob)
                    return jsonify(result.data)
                return jsonify(
                    {'error': "No Order found with id ({})".format(id)}), 400
            return jsonify({"error": "Access Denied"})
        if request.method == 'DELETE':
            ob = Order.query.filter_by(uid=id).first()
            if ob:
                ob.delete()
                return jsonify({'id': ob.uid})
            return jsonify({'error':
                            "No Order found with id ({})".format(id)}), 404
    except Exception as error:
        return jsonify({"error": str(error)}), 400
Beispiel #2
0
def loginUser():
    if request.method == 'POST':
        try:
            ob = request.authorization
            data = User.query.filter_by(email=ob.username).first()
            res = UserSchema().dump(data)
            if data:
                if res.data['verifiedMail'] == False:
                    return jsonify({"error": "Please Verify Your Mail"})
                else:
                    if check_password_hash(res.data['password'], ob.password):
                        token = jwt.encode(
                            {
                                "userId": res.data['uid'],
                                "password": res.data['password']
                            },
                            key=app.config['SECRET_KEY'],
                            algorithm='HS256')
                        return jsonify({
                            "data": True,
                            "message": "User Exits",
                            "token": token
                        })
                    else:
                        return jsonify({
                            "error": True,
                            "message": "Password Does Not match"
                        })
            else:
                return jsonify({
                    "error": True,
                    "message": "User Does Not Exits"
                })
        except Exception as error:
            return jsonify({"error": str(error)}), 400
Beispiel #3
0
def createKyc(current_user):
    if request.method == 'POST':
        try:
            user = UserSchema().dump(current_user)
            ob = Kyc(**request.json)
            ob.uid = uuid.uuid4()
            ob.user = user.data['uid']
            ob.save()
            result = KycSchema().dump(ob)
            return jsonify(result.data)
        except Exception as error:
            return jsonify({"error": str(error)}), 400
Beispiel #4
0
def createNotification(current_user):
    if request.method == 'POST':
        try:
            user = UserSchema().dump(current_user)
            ob = Notification(**request.json)
            ob.uid = uuid.uuid4()
            ob.user = user.data['uid']
            ob.save()
            result = NotificationSchema().dump(ob)
            sendNotification(user.data['email'], result.data['description'])
            return jsonify(result.data)
        except Exception as error:
            return jsonify({"error": str(error)}), 400
Beispiel #5
0
def verifyied():
    try:
        ob = request.json
        user = User.query.filter_by(email=ob['email']).first()
        setattr(user, 'verifiedMail', True)
        data = Otp.query.filter_by(email=ob['email']).first()
        res = OtpSchema().dump(data)
        if res.data['otp'] == ob['otp']:
            user.update()
            result = UserSchema().dump(user)
            return jsonify({"data": result.data})
        return jsonify({"error": "Otp does not match"})
    except Exception as error:
        return jsonify({"error": str(error)}), 400
Beispiel #6
0
def user_by_id(current_user):
    try:
        user = UserSchema().dump(current_user)
        if request.method == 'GET':
            data = User.query.filter_by(uid=user.data['uid']).first()
            if data:
                data = UserSchema().dump(data).data
                response = jsonify({"result": data})
                return response
            return jsonify({'error':
                            "No User found with id ({})".format(id)}), 400
        if request.method == 'POST':
            ob = User.query.filter_by(uid=user.data['uid']).first()
            if ob:
                for key in request.json:
                    if key == "password":
                        password = generate_password_hash(request.json[key],
                                                          method='sha256')
                        setattr(ob, key, password)
                    if key == "isAdmin":
                        setattr(ob, key, False)
                    if key != "password" and key != "isAdmin" and key != "email" and key != "verifiedMail":
                        setattr(ob, key, request.json[key])
                ob.update()
                result = UserSchema().dump(ob)
                return jsonify(result.data)
            return jsonify({'error':
                            "No User found with id ({})".format(id)}), 400
        if request.method == 'DELETE':
            ob = User.query.filter_by(uid=user.data['uid']).first()
            if ob:
                ob.delete()
                return jsonify({'id': ob.uid})
            return jsonify({'error':
                            "No User found with id ({})".format(id)}), 404
    except Exception as error:
        return jsonify({"error": str(error)}), 400
Beispiel #7
0
def getallOrders_Seller(current_user):
    try:
        ob = UserSchema().dump(current_user)
        data = Order.query.filter_by(seller=ob.data['uid']).all()
        if data:
            if len(data) > 0:
                finalRes = []
                for obj in data:
                    res = OrderSchema().dump(obj)
                    finalRes.append(res.data)
                return jsonify({"result": finalRes})
        return jsonify(
            {'error': "No Order found for this User ({})".format(id)})
    except Exception as error:
        return jsonify({"error": str(error)}), 400
Beispiel #8
0
def allOrdersOnUser(current_user):
    try:
        ob = UserSchema().dump(current_user)
        if ob.data['isAdmin'] == True:
            data = Order.query.filter_by(user=request.json['user']).all()
            if data:
                if len(data) > 0:
                    finalRes = []
                    for obj in data:
                        res = OrderSchema().dump(obj)
                        finalRes.append(res.data)
                    return jsonify({"result": finalRes})
            return jsonify({'error': "No Order found"})
        return jsonify({'error': 'You Have No Access'})
    except Exception as error:
        return jsonify({"error": str(error)}), 400
Beispiel #9
0
def getallNotifiationforUser(current_user):
    try:
        user = UserSchema().dump(current_user)
        data = Notification.query.filter_by(user=user.data['uid']).all()
        if data:
            if len(data) > 1:
                finalRes = []
                for obj in data:
                    res = NotificationSchema().dump(obj)
                    finalRes.append(res.data)
                return jsonify({"result": finalRes})
            return jsonify({"result": data})
        return jsonify(
            {'error': "No Order found for this User ({})".format(id)})
    except Exception as error:
        return jsonify({"error": str(error)}), 400
Beispiel #10
0
def createUser():
    if request.method == 'POST':
        try:
            ob = User(**request.json)
            data = User.query.filter_by(email=ob.email).first()
            if data:
                return jsonify({"error": "Sorry User Exists - 401"})
            else:
                ob.uid = uuid.uuid4()
                ob.password = generate_password_hash(ob.password,
                                                     method='sha256')
                ob.save()
                result = UserSchema().dump(ob)
                otpGenreationForUserMail(result.data['email'])
                return jsonify(result.data)
        except Exception as error:
            return jsonify({"error": str(error)}), 400
Beispiel #11
0
def forgetPassword():
    try:
        ob = request.json
        otp = Otp.query.filter_by(email=ob['email']).first()
        user = User.query.filter_by(email=ob['email']).first()
        if (otp.linkused != True and otp.refecthUrl == ob['refetchUrl']):
            setattr(otp, 'linkused', True)
            setattr(user, 'password',
                    generate_password_hash(ob['password'], method='sha256'))
            user.update()
            otp.update()
            result = UserSchema().dump(user)
            return jsonify(result.data)
        else:
            return jsonify({"error": "Forget Password Link Not Found 404"})
    except Exception as error:
        return jsonify({"error": str(error)}), 400