Beispiel #1
0
    def get(self, customer_id):
        """Returns all the Accounts related to the Customer """

        customers = mongo.db.Customers
        query = customers.find({"Customer_id": customer_id}, {
            "Accounts.Rules": 0,
            "AdressList": 0,
            "_id": 0,
            "Customer_id": 0,
            "Name": 0
        })

        if query.count() > 0:
            output = []

            for q in query:
                print(q)
                for i in q['Accounts']:
                    for acc in i:
                        output.append(acc)
                response = jsonify({'result': q})
                response.headers.add('Access-Control-Allow-Origin', '*')
                return response

        else:
            response = jsonify(
                {'result': 'customer_id %s does not Exist' % customer_id})
            response.headers.add('Access-Control-Allow-Origin', '*')
            return response
Beispiel #2
0
    def get(self, email):
        """Returns all the details of an Account"""
        customers = mongo.db.Customers
        query = customers.find({"Accounts.Email": email}, {
            "Customer_id": 1,
            "Name": 1,
            "_id": 0,
            "Accounts.Email": 1,
            "Accounts.Account_id": 1
        })

        output = {}
        if query.count() > 0:
            for q in query:
                print(q)
                output.update({"Name": q["Name"]})
                output.update({"Customer_id": q["Customer_id"]})

                for i in q['Accounts']:
                    if i['Email'] == email:
                        output.update({"Account_id": i["Account_id"]})
                        print(i, output)
                return jsonify(output)
        else:
            return 'email %s does not Exist' % email
Beispiel #3
0
 def get(self, custID):
     monitors = mongo.db.Monitors
     query = monitors.find({"Customer_id": custID}, {
         "Monitor_id": 1,
         "PlanType": 1,
         "_id": 0
     })
     output = []
     if query.count() > 0:
         for q in query:
             print(q)
             output.append(q)
         return jsonify(output[0])
     else:
         return 'customer_id %s does not Exist' % custID
Beispiel #4
0
    def get(self, account_id):
        """Returns all the details of an Account"""
        customers = mongo.db.Customers
        query = customers.find({"Accounts.Account_id": account_id}, {
            "Accounts.Rules": 0,
            "_id": 0,
            "Customer_id": 0,
            "Name": 0
        })

        output = []
        if query.count() > 0:
            for q in query:
                # print(q)
                for i in q['Accounts']:
                    if i['Account_id'] == account_id:
                        output.append(i)
                        print(i)
                return jsonify(output[0])
        else:
            return 'account_id %s does not Exist' % account_id
Beispiel #5
0
    def post(self):
        """login"""

        customers = mongo.db.Customers
        data = request.get_json()
        query = customers.find({"Accounts.Email": data["Email"]},
                               {"Accounts.Email": 1, "Accounts.Password": 1, "_id": 0})
        output = []
        if query.count() > 0:
            for q in query:
                print(q)
                print(q['Accounts'][0]['Password'])
                t1 = bcrypt.check_password_hash(q['Accounts'][0]['Password'], data['Password'])
                Email = request.json.get('Email', None)
                print(Email,t1)
                if t1:
                    access_token = create_access_token(identity=Email)
                    print(access_token)
                    return make_response(jsonify(access_token=access_token))
                    # return True
                else:
                    return abort(401, 'Incorrect Credentials ')
        else:
            return 'Incorrect Credentials'