Beispiel #1
0
 async def _import(app: App, article: Article, session: Session):
     if not session.get("login"):
         return app.render_template("login.html", ref="import")
     else:
         return app.render_template("import.html",
                                    success="",
                                    **article.to_dict())
Beispiel #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"))
Beispiel #3
0
 async def _import(self, app: App, session: Session):
     """
     导入文章
     :param app:
     :param session:
     :return: 导入文章页面
     """
     if not session.get("login"):
         return app.render_template("login.html", ref="import")
     else:
         return app.render_template("import.html", success="")
Beispiel #4
0
    async def upload(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="import")

        await self.service.upload(article)
        return app.render_template("import.html", success="success")
Beispiel #5
0
 async def edit(self, app: App, id: http.QueryParam, session: Session):
     """
     打开文章编辑页面
     :param app:
     :param id: 文章的id
     :ex id: `20111111111111`
     :param session:
     :return: 如果登录了,跳转到编辑页面,否则,跳转到登录页。
     """
     article = await Article.load(id=id)
     if not session.get("login"):
         return app.render_template("login.html", ref="edit", **article)
     else:
         return app.render_template("edit.html", ref="update", **article)
Beispiel #6
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"))
Beispiel #7
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"))
Beispiel #8
0
    def login(self,
              app: App,
              session: Session,
              host: http.Host,
              port: http.Port,
              scheme: http.Scheme,
              ticket: str = None):
        """
        This route has two purposes. First, it is used by the user
        to login. Second, it is used by the CAS to respond with the
        `ticket` after the user logs in successfully.

        When the user accesses this url, they are redirected to the CAS
        to login. If the login was successful, the CAS will respond to this
        route with the ticket in the url. The ticket is then validated.
        If validation was successful the logged in username is saved in
        the user's session under the key `CAS_USERNAME_SESSION_KEY` and
        the user's attributes are saved under the key
        'CAS_USERNAME_ATTRIBUTE_KEY'
        """
        login_url = f"{scheme}://{host}:{port}{app.reverse_url('view:cas:login')}"
        cas_token_session_key = settings['CAS_TOKEN_SESSION_KEY']

        redirect_url = create_cas_login_url(settings['CAS_SERVER'],
                                            settings['CAS_LOGIN_ROUTE'],
                                            login_url)

        if ticket:
            session[cas_token_session_key] = ticket

            if validate(ticket, login_url, session):
                if 'CAS_AFTER_LOGIN_SESSION_URL' in session:
                    redirect_url = session.pop('CAS_AFTER_LOGIN_SESSION_URL')
                else:
                    redirect_url = app.reverse_url(settings['CAS_AFTER_LOGIN'])
            else:
                del session[cas_token_session_key]

        logger.debug('Redirecting to: {0}'.format(redirect_url))

        return redirect(redirect_url)
Beispiel #9
0
 async def edit(app: App, article: Article, session: Session):
     await article.load()
     if not session.get("login"):
         return app.render_template("login.html", ref="edit", **article)
     else:
         return app.render_template("edit.html", ref="update", **article)
Beispiel #10
0
 async def modify(img_url: FormParam, service: ArticleService,
                  article: Article, session: Session):
     if not session.get("login"):
         return {"result": 0}
     await service.modify(article, img_url)
     return {"result": 1}
Beispiel #11
0
 async def upload(app: App, article: Article, session: Session):
     if not session.get("login"):
         return app.render_template("login.html", ref="import")
     await article.save()
     return app.render_template("import.html", success="success")