Merge pull request #31 from simple-login/canceled-premium
Canceled premium
This commit is contained in:
commit
70e16bb415
|
@ -13,6 +13,12 @@
|
|||
<div class="col-md-8 offset-md-2">
|
||||
<h1 class="h3"> Custom Domains </h1>
|
||||
|
||||
{% if not current_user.is_premium() %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
This feature is only available in premium plan.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for custom_domain in custom_domains %}
|
||||
<div class="card" style="max-width: 50rem">
|
||||
<div class="card-body">
|
||||
|
|
|
@ -10,6 +10,12 @@
|
|||
<div class="col-md-8 offset-md-2">
|
||||
<h1 class="h3"> Directories </h1>
|
||||
|
||||
{% if not current_user.is_premium() %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
This feature is only available in premium plan.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="alert alert-primary" role="alert">
|
||||
Directory allows you to create aliases <b>on the fly</b>. <br>
|
||||
Simply use <em>directory/<b>anything</b>@{{ EMAIL_DOMAIN }}</em>
|
||||
|
|
|
@ -17,11 +17,6 @@ class NewCustomDomainForm(FlaskForm):
|
|||
@dashboard_bp.route("/custom_domain", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def custom_domain():
|
||||
# only premium user can add custom domain
|
||||
if not current_user.is_premium():
|
||||
flash("Only premium user can add custom domains", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
custom_domains = CustomDomain.query.filter_by(user_id=current_user.id).all()
|
||||
|
||||
new_custom_domain_form = NewCustomDomainForm()
|
||||
|
@ -30,6 +25,10 @@ def custom_domain():
|
|||
|
||||
if request.method == "POST":
|
||||
if request.form.get("form-name") == "create":
|
||||
if not current_user.is_premium():
|
||||
flash("Only premium plan can add custom domain", "warning")
|
||||
return redirect(url_for("dashboard.custom_domain"))
|
||||
|
||||
if new_custom_domain_form.validate():
|
||||
new_domain = new_custom_domain_form.domain.data.strip()
|
||||
if CustomDomain.get_by(domain=new_domain):
|
||||
|
|
|
@ -18,11 +18,6 @@ class NewDirForm(FlaskForm):
|
|||
@dashboard_bp.route("/directory", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def directory():
|
||||
# only premium user can add directory
|
||||
if not current_user.is_premium():
|
||||
flash("Only premium user can add directories", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
dirs = Directory.query.filter_by(user_id=current_user.id).all()
|
||||
|
||||
new_dir_form = NewDirForm()
|
||||
|
@ -47,6 +42,10 @@ def directory():
|
|||
return redirect(url_for("dashboard.directory"))
|
||||
|
||||
elif request.form.get("form-name") == "create":
|
||||
if not current_user.is_premium():
|
||||
flash("Only premium plan can add directory", "warning")
|
||||
return redirect(url_for("dashboard.directory"))
|
||||
|
||||
if new_dir_form.validate():
|
||||
new_dir_name = new_dir_form.name.data.lower()
|
||||
|
||||
|
@ -60,7 +59,7 @@ def directory():
|
|||
|
||||
flash(f"Directory {new_dir.name} is created", "success")
|
||||
|
||||
return redirect(url_for("dashboard.directory",))
|
||||
return redirect(url_for("dashboard.directory"))
|
||||
|
||||
return render_template(
|
||||
"dashboard/directory.html",
|
||||
|
|
|
@ -16,11 +16,6 @@ from app.models import CustomDomain, GenEmail
|
|||
@dashboard_bp.route("/domains/<int:custom_domain_id>/dns", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def domain_detail_dns(custom_domain_id):
|
||||
# only premium user can see custom domain
|
||||
if not current_user.is_premium():
|
||||
flash("Only premium user can add custom domains", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
custom_domain = CustomDomain.get(custom_domain_id)
|
||||
if not custom_domain or custom_domain.user_id != current_user.id:
|
||||
flash("You cannot see this page", "warning")
|
||||
|
@ -103,11 +98,6 @@ def domain_detail_dns(custom_domain_id):
|
|||
@dashboard_bp.route("/domains/<int:custom_domain_id>/info", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def domain_detail(custom_domain_id):
|
||||
# only premium user can see custom domain
|
||||
if not current_user.is_premium():
|
||||
flash("Only premium user can add custom domains", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
custom_domain = CustomDomain.get(custom_domain_id)
|
||||
if not custom_domain or custom_domain.user_id != current_user.id:
|
||||
flash("You cannot see this page", "warning")
|
||||
|
|
|
@ -101,6 +101,47 @@ def send_test_email_alias(email, name):
|
|||
)
|
||||
|
||||
|
||||
def send_cannot_create_directory_alias(user, alias, directory):
|
||||
"""when user cancels their subscription, they cannot create alias on the fly.
|
||||
If this happens, send them an email to notify
|
||||
"""
|
||||
send_email(
|
||||
user.email,
|
||||
f"Alias {alias} cannot be created",
|
||||
_render(
|
||||
"cannot-create-alias-directory.txt",
|
||||
name=user.name,
|
||||
alias=alias,
|
||||
directory=directory,
|
||||
),
|
||||
_render(
|
||||
"cannot-create-alias-directory.html",
|
||||
name=user.name,
|
||||
alias=alias,
|
||||
directory=directory,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def send_cannot_create_domain_alias(user, alias, domain):
|
||||
"""when user cancels their subscription, they cannot create alias on the fly with custom domain.
|
||||
If this happens, send them an email to notify
|
||||
"""
|
||||
send_email(
|
||||
user.email,
|
||||
f"Alias {alias} cannot be created",
|
||||
_render(
|
||||
"cannot-create-alias-domain.txt", name=user.name, alias=alias, domain=domain
|
||||
),
|
||||
_render(
|
||||
"cannot-create-alias-domain.html",
|
||||
name=user.name,
|
||||
alias=alias,
|
||||
domain=domain,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def send_email(to_email, subject, plaintext, html):
|
||||
if NOT_SEND_EMAIL:
|
||||
LOG.d(
|
||||
|
|
|
@ -720,6 +720,8 @@ class CustomDomain(db.Model, ModelMixin):
|
|||
# an alias is created automatically the first time it receives an email
|
||||
catch_all = db.Column(db.Boolean, nullable=False, default=False, server_default="0")
|
||||
|
||||
user = db.relationship(User)
|
||||
|
||||
def nb_alias(self):
|
||||
return GenEmail.filter_by(custom_domain_id=self.id).count()
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ from app.email_utils import (
|
|||
get_email_domain_part,
|
||||
add_or_replace_header,
|
||||
delete_header,
|
||||
send_cannot_create_directory_alias,
|
||||
send_cannot_create_domain_alias,
|
||||
)
|
||||
from app.extensions import db
|
||||
from app.log import LOG
|
||||
|
@ -110,7 +112,9 @@ class MailHandler:
|
|||
|
||||
gen_email = GenEmail.get_by(email=alias)
|
||||
if not gen_email:
|
||||
LOG.d("alias %s not exist. Try to see if it can created on the fly", alias)
|
||||
LOG.d(
|
||||
"alias %s not exist. Try to see if it can be created on the fly", alias
|
||||
)
|
||||
|
||||
# try to see if alias could be created on-the-fly
|
||||
on_the_fly = False
|
||||
|
@ -122,31 +126,56 @@ class MailHandler:
|
|||
LOG.d("directory_name %s", directory_name)
|
||||
|
||||
directory = Directory.get_by(name=directory_name)
|
||||
if directory:
|
||||
LOG.d("create alias %s for directory %s", alias, directory)
|
||||
on_the_fly = True
|
||||
|
||||
gen_email = GenEmail.create(
|
||||
email=alias,
|
||||
user_id=directory.user_id,
|
||||
directory_id=directory.id,
|
||||
)
|
||||
db.session.commit()
|
||||
# Only premium user can continue using the directory feature
|
||||
if directory:
|
||||
dir_user = directory.user
|
||||
if dir_user.is_premium():
|
||||
LOG.d("create alias %s for directory %s", alias, directory)
|
||||
on_the_fly = True
|
||||
|
||||
gen_email = GenEmail.create(
|
||||
email=alias,
|
||||
user_id=directory.user_id,
|
||||
directory_id=directory.id,
|
||||
)
|
||||
db.session.commit()
|
||||
else:
|
||||
LOG.error(
|
||||
"User %s is not premium anymore and cannot create alias with directory",
|
||||
dir_user,
|
||||
)
|
||||
send_cannot_create_directory_alias(
|
||||
dir_user, alias, directory_name
|
||||
)
|
||||
else:
|
||||
# check if alias is custom-domain alias and if the custom-domain has catch-all enabled
|
||||
alias_domain = get_email_domain_part(alias)
|
||||
custom_domain = CustomDomain.get_by(domain=alias_domain)
|
||||
if custom_domain and custom_domain.catch_all:
|
||||
LOG.d("create alias %s for domain %s", alias, custom_domain)
|
||||
on_the_fly = True
|
||||
|
||||
gen_email = GenEmail.create(
|
||||
email=alias,
|
||||
user_id=custom_domain.user_id,
|
||||
custom_domain_id=custom_domain.id,
|
||||
automatic_creation=True,
|
||||
)
|
||||
db.session.commit()
|
||||
# Only premium user can continue using the catch-all feature
|
||||
if custom_domain and custom_domain.catch_all:
|
||||
domain_user = custom_domain.user
|
||||
if domain_user.is_premium():
|
||||
LOG.d("create alias %s for domain %s", alias, custom_domain)
|
||||
on_the_fly = True
|
||||
|
||||
gen_email = GenEmail.create(
|
||||
email=alias,
|
||||
user_id=custom_domain.user_id,
|
||||
custom_domain_id=custom_domain.id,
|
||||
automatic_creation=True,
|
||||
)
|
||||
db.session.commit()
|
||||
else:
|
||||
LOG.error(
|
||||
"User %s is not premium anymore and cannot create alias with domain %s",
|
||||
domain_user,
|
||||
alias_domain,
|
||||
)
|
||||
send_cannot_create_domain_alias(
|
||||
domain_user, alias, alias_domain
|
||||
)
|
||||
|
||||
if not on_the_fly:
|
||||
LOG.d("alias %s not exist, return 510", alias)
|
||||
|
|
|
@ -46,6 +46,7 @@ from app.models import (
|
|||
ApiKey,
|
||||
CustomDomain,
|
||||
LifetimeCoupon,
|
||||
Directory,
|
||||
)
|
||||
from app.monitor.base import monitor_bp
|
||||
from app.oauth.base import oauth_bp
|
||||
|
@ -158,6 +159,10 @@ def fake_data():
|
|||
)
|
||||
db.session.commit()
|
||||
|
||||
Directory.create(user_id=user.id, name="abcd")
|
||||
Directory.create(user_id=user.id, name="xyzt")
|
||||
db.session.commit()
|
||||
|
||||
# Create a client
|
||||
client1 = Client.create_new(name="Demo", user_id=user.id)
|
||||
client1.oauth_client_id = "client-id"
|
||||
|
|
8
templates/emails/cannot-create-alias-directory.html
Normal file
8
templates/emails/cannot-create-alias-directory.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
Hi {{name}} <br><br>
|
||||
|
||||
An email has been sent to the alias <b>{{alias}}</b> that would be created automatically as you own the directory <b>{{directory}}</b>. However as your plan is no longer premium, this creation cannot happen.<br><br>
|
||||
|
||||
Please upgrade to premium plan in order to use this feature.<br><br>
|
||||
|
||||
Best,<br>
|
||||
SimpleLogin team.
|
7
templates/emails/cannot-create-alias-directory.txt
Normal file
7
templates/emails/cannot-create-alias-directory.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
Hi {{name}}
|
||||
|
||||
An email has been sent to the alias {{alias}} that would be created automatically as you own the directory {{directory}}. However as your plan is no longer premium, this creation cannot happen.
|
||||
|
||||
Please upgrade to premium plan in order to use this feature.
|
||||
Best,
|
||||
SimpleLogin team.
|
8
templates/emails/cannot-create-alias-domain.html
Normal file
8
templates/emails/cannot-create-alias-domain.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
Hi {{name}} <br><br>
|
||||
|
||||
An email has been sent to the alias <b>{{alias}}</b> that would be created automatically as you own the domain <b>{{domain}}</b>. However as your plan is no longer premium, this creation cannot happen.<br><br>
|
||||
|
||||
Please upgrade to premium plan in order to use this feature.<br><br>
|
||||
|
||||
Best,<br>
|
||||
SimpleLogin team.
|
7
templates/emails/cannot-create-alias-domain.txt
Normal file
7
templates/emails/cannot-create-alias-domain.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
Hi {{name}}
|
||||
|
||||
An email has been sent to the alias {{alias}} that would be created automatically as you own the domain {{domain}}. However as your plan is no longer premium, this creation cannot happen.
|
||||
|
||||
Please upgrade to premium plan in order to use this feature.
|
||||
Best,
|
||||
SimpleLogin team.
|
Loading…
Reference in a new issue