Example #1
0
 def admin(self, env, req):
     isso_host_script = self.isso.conf.get("server", "public-endpoint") or local.host
     if not self.isso.conf.getboolean("admin", "enabled"):
         return render_template('disabled.html')
     try:
         data = self.isso.unsign(req.cookies.get('admin-session', ''),
                                 max_age=60 * 60 * 24)
     except BadSignature:
         return render_template('login.html', isso_host_script=isso_host_script)
     if not data or not data['logged']:
         return render_template('login.html', isso_host_script=isso_host_script)
     page_size = 100
     page = int(req.args.get('page', 0))
     order_by = req.args.get('order_by', None)
     asc = int(req.args.get('asc', 1))
     mode = int(req.args.get('mode', 2))
     comments = self.comments.fetchall(mode=mode, page=page,
                                       limit=page_size,
                                       order_by=order_by,
                                       asc=asc)
     comments_enriched = []
     for comment in list(comments):
         comment['hash'] = self.isso.sign(comment['id'])
         comments_enriched.append(comment)
     comment_mode_count = self.comments.count_modes()
     max_page = int(sum(comment_mode_count.values()) / 100)
     return render_template('admin.html', comments=comments_enriched,
                            page=int(page), mode=int(mode),
                            conf=self.conf, max_page=max_page,
                            counts=comment_mode_count,
                            order_by=order_by, asc=asc,
                            isso_host_script=isso_host_script)
Example #2
0
 def admin(self, env, req):
     isso_host_script = self.isso.conf.get("server", "public-endpoint") or local.host
     try:
         data = self.isso.unsign(req.cookies.get('admin-session', ''),
                                 max_age=60 * 60 * 24)
     except BadSignature:
         return render_template('login.html', isso_host_script=isso_host_script)
     if not data or not data['logged']:
         return render_template('login.html', isso_host_script=isso_host_script)
     page_size = 100
     page = int(req.args.get('page', 0))
     order_by = req.args.get('order_by', None)
     asc = int(req.args.get('asc', 1))
     mode = int(req.args.get('mode', 2))
     comments = self.comments.fetchall(mode=mode, page=page,
                                       limit=page_size,
                                       order_by=order_by,
                                       asc=asc)
     comments_enriched = []
     for comment in list(comments):
         comment['hash'] = self.isso.sign(comment['id'])
         comments_enriched.append(comment)
     comment_mode_count = self.comments.count_modes()
     max_page = int(sum(comment_mode_count.values()) / 100)
     return render_template('admin.html', comments=comments_enriched,
                            page=int(page), mode=int(mode),
                            conf=self.conf, max_page=max_page,
                            counts=comment_mode_count,
                            order_by=order_by, asc=asc,
                            isso_host_script=isso_host_script)
Example #3
0
    def admin(self, env, req):
        isso_host_script = self.isso.conf.get("server",
                                              "public-endpoint") or local.host
        if not self.isso.conf.getboolean("admin", "enabled"):
            return render_template('disabled.html',
                                   isso_host_script=isso_host_script)
        try:
            data = self.isso.unsign(req.cookies.get('admin-session', ''),
                                    max_age=60 * 60 * 24)
        except BadSignature:
            return render_template('login.html',
                                   isso_host_script=isso_host_script)
        if not data or not data['logged']:
            return render_template('login.html',
                                   isso_host_script=isso_host_script)
        page_size = 100
        page = int(req.args.get('page', 0))
        order_by = req.args.get('order_by', 'created')
        asc = int(req.args.get('asc', 0))
        mode = int(req.args.get('mode', 2))
        comments = self.comments.fetchall(mode=mode,
                                          page=page,
                                          limit=page_size,
                                          order_by=order_by,
                                          asc=asc)
        comments_enriched = []

        # 2020-08-29 zrong add absurl
        url = self.conf.get('comment-postid-url')

        for comment in list(comments):
            comment['hash'] = self.isso.sign(comment['id'])
            if url is not None:
                comment['absurl'] = url.format(comment['uri'])
            comments_enriched.append(comment)
        comment_mode_count = self.comments.count_modes()
        max_page = int(sum(comment_mode_count.values()) / 100)
        return render_template('admin.html',
                               comments=comments_enriched,
                               page=int(page),
                               mode=int(mode),
                               conf=self.conf,
                               max_page=max_page,
                               counts=comment_mode_count,
                               order_by=order_by,
                               asc=asc,
                               isso_host_script=isso_host_script)
Example #4
0
 def login(self, env, req):
     if not self.isso.conf.getboolean("admin", "enabled"):
         return render_template('disabled.html')
     data = req.form
     password = self.isso.conf.get("admin", "password")
     if data['password'] and data['password'] == password:
         response = redirect(
             re.sub(r'/login$', '/admin',
                    get_current_url(env, strip_querystring=True)))
         cookie = functools.partial(dump_cookie,
                                    value=self.isso.sign({"logged": True}),
                                    expires=datetime.now() + timedelta(1))
         response.headers.add("Set-Cookie", cookie("admin-session"))
         response.headers.add("X-Set-Cookie", cookie("isso-admin-session"))
         return response
     else:
         isso_host_script = self.isso.conf.get(
             "server", "public-endpoint") or local.host
         return render_template('login.html',
                                isso_host_script=isso_host_script)
Example #5
0
 def login(self, env, req):
     if not self.isso.conf.getboolean("admin", "enabled"):
         return render_template('disabled.html')
     data = req.form
     password = self.isso.conf.get("admin", "password")
     if data['password'] and data['password'] == password:
         response = redirect(re.sub(
             r'/login$',
             '/admin',
             get_current_url(env, strip_querystring=True)
         ))
         cookie = functools.partial(dump_cookie,
                                    value=self.isso.sign({"logged": True}),
                                    expires=datetime.now() + timedelta(1))
         response.headers.add("Set-Cookie", cookie("admin-session"))
         response.headers.add("X-Set-Cookie", cookie("isso-admin-session"))
         return response
     else:
         isso_host_script = self.isso.conf.get("server", "public-endpoint") or local.host
         return render_template('login.html', isso_host_script=isso_host_script)
 def login(self, env, req):
     data = req.form
     password = self.isso.conf.get("general", "admin_password")
     if data['password'] and data['password'] == password:
         response = redirect(get_current_url(env, host_only=True) + '/admin')
         cookie = functools.partial(dump_cookie,
             value=self.isso.sign({"logged": True}),
             expires=datetime.now() + timedelta(1))
         response.headers.add("Set-Cookie", cookie("admin-session"))
         response.headers.add("X-Set-Cookie", cookie("isso-admin-session"))
         return response
     else:
         return render_template('login.html')
Example #7
0
 def login(self, env, req):
     data = req.form
     password = self.isso.conf.get("general", "admin_password")
     if data['password'] and data['password'] == password:
         response = redirect(re.sub(
             r'/login$',
             '/admin',
             get_current_url(env, strip_querystring=True)
         ))
         cookie = functools.partial(dump_cookie,
                                    value=self.isso.sign({"logged": True}),
                                    expires=datetime.now() + timedelta(1))
         response.headers.add("Set-Cookie", cookie("admin-session"))
         response.headers.add("X-Set-Cookie", cookie("isso-admin-session"))
         return response
     else:
         return render_template('login.html')