mirror of
https://github.com/simple-login/app.git
synced 2025-09-29 01:46:49 +08:00
able to choose mailboxes for a domain
This commit is contained in:
parent
ec8f120085
commit
f5bc166f39
2 changed files with 143 additions and 14 deletions
|
@ -20,7 +20,10 @@
|
||||||
|
|
||||||
{% if not current_user.is_premium() %}
|
{% if not current_user.is_premium() %}
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
This feature is only available for Premium users. <a href="https://app.simplelogin.io/dashboard/pricing" target="_blank" rel="noopener">Upgrade<i class="fe fe-external-link"></i></a>
|
This feature is only available on Premium plan.
|
||||||
|
<a href="https://app.simplelogin.io/dashboard/pricing" target="_blank" rel="noopener">
|
||||||
|
Upgrade<i class="fe fe-external-link"></i>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -46,33 +49,99 @@
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</h5>
|
</h5>
|
||||||
<h6 class="card-subtitle mb-2 text-muted">
|
|
||||||
|
<h6 class="card-subtitle mb-4 text-muted">
|
||||||
Created {{ custom_domain.created_at | dt }} <br>
|
Created {{ custom_domain.created_at | dt }} <br>
|
||||||
<span class="font-weight-bold">{{ custom_domain.nb_alias() }}</span> aliases.
|
<span class="font-weight-bold">{{ custom_domain.nb_alias() }}</span> aliases.
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
<b>Mailboxes:</b>
|
||||||
|
<i class="fe fe-info" data-toggle="tooltip"
|
||||||
|
title="Aliases created with this domain are automatically owned by these mailboxes">
|
||||||
|
</i>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
{% set domain_mailboxes=custom_domain.mailboxes %}
|
||||||
|
<form method="post" class="mt-2">
|
||||||
|
<input type="hidden" name="form-name" value="update">
|
||||||
|
<input type="hidden" name="domain-id" value="{{ custom_domain.id }}">
|
||||||
|
|
||||||
|
<div class="d-flex">
|
||||||
|
<div class="flex-grow-1 mr-2">
|
||||||
|
<select data-width="100%" required
|
||||||
|
class="mailbox-select" multiple name="mailbox_ids">
|
||||||
|
{% for mailbox in mailboxes %}
|
||||||
|
<option value="{{ mailbox.id }}" {% if mailbox in domain_mailboxes %}
|
||||||
|
selected {% endif %}>
|
||||||
|
{{ mailbox.email }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button class="btn btn-outline-primary btn-sm">Update</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
</h6>
|
</h6>
|
||||||
|
|
||||||
<a href="{{ url_for('dashboard.domain_detail', custom_domain_id=custom_domain.id) }}">Details ➡</a>
|
<a href="{{ url_for('dashboard.domain_detail', custom_domain_id=custom_domain.id) }}" class="mt-3">
|
||||||
|
Details ➡
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="post">
|
<div class="row">
|
||||||
{{ new_custom_domain_form.csrf_token }}
|
<div class="col">
|
||||||
<input type="hidden" name="form-name" value="create">
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
<h2 class="h4">New Domain</h2>
|
<form method="post" class="mt-2">
|
||||||
|
{{ new_custom_domain_form.csrf_token }}
|
||||||
|
<input type="hidden" name="form-name" value="create">
|
||||||
|
|
||||||
{{ new_custom_domain_form.domain(class="form-control", placeholder="my-domain.com", maxlength=128) }}
|
<h2 class="h4">New Domain</h2>
|
||||||
{{ render_field_errors(new_custom_domain_form.domain) }}
|
|
||||||
<div class="small-text">Please use full path domain, for ex <em>my-subdomain.my-domain.com</em></div>
|
|
||||||
|
|
||||||
<button class="btn btn-lg btn-success mt-2">Create</button>
|
{{ new_custom_domain_form.domain(class="form-control", placeholder="my-domain.com", maxlength=128) }}
|
||||||
</form>
|
{{ render_field_errors(new_custom_domain_form.domain) }}
|
||||||
|
<div class="small-text">
|
||||||
|
Please use full path domain, for ex <em>my-subdomain.my-domain.com</em>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-3 small-text alert alert-info">
|
||||||
|
By default, aliases created with your domain are "owned" by your default
|
||||||
|
mailbox <b>{{ current_user.default_mailbox.email }}</b>. <br>
|
||||||
|
This below option allow you to choose the mailbox(es) that a new alias automatically belongs to.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<select data-width="100%"
|
||||||
|
class="mailbox-select" multiple name="mailbox_ids">
|
||||||
|
{% for mailbox in mailboxes %}
|
||||||
|
<option value="{{ mailbox.id }}" {% if mailbox.id == current_user.default_mailbox_id %}
|
||||||
|
selected {% endif %}>
|
||||||
|
{{ mailbox.email }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button class="btn btn-lg btn-success mt-2">Create</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
|
<script>
|
||||||
|
$('.mailbox-select').multipleSelect();
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
|
@ -7,7 +7,7 @@ from app.config import EMAIL_SERVERS_WITH_PRIORITY
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
from app.email_utils import get_email_domain_part
|
from app.email_utils import get_email_domain_part
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models import CustomDomain
|
from app.models import CustomDomain, Mailbox, DomainMailbox
|
||||||
|
|
||||||
|
|
||||||
class NewCustomDomainForm(FlaskForm):
|
class NewCustomDomainForm(FlaskForm):
|
||||||
|
@ -20,7 +20,7 @@ class NewCustomDomainForm(FlaskForm):
|
||||||
@login_required
|
@login_required
|
||||||
def custom_domain():
|
def custom_domain():
|
||||||
custom_domains = CustomDomain.query.filter_by(user_id=current_user.id).all()
|
custom_domains = CustomDomain.query.filter_by(user_id=current_user.id).all()
|
||||||
|
mailboxes = current_user.mailboxes()
|
||||||
new_custom_domain_form = NewCustomDomainForm()
|
new_custom_domain_form = NewCustomDomainForm()
|
||||||
|
|
||||||
errors = {}
|
errors = {}
|
||||||
|
@ -54,6 +54,28 @@ def custom_domain():
|
||||||
)
|
)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
mailbox_ids = request.form.getlist("mailbox_ids")
|
||||||
|
if mailbox_ids:
|
||||||
|
# check if mailbox is not tempered with
|
||||||
|
mailboxes = []
|
||||||
|
for mailbox_id in mailbox_ids:
|
||||||
|
mailbox = Mailbox.get(mailbox_id)
|
||||||
|
if (
|
||||||
|
not mailbox
|
||||||
|
or mailbox.user_id != current_user.id
|
||||||
|
or not mailbox.verified
|
||||||
|
):
|
||||||
|
flash("Something went wrong, please retry", "warning")
|
||||||
|
return redirect(url_for("dashboard.custom_domain"))
|
||||||
|
mailboxes.append(mailbox)
|
||||||
|
|
||||||
|
for mailbox in mailboxes:
|
||||||
|
DomainMailbox.create(
|
||||||
|
domain_id=new_custom_domain.id, mailbox_id=mailbox.id
|
||||||
|
)
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
flash(
|
flash(
|
||||||
f"New domain {new_custom_domain.domain} is created", "success"
|
f"New domain {new_custom_domain.domain} is created", "success"
|
||||||
)
|
)
|
||||||
|
@ -64,6 +86,43 @@ def custom_domain():
|
||||||
custom_domain_id=new_custom_domain.id,
|
custom_domain_id=new_custom_domain.id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
elif request.form.get("form-name") == "update":
|
||||||
|
domain_id = request.form.get("domain-id")
|
||||||
|
domain = CustomDomain.get(domain_id)
|
||||||
|
|
||||||
|
if not domain or domain.user_id != current_user.id:
|
||||||
|
flash("Unknown error. Refresh the page", "warning")
|
||||||
|
return redirect(url_for("dashboard.custom_domain"))
|
||||||
|
|
||||||
|
mailbox_ids = request.form.getlist("mailbox_ids")
|
||||||
|
# check if mailbox is not tempered with
|
||||||
|
mailboxes = []
|
||||||
|
for mailbox_id in mailbox_ids:
|
||||||
|
mailbox = Mailbox.get(mailbox_id)
|
||||||
|
if (
|
||||||
|
not mailbox
|
||||||
|
or mailbox.user_id != current_user.id
|
||||||
|
or not mailbox.verified
|
||||||
|
):
|
||||||
|
flash("Something went wrong, please retry", "warning")
|
||||||
|
return redirect(url_for("dashboard.custom_domain"))
|
||||||
|
mailboxes.append(mailbox)
|
||||||
|
|
||||||
|
if not mailboxes:
|
||||||
|
flash("You must select at least 1 mailbox", "warning")
|
||||||
|
return redirect(url_for("dashboard.custom_domain"))
|
||||||
|
|
||||||
|
# first remove all existing domain-mailboxes links
|
||||||
|
DomainMailbox.query.filter_by(domain_id=domain.id).delete()
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
|
for mailbox in mailboxes:
|
||||||
|
DomainMailbox.create(domain_id=domain.id, mailbox_id=mailbox.id)
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
flash(f"Domain {domain.domain} has been updated", "success")
|
||||||
|
|
||||||
|
return redirect(url_for("dashboard.custom_domain"))
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"dashboard/custom_domain.html",
|
"dashboard/custom_domain.html",
|
||||||
|
@ -71,4 +130,5 @@ def custom_domain():
|
||||||
new_custom_domain_form=new_custom_domain_form,
|
new_custom_domain_form=new_custom_domain_form,
|
||||||
EMAIL_SERVERS_WITH_PRIORITY=EMAIL_SERVERS_WITH_PRIORITY,
|
EMAIL_SERVERS_WITH_PRIORITY=EMAIL_SERVERS_WITH_PRIORITY,
|
||||||
errors=errors,
|
errors=errors,
|
||||||
|
mailboxes=mailboxes,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue