def wrapped_view(*args, **kwargs): if not current_user.email_confirmed: message = Markup( 'Please confirm your account first.' 'Not receive the email?' '<a class="alert-link" href="%s">Resend Confirm Email</a>' % url_for('auth.resend_confirm_email')) flash(message, 'warning') return redirect_back() return view(*args, **kwargs)
def re_authenticate(): """处理非新鲜登录的重认证""" if login_fresh(): return redirect(url_for('blog.index')) form = LoginForm() if form.validate_on_submit() and current_user.validate_password( form.password.data): confirm_login() return redirect_back() return render_template('auth/signin.html', form=form)
def reply_comment(pk, post_type): """实现评论的回复功能 以该视图作为中转传递被回复的评论的id。 在show_post视图中获取查询参数并进行相应处理。 :param pk: 被回复的comment id :param post_type: 发表评论的文章类型 """ comment = Comment.objects.get_or_404(pk=pk) post = Post.objects.get_or_404(slug=comment.post_slug) if post.can_comment: endpoints = {'post': 'blog.show_post', 'page': 'blog.show_page'} return redirect( url_for(endpoints[post_type], slug=post.slug, replyto=pk, author=comment.author) + '#comments') else: flash('This post is comment disabled.', 'warning') return redirect_back()
def login(): """处理用户登录""" if current_user.is_authenticated: return redirect(url_for('blog.index')) form = LoginForm() if form.validate_on_submit(): username = form.username.data password = form.password.data remember = form.remember.data user = User.objects.filter(username=username).first() if user: if username == user.username and user.validate_password(password): login_user(user, remember) flash('Welcome back', 'info') return redirect_back() flash('Invalid username or password.', 'warning') else: flash('Invalid username or password.', 'warning') return render_template('auth/signin.html', form=form)
def logout(): """处理用户注销""" logout_user() flash('Logout success.', 'info') return redirect_back()