def client_polling_update(ssid, user_name, credit, bandwidth):

        friends = Connections.get_friends(ssid) or []

        if user_name not in friends:
            Account.update_credits(user_name, -credit)
            Connections.update_credits(ssid, credit)
            host_name = Connections.get_user_name(ssid)
            if host_name:
                Account.update_credits(host_name, credit)

        Connections.update_bandwidth(ssid, bandwidth)

        credits_left = Account.get_user(user_name)['credits']

        return credits_left
Exemple #2
0
    def post(self):
        """
        data reqs:
        {"first_name":"test",
        "last_name":"test",
        "email":"email",
        "date_of_birth":"temp",
        "password":"******",
        "password_confirm":"temp"
        }

        :return:
        """
        data = request.get_json()
        if not data:
            data = {"response": "Bad Request"}
            return jsonify(data)
        first_name = data.get('first_name')
        last_name = data.get('last_name')
        user_name = data.get('user_name')
        email = data.get('email')
        date_of_birth = data.get('date_of_birth')
        password = data.get('password')
        password_confirm = data.get('password_confirm')
        response = {}
        if Account.create_account(first_name, last_name, user_name, email,
                                  date_of_birth, password, password_confirm):
            response['response'] = "Account Created"
            return jsonify(response)
        else:
            response['response'] = "Account Creation Failed"
            return make_response(jsonify(response), 500)
 def post(self):
     data = request.get_json()
     if not data:
         data = {"response": "Bad Login"}
         return jsonify(data)
     user_name = data.get('user_name')
     password = data.get('password')
     if Authentication.check_login(user_name, password):
         user_info = Account.get_user(user_name)
         user_info.pop('_id')
         return user_info
     else:
         data = {"response": "Bad Login"}
         return make_response(jsonify(data), 500)
 def get_criteria_used(ssid):
     """
     returns the bandwidth used on a ssid
     :param ssid:
     :return:
     """
     connections = client.connections
     row = connections.find_one({'ssid': ssid})
     if row:
         row['host_credits'] = Account.get_credits(row['user_name'])
         row.pop('_id')
         print(row)
         return row
     else:
         return False
Exemple #5
0
 def post(self):
     """
     '{"credit_difference": 12, "user_name":"test"}'
     :return:
     """
     data = request.get_json()
     if not data:
         data = {"response": "Bad Request"}
         return jsonify(data)
     credit_difference = data.get('credit_difference')
     user_name = data.get('user_name')
     response = {}
     if Account.update_credits(user_name, credit_difference):
         response['response'] = 'Credits updated'
         return jsonify(response)
     else:
         response['response'] = 'Credit Update Failed'
         return make_response(jsonify(response))
    def add_transaction(info):
        """
        template_transaction = {
            "transaction_type": "test",
            "data_type": "test",
            "start_time": 20170313,
            "end_time": 20170314,
            "data_usage": 12,
            "credit_usage": 31,
            "user_name":"test"
        }
        :param dict info: dict of info to insert
        :return: None
        """
        template_transaction = {
            'transaction_type': None,
            'data_type': None,
            'start_time': None,
            'end_time': None,
            'data_usage': None,
            'credit_usage': None,
            'user_name': None
        }
        transaction_db = client.transactions
        data = {}
        for k, v in template_transaction.items():
            if k in info:
                data[k] = info[k]
            else:
                data[k] = v
        data['_id'] = ObjectId()
        transaction_db.insert_one(data)
        client_info = Account.get_user(data['user_name'])

        data2 = copy.deepcopy(data)
        data2['transaction_type'] = 'host'
        data2['_id'] = ObjectId()
        data2['user_name'] = info['host']
        transaction_db.insert_one(data2)
        return client_info['credits']
 def post(self):
     """
     '{
     "user_name":"test",
     "password":"******",
     "password_confirm":"test2"
     }'
     :return:
     """
     data = request.get_json()
     if not data:
         data = {"response": "Bad Request"}
         return jsonify(data)
     user_name = data.get('user_name')
     password = data.get('password')
     prev_password = data.get('prev_password')
     password_confirm = data.get('password_confirm')
     if Account.change_password(user_name, prev_password, password,
                                password_confirm):
         return jsonify({'response': 'ok'})
     else:
         return make_response(jsonify({'response': 'Bad Request'}), 500)