Esempio n. 1
0
    def login(self, parameters):

        data = {}
        self.send_header('Content-type', 'application/json')
        self.end_headers()

        if 'user' in parameters and 'pass' in parameters:
            username = parameters['user'][0]
            password = parameters['pass'][0]
            
            user = queries.log_in(username = username, password = password)

            if user is None: 
                self.send_response(400)
                data['error'] = 'No username password combination exists'
                print("user: "******" failed to log in")

            else:
                self.send_response(200)

                resource_buildings = queries.get_user_resource_buildings(user.user_id)
                decorative_buildings = queries.get_user_decorative_buildings(user.user_id)
                data['name'] = user.name
                data['username'] = user.username
                data['email'] = user.email
                data['password'] = user.password
                data['user_id'] = user.user_id
                data['experience'] = user.experience
                data['headquarters_level'] = user.headquarters_level
                data['level'] = user.level
                data['resource_buildings'] = resource_buildings
                data['decorative_buildings'] = decorative_buildings
                data['fire'] = user.fire
                data['water'] = user.water
                data['air'] = user.air
                data['earth'] = user.earth
                data['max_fire'] = user.max_fire
                data['max_water'] = user.max_water
                data['max_earth'] = user.max_earth
                data['max_air'] = user.max_air
                data['fire_ele'] = user.fire_ele
                data['water_ele'] = user.water_ele
                data['earth_ele'] = user.earth_ele
                data['air_ele'] = user.air_ele
                data['poof_count'] = user.poof_count
                data['hq_pos_x'] = user.hq_pos_x
                data['hq_pos_y'] = user.hq_pos_y
                print("user: "******" is logging in with user id: " + \
                      str(user.user_id) + "\n")

            self.wfile.write(json.dumps(data))

        else:
            self.send_response(400)
            data['error'] = 'Need a username and password'
            print("no username and password given")
            self.wfile.write(json.dumps(data))
Esempio n. 2
0
    def login(self, parameters):

        data = {}
        self.send_header("Content-type", "application/json")
        self.end_headers()

        if "user" in parameters and "pass" in parameters:
            username = parameters["user"][0]
            password = parameters["pass"][0]

            user = queries.log_in(username=username, password=password)

            if user is None:
                self.send_response(400)
                data["error"] = "No username password combination exists"
                print ("user: "******" failed to log in")

            else:
                self.send_response(200)

                resource_buildings = queries.get_user_resource_buildings(user.user_id)
                decorative_buildings = queries.get_user_decorative_buildings(user.user_id)
                data["name"] = user.name
                data["username"] = user.username
                data["email"] = user.email
                data["password"] = user.password
                data["user_id"] = user.user_id
                data["experience"] = user.experience
                data["headquarters_level"] = user.headquarters_level
                data["level"] = user.level
                data["resource_buildings"] = resource_buildings
                data["decorative_buildings"] = decorative_buildings
                data["fire"] = user.fire
                data["water"] = user.water
                data["air"] = user.air
                data["earth"] = user.earth
                data["max_fire"] = user.max_fire
                data["max_water"] = user.max_water
                data["max_earth"] = user.max_earth
                data["max_air"] = user.max_air
                data["fire_ele"] = user.fire_ele
                data["water_ele"] = user.water_ele
                data["earth_ele"] = user.earth_ele
                data["air_ele"] = user.air_ele
                data["poof_count"] = user.poof_count
                data["hq_pos_x"] = user.hq_pos_x
                data["hq_pos_y"] = user.hq_pos_y
                print ("user: "******" is logging in with user id: " + str(user.user_id) + "\n")

            self.wfile.write(json.dumps(data))

        else:
            self.send_response(400)
            data["error"] = "Need a username and password"
            print ("no username and password given")
            self.wfile.write(json.dumps(data))
Esempio n. 3
0
    def do_GET(self):

        parameters = parse_qs(urlparse(self.path).query)

        # logging in
        if re.match("/login", self.path):
            self.login(parameters)

        # looking for friends of a user
        elif re.match("/friends", self.path):
            self.getFriends(parameters)

        # looking for a specific user
        elif re.match("/users/.*", self.path):

            self.send_header("Content-type", "text-html")
            self.end_headers()

            user_id = os.path.basename(urlparse(self.path).path)
            decorative_buildings = queries.get_user_decorative_buildings(user_id)
            resource_buildings = queries.get_user_resource_buildings(user_id)

            self.wfile.write("user id: " + user_id)

        # asking for all users
        elif re.match(".*/users$", self.path):

            self.send_header("Content-type", "text-html")
            self.end_headers()
            self.wfile.write("user homepage")

        # get static info
        elif re.match(".*/static$", self.path):

            self.send_header("Content-type", "application/json")
            self.end_headers()
            static_info = queries.get_static_info()

        # homepage
        elif re.match("/$", self.path):

            self.send_header("Content-type", "text-html")
            self.end_headers()
            self.wfile.write("homepage")

        else:
            self.send_response(404)
        return
Esempio n. 4
0
    def do_GET(self):

        parameters = parse_qs(urlparse(self.path).query)

        # logging in
        if re.match('/login', self.path):
            self.login(parameters)

        # looking for friends of a user
        elif re.match('/friends', self.path):
            self.getFriends(parameters)

        # looking for a specific user
        elif re.match('/users/.*', self.path):

            self.send_header('Content-type', 'text-html')
            self.end_headers()

            user_id = os.path.basename(urlparse(self.path).path)
            decorative_buildings = queries.get_user_decorative_buildings(user_id)
            resource_buildings = queries.get_user_resource_buildings(user_id)
                
            self.wfile.write('user id: ' + user_id)

        # asking for all users
        elif re.match('.*/users$', self.path):

            self.send_header('Content-type', 'text-html')
            self.end_headers()
            self.wfile.write('user homepage')

        # get static info
        elif re.match('.*/static$', self.path):
            
            self.send_header('Content-type', 'application/json')
            self.end_headers()
            static_info = queries.get_static_info()

        # homepage
        elif re.match('/$', self.path):

            self.send_header('Content-type', 'text-html')
            self.end_headers()
            self.wfile.write('homepage')

        else:
            self.send_response(404)
        return