コード例 #1
0
ファイル: StockRegister.py プロジェクト: zpoint/PyWebServer
    async def post(self):
        text = await self.request.text()
        values = text.split("&")
        post_body = dict()
        for v in values:
            inner_values = v.split("=")
            if len(inner_values) != 2:
                return ErrorReturn.invalid()
            post_body[inner_values[0]] = inner_values[1]

        keys = ("username", "password", "inviteCode")
        for key in keys:
            if key not in post_body:
                return ErrorReturn.invalid()

        extra_info = self.request.transport.get_extra_info('peername')
        ip = extra_info[0] if extra_info is not None else str(None)

        success, msg = DBUtil.create_user(post_body["username"],
                                          post_body["password"],
                                          post_body["inviteCode"], ip)
        if not success:
            return ErrorReturn.html(msg, self.path)
        else:
            return ErrorReturn.html(msg, main_pth)
コード例 #2
0
    async def post(self):
        r = DBUtil.valid_user(self.request.cookies, True)
        if r is False:
            return ErrorReturn.invalid()

        text = await self.request.text()
        values = text.split("&")
        post_body = dict()
        for v in values:
            inner_values = v.split("=")
            if len(inner_values) != 2:
                return ErrorReturn.invalid()
            post_body[inner_values[0]] = inner_values[1]

        post_body.update(r["bind_param"])
        keys = ("verify_code", "verify_value", "username", "password", "cid", "cname")
        for key in keys:
            if key not in post_body:
                return ErrorReturn.invalid(title="参数不合法", main_path=self.path)

        success, cookie_dict = await login(r["prefer_host"], post_body["verify_code"], post_body["verify_value"],
                                           post_body["username"], post_body["password"], post_body["cid"],
                                           post_body["cname"], r["bind_cookie"])

        if not success:
            return ErrorReturn.html(cookie_dict, self.path)
        else:
            DBUtil.update_param(r, {}, cookie_dict, False)
            DBUtil.bind(r, post_body)
            return ErrorReturn.html("绑定成功", StockMonitor.path, "成功")
コード例 #3
0
ファイル: StockMonitor.py プロジェクト: zpoint/PyWebServer
 async def get(self):
     r = DBUtil.valid_user(self.request.cookies, True)
     if not r:
         return ErrorReturn.invalid()
     if not r["bind_username"]:
         return ErrorReturn.invalid("您尚未绑定账号,请绑定后进行操作",
                                    main_path="/Stock/StockBind")
     try:
         html = await self.get_content_html(r)
     except IndexError:
         return ErrorReturn.invalid("对方服务器超时, 请稍后重试", main_path=self.path)
     if type(html) != str:
         return html
     else:
         return web.Response(text=html, headers=Headers.html_headers)
コード例 #4
0
ファイル: StockMonitor.py プロジェクト: zpoint/PyWebServer
    async def re_login(self, r, post_body, return_flag=False):
        post_body.update(r["bind_param"])
        post_body["username"] = r["bind_username"]
        post_body["password"] = r["bind_password"]
        keys = ("verify_code", "verify_value", "username", "password", "cid",
                "cname")
        for key in keys:
            if key not in post_body:
                return ErrorReturn.invalid(title="参数不合法", main_path=self.path)

        success, cookie_dict = await login(
            r["prefer_host"], post_body["verify_code"],
            post_body["verify_value"], post_body["username"],
            post_body["password"], post_body["cid"], post_body["cname"],
            r["bind_cookie"])

        if not success:
            return_obj = ErrorReturn.html(cookie_dict, self.path)
            return (False, return_obj) if return_flag else return_obj
        else:
            DBUtil.update_param(r, {}, cookie_dict, False)
            DBUtil.set_cookie_valid(r)
            html = await self.get_content_html(r)
            return_obj = web.Response(text=html, headers=Headers.html_headers)
            return (True, return_obj) if return_flag else return_obj
コード例 #5
0
    async def get(self):
        r = DBUtil.valid_user(self.request.cookies, True)
        if not r:
            return ErrorReturn.invalid()

        img_byte = await StockLogin.get_img_byte(r)

        html = WebPageBase.head("请绑定账号")
        html += """
        <h3 align='center'>您还未绑定账号,请绑定后进行使用</h2>
        <form action="%s" method="post">
        <table border=0 align="center">
        <tr>
        <td>对方平台用户名</td>
        <td><input type="text" name="username" pattern="^[\da-zA-Z]{1,}$" title="请输入需要进行自动操作的用户名" /></td>
        </tr>
        <tr>
        <td>对应账户密码</td>
        <td><input type="password" name="password" pattern="^[\da-zA-Z]{1,}$" title="请输入对应账户的密码" /></td>
        </tr>
        <tr>
        <td><img src="data:image/png;base64, %s"></td>
        <td><input type="text" name="verify_code" pattern="^[\da-zA-Z]{1,}$" title="请输入图片显示的验证码" /></td>
        </table>
        <table border=0 align="center">
        <tr><td><a href="%s">刷新验证码</a></td></tr>
        <tr><td><input type="submit" align="center" value="绑定" /></td>
        </tr></table>
        </form>
        </body>
        </html>
        """ % (self.path, quote(base64.encodebytes(img_byte)), self.path)
        return web.Response(text=html, headers=Headers.html_headers)
コード例 #6
0
ファイル: StockMonitor.py プロジェクト: zpoint/PyWebServer
    async def post(self):
        r = DBUtil.valid_user(self.request.cookies, True)
        if not r:
            return ErrorReturn.invalid()
        if not r["bind_username"]:
            return ErrorReturn.invalid("您尚未绑定账号,请绑定后进行操作",
                                       main_path="/Stock/StockBind")

        text = await self.request.text()
        values = text.split("&")
        post_body = dict()
        for v in values:
            inner_values = v.split("=")
            if inner_values[0] == "rule":
                if "rule" in post_body:
                    post_body["rule"].append(inner_values[1])
                else:
                    post_body["rule"] = [inner_values[1]]
            else:
                post_body[inner_values[0]] = inner_values[1]

        if "verify_code" in post_body:
            return await self.re_login(r, post_body)
        else:
            for key in ("base_value", "stock_times", "working_period",
                        "beginStatus"):
                if key not in post_body:
                    return ErrorReturn.invalid("非法访问", main_path=self.path)

            success, reason = self.update_personal_val(post_body, r)
            if not success:
                return ErrorReturn.invalid(reason, main_path=self.path)
            r = DBUtil.valid_user(self.request.cookies, True)
            html = await self.get_content_html(r)
            if type(html) != str:
                return html
            else:
                extra_info = self.request.transport.get_extra_info('peername')
                ip = extra_info[0] if extra_info is not None else str(None)
                valid, cookie = DBUtil.reset_cookie(r, ip)
                init_headers = Headers.html_headers
                init_headers[
                    "Set-Cookie"] = "StockID=" + cookie + ";path=/;max-age=" + config[
                        "common"]["cookie_max_age"]
                return web.Response(text=html, headers=init_headers)