def discussion(id): user = None message = None isLogin = Account.isLogin() if isLogin: user = Account.get_current_user() if request.method == 'POST': if isLogin: DBHelper.create_comment(id, user.username, request.form['content']) DBHelper.update_comment_count(id) else: message = 'please login' article = DBHelper.get_article(id) article.time = post_time(article.create_at) comments = DBHelper.get_comments(id) if comments: for comment in comments: comment.time = post_time(comment.create_at) statistics = {} statistics['user_count'] = DBHelper.get_user_count() statistics['article_count'] = DBHelper.get_article_count() statistics['comment_count'] = DBHelper.get_comment_count() return render_template('discussion.html', user=user, article=article, comments=comments, statistics=statistics, message=message)
def setting_avatar(): user = Account.get_current_user() if request.method == 'POST': file = request.files['avatar'] file_name = secure_filename(file.filename) file.save(os.path.join('avatar', file_name)) DBHelper.update_avatar(user.id, '/avatar/' + file_name) user = Account.get_current_user() return render_template('setting.html', user=user)
def setting(): user = Account.get_current_user() if request.method == 'POST': DBHelper.update_user(user.id, request.form['username']) DBHelper.update_social_account(user.id, request.form['github'], request.form['weibo'], request.form['twitter']) user = Account.get_current_user() return render_template('setting.html', user=user)
def set_reset_info(): msg = None if request.method == 'POST': user = DBHelper.get_user(request.form['email']) if user: Account.send_email(user) msg = "已发送到邮箱" else: msg = "没有该用户" return render_template('reset_info.html', msg=msg)
def signup(): if Account.isLogin(): return redirect(url_for('index')) if request.method == 'GET': return render_template('register.html') else: if Account.isRegister(request.form['email']): return render_template('register.html') else: Account.register(request.form['username'], request.form['email'], request.form['password']) return redirect(url_for('login'))
def login(): message = None if Account.isLogin(): return redirect(url_for('index')) if request.method == 'POST': isLogin = Account.login(request.form['email'], request.form['password']) if isLogin: return redirect(url_for('index')) else: message = '账号或密码错误' return render_template('login.html', message=message) else: return render_template('login.html', message=None)
def classify(tag): user = None message = None if Account.isLogin(): user = Account.get_current_user() articles = DBHelper.get_articles_by_tag(tag, 0) statistics = {} statistics['user_count'] = DBHelper.get_user_count() statistics['article_count'] = DBHelper.get_article_count() statistics['comment_count'] = DBHelper.get_comment_count() return render_template('index.html', user=user, articles=articles, tag=tag, statistics=statistics)
def article(): user = None if Account.isLogin(): user = Account.get_current_user() statistics = {} statistics['user_count'] = DBHelper.get_user_count() statistics['article_count'] = DBHelper.get_article_count() statistics['comment_count'] = DBHelper.get_comment_count() if request.method == 'GET': return render_template('article.html', user=user, statistics=statistics) else: DBHelper.create_article(user.username, request.form['tag'], request.form['title'], request.form['contentArea']) return redirect(url_for('index'))
def index(): user = None if Account.isLogin(): user = Account.get_current_user() articles = DBHelper.get_articles(0) if articles: for article in articles: article.time = post_time(article.create_at) statistics = {} statistics['user_count'] = DBHelper.get_user_count() statistics['article_count'] = DBHelper.get_article_count() statistics['comment_count'] = DBHelper.get_comment_count() return render_template('index.html', user=user, articles=articles, tag='all', statistics=statistics)
def setting_password(): user = Account.get_current_user() if request.method == 'POST': password_current = request.form['password_current'] password_new = request.form['password_new'] if password_current == user.password: DBHelper.update_password(user.id, password_new) return render_template('setting.html', user=user)
def notification(): user = Account.get_current_user() comments = DBHelper.get_notifications(user.username) if comments: for comment in comments: comment['time'] = post_time(comment['create_at']) comment_user = DBHelper.get_user_by_name(comment['username']) comment['avatar'] = comment_user.avatar return render_template('notification.html', user=user, comments=comments)
def user(username): user = Account.get_current_user() articles = DBHelper.get_articles_by_username(username, 0) if articles: for article in articles: article.time = post_time(article.create_at) comments = DBHelper.get_comments_by_username(username, 0) commentted_articles = DBHelper.get_articles_by_comments(username, 0) if comments: index = 0 for comment in comments: comment.article_title = commentted_articles[index].title comment.time = post_time(comment.create_at) index = index + 1 return render_template('user.html', user=user, articles=articles, comments=comments)
def logout(): Account.logout() return redirect(url_for('index'))