|  |  | @ -2,6 +2,8 @@ from datetime import datetime | 
			
		
	
		
			
				
					|  |  |  | import hashlib | 
			
		
	
		
			
				
					|  |  |  | from werkzeug.security import generate_password_hash, check_password_hash | 
			
		
	
		
			
				
					|  |  |  | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer | 
			
		
	
		
			
				
					|  |  |  | from markdown import markdown | 
			
		
	
		
			
				
					|  |  |  | import bleach | 
			
		
	
		
			
				
					|  |  |  | from itsdangerous import BadSignature | 
			
		
	
		
			
				
					|  |  |  | from flask import current_app | 
			
		
	
		
			
				
					|  |  |  | from flask_login import UserMixin, AnonymousUserMixin | 
			
		
	
	
		
			
				
					|  |  | @ -191,9 +193,22 @@ class Post(db.Model): | 
			
		
	
		
			
				
					|  |  |  | __tablename__ = 'posts' | 
			
		
	
		
			
				
					|  |  |  | id = db.Column(db.Integer, primary_key=True) | 
			
		
	
		
			
				
					|  |  |  | body = db.Column(db.Text) | 
			
		
	
		
			
				
					|  |  |  | body_html = db.Column(db.Text) | 
			
		
	
		
			
				
					|  |  |  | timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) | 
			
		
	
		
			
				
					|  |  |  | author_id = db.Column(db.Integer, db.ForeignKey('users.id')) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | @staticmethod | 
			
		
	
		
			
				
					|  |  |  | def on_changed_body(target, value, oldvalue, initiator): | 
			
		
	
		
			
				
					|  |  |  | allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code', | 
			
		
	
		
			
				
					|  |  |  | 'em', 'i', 'li', 'ol', 'pre', 'strong', 'ul', | 
			
		
	
		
			
				
					|  |  |  | 'h1', 'h2', 'h3', 'p'] | 
			
		
	
		
			
				
					|  |  |  | md = markdown(value, output_format='html') | 
			
		
	
		
			
				
					|  |  |  | clean_md = bleach.clean(md, tags=allowed_tags, strip=True) | 
			
		
	
		
			
				
					|  |  |  | target.body_html = bleach.linkify(clean_md) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | db.event.listen(Post.body, 'set', Post.on_changed_body) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | class AnonymousUser(AnonymousUserMixin): | 
			
		
	
		
			
				
					|  |  |  | def can(self, perm): | 
			
		
	
	
		
			
				
					|  |  | 
 |