def do_login(request): if 'username' in request and 'password' in request: username = request['username'].value password = request['password'].value if db.get_data(username, 'password_hash') == get_hash(username, password): # Successful login print head.get_head() f = open(config.template_dir + 'authbar_login.template', 'r') t = Template (f.read()) return t.safe_substitute(login=username, token = get_token(username), page=cgienv.get_full_URL()) return '<script>document.location.href=""</script>'
def get_images(client, data): print('[GET] getting images...') images = [] reply = b'' for imgtag in data.find_all('img'): src = imgtag.get('src') src = src.replace(" ", "_") src = src.replace("%20", "_") request = get_from_src(src, client.addr, client) client.sock.send(request) headers = head.get_head(client) reply = get.get_data(headers, client) src = src.split("/")[-1] if (src.startswith("/") == False): src = "/{}".format(str(src)) url = "{}{}".format(str(client.addr), str(src)) imgtag['src'] = "./images{}".format(src) print('Request: ', str(request)) images.append((src, reply)) return images
def send_msg(self): data = '' # === Handling GET === """ Go to file: [[get.py]]. """ if self.command == "GET": get.setup(self) headers = head.get_head(self) data, content_type = get.get_data(headers, self) if content_type == "html": parser_.set_html_file(self, data) else: parser_.set_object(self, data) # === Handling PUT === """ Go to file: [[put.py]]. """ if self.command == "PUT": put.put_data(self) headers = head.get_head(self) # === Handling POST === """ Go to file: [[post.py]]. """ if self.command == "POST": post.post_data(self) headers = head.get_head(self) # === Handling HEAD === """ Go to file: [[head.py]]. """ if self.command == "HEAD": head.head_data(self) return data
def insert_head (page): return head.get_head() + "\n" + page
def do_logout(request): print head.get_head() f = open(config.template_dir + 'authbar_logout.template', 'r') t = Template (f.read()) return t.safe_substitute()