[docs]@blueprint.route("/<token>",methods=["GET"])@login_requireddefconfirm_email(token:str)->Response:"""Confirm each individual user registering with their email. There is no view for this route and so the user will be redirected to the index page. :param token: Encrypted token to verify correct user. :return: Response object redirect to index view. """try:email=confirm_token(token)user=User.query.filter_by(email=email).first()ifuser.confirmed:flash(_("Account already confirmed. Please login."))else:user.confirmed=Trueuser.confirmed_on=datetime.now()db.session.add(user)db.session.commit()flash(_("Your account has been verified."))exceptBadSignature:flash(_("The confirmation link is invalid or has expired."))returnredirect(url_for("index"))
[docs]@blueprint.route("/resend",methods=["GET"])@login_requireddefresend_confirmation()->Response:"""Resend verification email. There is no view for this route and so the user will be redirected to the auth/unconfirmed view. :return: Response object redirect to auth/unconfirmed view. """send_email(subject="Please verify your email address",recipients=[current_user.email],html=render_template("email/activate.html",confirm_url=url_for("redirect.confirm_email",token=generate_confirmation_token(current_user.email),_external=True,),),)flash(_("A new confirmation email has been sent."))returnredirect(url_for("auth.unconfirmed"))
[docs]@blueprint.route("/follow/<username>",methods=["POST"])@login_required@confirmation_requireddeffollow(username:str)->Response:"""Add a user model to follow to the current user model. There is no view for this route and so the user will be redirected to the profile view. :param username: User to follow. :return: Response object redirect to profile view of user that has been followed. """form=EmptyForm()ifform.validate_on_submit():user=User.query.filter_by(username=username).first_or_404()current_user.follow(user)db.session.commit()flash(_("You are now following %(username)s",username=username))returnredirect(url_for("public.profile",username=username))
[docs]@blueprint.route("/unfollow/<username>",methods=["POST"])@login_required@confirmation_requireddefunfollow(username:str)->Response:"""Remove a user model to unfollow from the current user model. There is no view for this route and so the user will be redirected to the profile view. :param username: User to unfollow. :return: response object redirect to profile view of user that has been unfollowed. """form=EmptyForm()ifform.validate_on_submit():user=User.query.filter_by(username=username).first_or_404()current_user.unfollow(user)db.session.commit()flash(_("You are no longer following %(username)s",username=username))returnredirect(url_for("public.profile",username=username))