Exemplo n.º 1
0
 async def check(self, app: App, article: Article, username: FormParam,
                 password: FormParam, ref: FormParam, session: Session):
     """
     检查用户名和密码是否正确
     :param app:
     :param article:
     :ex article:
     ```json
     {"title": "xxx"}
     ```
     :type article: form
     :param username: 用户名
     :ex username: `test`
     :param password: 密码
     :ex password: `12345`
     :param ref: 从哪里跳过来的
     :param session:
     :return: 返回网页
     """
     # article由于没有经过format会带有多余的信息
     if username == settings["USERNAME"] and password == settings[
             "PASSWORD"]:
         session["login"] = f'{username}:{password}'
         if ref == "edit" and hasattr(article, "id"):
             article = await Article.load(id=article.id)
         if ref:
             return app.render_template(f"{ref}.html",
                                        success="",
                                        **article.to_dict())
         else:
             return redirect(app.reverse_url("view:welcome:index"))
     else:
         return app.render_template("login.html", **article.to_dict())
Exemplo n.º 2
0
 async def delete(app: App, article: Article, service: ArticleService,
                  session: Session):
     if not session.get("login"):
         return app.render_template("login.html",
                                    ref="delete",
                                    id=article.id)
     await service.delete(article)
     return redirect(app.reverse_url("view:welcome:index"))
Exemplo n.º 3
0
 async def cut(service: ArticleService,
               url: http.QueryParam,
               top: int = 0,
               left: int = 0,
               width: int = 1024,
               height: int = 768):
     save_name = await service.cut(url, top, left, width, height)
     return redirect(save_name.replace(project_path, ""))
Exemplo n.º 4
0
    async def update(self, app: App, article: Article, session: Session):
        """
        编辑之后更新文章内容
        :param app:
        :param article: 文章对象
        :type article: form
        :param session:
        :return: 如果登录了,跳转到首页,否则,跳转到登录页
        """
        if not session.get("login"):
            return app.render_template("login.html", ref="edit", **article)

        await self.service.update(article)
        return redirect(app.reverse_url("view:welcome:index"))
Exemplo n.º 5
0
 async def cut(self,
               url: http.QueryParam,
               top: int = 0,
               left: int = 0,
               width: int = 1024,
               height: int = 768):
     """
     截图api
     :param url: 要截图的地址
     :param top: 截图区域的top
     :param left: 截图区域的left
     :param width: 截图区域的width
     :param height: 截图区域的height
     :return: 重定向到截图的静态地址
     """
     save_name = await self.service.cut(url, top, left, width, height)
     return redirect(save_name.replace(settings["PROJECT_PATH"], ""))
Exemplo n.º 6
0
    async def delete(self, app: App, id: http.QueryParam, session: Session):
        """
        删除文章接口
        :param app:
        :param id: 要删除的文章id
        :ex id: `19911111111111`
        :param session:
        :return: 如果登录了,跳转到首页,否则跳转到登录页。
        """
        article = Article(id=id)
        if not session.get("login"):
            return app.render_template("login.html",
                                       ref="delete",
                                       id=article.id)

        await self.service.delete(article)
        return redirect(app.reverse_url("view:welcome:index"))