Просмотр исходного кода

注册时用户组,回复可带部分html标签,feed标题

honmaple 9 лет назад
Родитель
Сommit
e48738e4a1

+ 5 - 3
maple/auth/views.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Created: 2016-06-17 13:25:39 (CST)
-# Last Update:星期五 2016-6-17 13:36:59 (CST)
+# Last Update:星期日 2016-6-19 13:36:5 (CST)
 #          By:
 # Description:
 # **************************************************************************
@@ -25,8 +25,10 @@ class Login(Auth):
         user.infor = userinfor
         usersetting = UserSetting()
         user.setting = usersetting
-        role = Role()
-        role.rolename = 'unconfirmed'
+        role = Role.query.filter_by(rolename='unconfirmed').first()
+        if role is None:
+            role = Role()
+            role.rolename = 'unconfirmed'
         user.roles.append(role)
         self.db.session.add(user)
         self.db.session.commit()

+ 3 - 2
maple/extensions.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Created: 2016-05-20 13:02:50 (CST)
-# Last Update:星期五 2016-6-17 13:36:25 (CST)
+# Last Update:星期日 2016-6-19 16:23:11 (CST)
 #          By:
 # Description:
 # **************************************************************************
@@ -117,7 +117,7 @@ def register_redis(app):
 
 def register_jinja2(app):
     from maple.main.records import load_online_users
-    from .filters import Filters
+    from .filters import Filters, safe_clean
 
     app.jinja_env.globals['Title'] = Filters.Title
     app.jinja_env.filters['get_last_reply'] = Filters.get_last_reply
@@ -126,3 +126,4 @@ def register_jinja2(app):
     app.jinja_env.filters['timesince'] = Filters.timesince
     app.jinja_env.filters['get_online_users'] = load_online_users
     app.jinja_env.filters['markdown'] = Filters.safe_markdown
+    app.jinja_env.filters['safe_clean'] = safe_clean

+ 3 - 3
maple/filters.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Created: 2016-06-15 00:39:29 (CST)
-# Last Update:星期五 2016-6-17 13:36:44 (CST)
+# Last Update:星期日 2016-6-19 16:26:44 (CST)
 #          By:
 # Description:
 # **************************************************************************
@@ -24,8 +24,8 @@ from bleach import clean
 
 
 def safe_clean(text):
-    tags = ['b', 'i', 'font', 'br', 'blockquote', 'a', 'div', 'ul', 'li', 'h2']
-    attrs = {'*': ['style', 'id', 'class'], 'font': ['color'], 'a': ['href']}
+    tags = ['b', 'i', 'font', 'br', 'blockquote', 'div', 'h2']
+    attrs = {'*': ['style', 'id', 'class'], 'font': ['color']}
     styles = ['color']
     return Markup(clean(text, tags=tags, attributes=attrs, styles=styles))
 

+ 3 - 2
maple/forums/views.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Created: 2016-05-20 13:18:19 (CST)
-# Last Update:星期三 2016-6-15 19:4:31 (CST)
+# Last Update:星期日 2016-6-19 16:6:42 (CST)
 #          By:
 # Description:
 # **************************************************************************
@@ -48,7 +48,8 @@ def forums():
 def notice(page):
     notices = Notice.query.join(Notice.rece_user).filter(
         User.username == current_user.username).paginate(
-            page, app.config['PER_PAGE'],
+            page,
+            app.config['PER_PAGE'],
             error_out=True)
     return render_template('forums/notice.html', notices=notices)
 

+ 7 - 5
maple/tag/views.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Created: 2016-05-20 13:18:19 (CST)
-# Last Update:星期五 2016-6-17 13:28:58 (CST)
+# Last Update:星期日 2016-6-19 16:51:32 (CST)
 #          By:
 # Description:
 # **************************************************************************
@@ -14,9 +14,11 @@ from flask import Blueprint, render_template, request, url_for
 from maple import app
 from maple.helpers import is_num
 from maple.topic.models import Tags, Topic
+from maple.filters import Filters
 from urllib.parse import urljoin
+from werkzeug.utils import escape
 from werkzeug.contrib.atom import AtomFeed
-from maple.filters import Filters
+
 
 site = Blueprint('tag', __name__)
 
@@ -41,7 +43,7 @@ def tag(tag):
 
 @site.route('/<tag>/feed')
 def rss(tag):
-    feed = AtomFeed('Recent Topics',
+    feed = AtomFeed('%s·HonMaple社区'%tag,
                     feed_url=request.url,
                     url=request.url_root,
                     subtitle='I like solitude, yearning for freedom')
@@ -50,8 +52,8 @@ def rss(tag):
     for topic in topics:
         feed.add(
             topic.title,
-            Filters.safe_markdown(topic.content)
-            if topic.is_markdown else topic.content,
+            escape(Filters.safe_markdown(topic.content)
+            if topic.is_markdown else topic.content),
             content_type='html',
             author=topic.author.username,
             url=urljoin(request.url_root,

+ 1 - 1
maple/templates/maple/footer.html

@@ -1,6 +1,6 @@
 <div class="footer col-md-offset-1 col-md-10" style="padding:0">
     <div class="row">
-        <div class="col-md-6 text-center">
+        <div class="col-md-6 text-center hidden-xs">
             <small style="color:#999">
                 <span>当前在线用户:<strong style="color:#333;">{{ 'all_counts' | get_online_users }}</strong></span>
                 <span style="margin-left:10px">注册用户:<strong style="color:#333;">{{ 'sign_counts' | get_online_users }}</strong></span>

+ 1 - 1
maple/templates/topic/content.html

@@ -55,7 +55,7 @@ board.board:url_for('board.board',parent_b=board.parent_board,child_b=board.boar
                 {% if topic.is_markdown %}
                 {{ topic.content | markdown }}
                 {% else %}
-                {{ topic.content }}
+                {{ topic.content | safe_clean }}
                 {% endif %}
             </div>
         </div>

+ 1 - 1
maple/templates/topic/replies.html

@@ -77,7 +77,7 @@
                 <a name="reply{{ num }}" class="anchor" href="#reply{{ num }}" aria-hidden="true">#{{ num }}</a>
             </small>
             <div>
-                {{ reply.content}}
+                {{ reply.content | safe_clean }}
             </div>
         </div>
         <div class="media-right">

+ 1 - 1
maple/topic/models.py

@@ -6,7 +6,7 @@
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Created: 2016-05-20 13:32:12 (CST)
-# Last Update:星期五 2016-6-17 10:44:16 (CST)
+# Last Update:星期日 2016-6-19 16:6:52 (CST)
 #          By:
 # Description:
 # **************************************************************************

+ 3 - 0
requirements.txt

@@ -30,6 +30,7 @@ Flask-Login==0.3.2
 Flask-Mail==0.9.1
 Flask-Maple==0.3.4
 Flask-Migrate==1.8.0
+Flask-OAuthlib==0.9.3
 Flask-Plugins==1.6.1
 Flask-Principal==0.4.0
 Flask-Redis==0.1.0
@@ -53,6 +54,7 @@ Mako==1.0.4
 MarkupSafe==0.23
 misaka==2.0.0
 mistune==0.7.1
+oauthlib==1.1.2
 Pillow==3.2.0
 psycopg2==2.6.1
 pycparser==2.14
@@ -65,6 +67,7 @@ python-socketio==1.2
 pytz==2016.4
 redis==2.10.5
 requests==2.9.1
+requests-oauthlib==0.6.1
 simplejson==3.8.1
 six==1.10.0
 speaklater==1.3