diff --git a/app/blueprints/github/__init__.py b/app/blueprints/github/__init__.py index b3be731..c65a68d 100644 --- a/app/blueprints/github/__init__.py +++ b/app/blueprints/github/__init__.py @@ -24,7 +24,7 @@ from sqlalchemy import func from flask_github import GitHub from app import github, csrf from app.models import db, User, APIToken, Package, Permission -from app.utils import loginUser, randomString +from app.utils import loginUser, randomString, abs_url_for from app.blueprints.api.support import error, handleCreateRelease import hmac, requests, json @@ -180,7 +180,7 @@ def setup_webhook(): if current_user.github_access_token is None: return github.authorize("write:repo_hook", \ - redirect_uri=url_for("github.callback_webhook", pid=pid, _external=True)) + redirect_uri=abs_url_for("github.callback_webhook", pid=pid)) form = SetupWebhookForm(formdata=request.form) if request.method == "POST" and form.validate(): @@ -214,7 +214,7 @@ def handleMakeWebhook(gh_user, gh_repo, package, oauth, event, token): "active": True, "events": [event], "config": { - "url": url_for("github.webhook", _external=True), + "url": abs_url_for("github.webhook"), "content_type": "json", "secret": token.access_token }, diff --git a/app/tasks/emails.py b/app/tasks/emails.py index f81deaa..fa5a8c8 100644 --- a/app/tasks/emails.py +++ b/app/tasks/emails.py @@ -19,6 +19,7 @@ from flask import render_template, url_for from flask_mail import Message from app import mail from app.tasks import celery +from app.utils import abs_url_for @celery.task() def sendVerifyEmail(newEmail, token): @@ -34,7 +35,7 @@ def sendVerifyEmail(newEmail, token): If this was you, then please click this link to verify the address: {} - """.format(url_for('users.verify_email', token=token, _external=True)) + """.format(abs_url_for('users.verify_email', token=token)) msg.html = render_template("emails/verify.html", token=token) mail.send(msg) diff --git a/app/templates/emails/verify.html b/app/templates/emails/verify.html index 04a4bc5..925521a 100644 --- a/app/templates/emails/verify.html +++ b/app/templates/emails/verify.html @@ -16,12 +16,12 @@ If this was you, then please click this link to verify the address:

- + Confirm Email Address

- Or paste this into your browser: {{ url_for('users.verify_email', token=token, _external=True) }} + Or paste this into your browser: {{ abs_url_for('users.verify_email', token=token) }}

{% endblock %} diff --git a/app/utils.py b/app/utils.py index f44622d..712339b 100644 --- a/app/utils.py +++ b/app/utils.py @@ -22,6 +22,12 @@ from app.models import * from app import app import random, string, os, imghdr + +@app.template_filter() +def abs_url_for(path, **kwargs): + scheme = "https" if app.config["BASE_URL"][:5] == "https" else "http" + return url_for(path, _external=True, _scheme=scheme, **kwargs) + def get_int_or_abort(v, default=None): try: return int(v or default)