mirror of
https://github.com/simple-login/app.git
synced 2024-11-18 06:31:27 +08:00
Merge pull request #136 from simple-login/refactor
Refactor: remove unused POST
This commit is contained in:
commit
c8ed1437f1
2 changed files with 74 additions and 156 deletions
|
@ -110,34 +110,31 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col text-right">
|
<div class="col text-right">
|
||||||
<form method="post">
|
<label class="custom-switch cursor"
|
||||||
<input type="hidden" name="form-name" value="switch-email-forwarding">
|
data-toggle="tooltip"
|
||||||
<input type="hidden" name="alias-id" value="{{ alias.id }}">
|
{% if alias.enabled %}
|
||||||
<label class="custom-switch cursor"
|
title="Disable alias - you will stop receiving emails sent to this alias"
|
||||||
data-toggle="tooltip"
|
{% else %}
|
||||||
{% if alias.enabled %}
|
title="Enable alias - you will start receiving emails sent to this alias"
|
||||||
title="Disable alias - you will stop receiving emails sent to this alias"
|
{% endif %}
|
||||||
{% else %}
|
|
||||||
title="Enable alias - you will start receiving emails sent to this alias"
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if loop.index ==1 %}
|
{% if loop.index ==1 %}
|
||||||
data-intro="By turning off an alias, emails sent to this alias will <em>not</em>
|
data-intro="By turning off an alias, emails sent to this alias will <em>not</em>
|
||||||
be forwarded to your inbox. <br><br>
|
be forwarded to your inbox. <br><br>
|
||||||
This should be used with care as others might
|
This should be used with care as others might
|
||||||
not be able to reach you after ...
|
not be able to reach you after ...
|
||||||
"
|
"
|
||||||
data-step="3"
|
data-step="3"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
style="padding-left: 0px"
|
style="padding-left: 0px"
|
||||||
>
|
>
|
||||||
<input type="hidden" name="alias" class="alias" value="{{ alias.email }}">
|
<input type="checkbox" class="custom-switch-input"
|
||||||
<input type="checkbox" class="custom-switch-input" data-alias="{{ alias.id }}"
|
data-alias="{{ alias.id }}"
|
||||||
{{ "checked" if alias.enabled else "" }}>
|
data-alias-email="{{ alias.email }}"
|
||||||
|
{{ "checked" if alias.enabled else "" }}>
|
||||||
|
|
||||||
<span class="custom-switch-indicator"></span>
|
<span class="custom-switch-indicator"></span>
|
||||||
</label>
|
</label>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -218,61 +215,51 @@
|
||||||
<div class="collapse" id="alias-{{ alias.id }}">
|
<div class="collapse" id="alias-{{ alias.id }}">
|
||||||
|
|
||||||
{% if mailboxes|length > 1 %}
|
{% if mailboxes|length > 1 %}
|
||||||
<form method="post">
|
<div class="small-text mt-2">Current mailbox</div>
|
||||||
<div class="small-text mt-2">Current mailbox</div>
|
<div class="d-flex">
|
||||||
<div class="d-flex">
|
<div class="flex-grow-1 mr-2">
|
||||||
<div class="flex-grow-1 mr-2">
|
<select id="mailbox-{{ alias.id }}"
|
||||||
<select id="mailbox-{{ alias.id }}"
|
class="form-control form-control-sm custom-select" name="mailbox">
|
||||||
class="form-control form-control-sm custom-select" name="mailbox">
|
{% for mailbox in mailboxes %}
|
||||||
{% for mailbox in mailboxes %}
|
<option value="{{ mailbox.id }}" {% if mailbox.id == alias_info.mailbox.id %}
|
||||||
<option value="{{ mailbox.id }}" {% if mailbox.id == alias_info.mailbox.id %} selected {% endif %}>
|
selected {% endif %}>
|
||||||
{{ mailbox.email }}
|
{{ mailbox.email }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="">
|
|
||||||
<input type="hidden" name="form-name" value="set-mailbox">
|
|
||||||
<input type="hidden" name="alias-id" value="{{ alias.id }}">
|
|
||||||
|
|
||||||
<a data-alias="{{ alias.id }}"
|
|
||||||
class="save-mailbox btn btn-sm btn-outline-info w-100">
|
|
||||||
Update
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
|
<div class="">
|
||||||
|
<a data-alias="{{ alias.id }}"
|
||||||
|
class="save-mailbox btn btn-sm btn-outline-info w-100">
|
||||||
|
Update
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
{% elif alias_info.mailbox != None and alias_info.mailbox.email != current_user.email %}
|
{% elif alias_info.mailbox != None and alias_info.mailbox.email != current_user.email %}
|
||||||
<div class="small-text">
|
<div class="small-text">
|
||||||
Owned by <b>{{ alias_info.mailbox.email }}</b> mailbox
|
Owned by <b>{{ alias_info.mailbox.email }}</b> mailbox
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<form method="post">
|
<div class="d-flex mt-2">
|
||||||
<div class="d-flex mt-2">
|
<div class="flex-grow-1 mr-2">
|
||||||
|
<textarea
|
||||||
<div class="flex-grow-1 mr-2">
|
id="note-{{ alias.id }}"
|
||||||
<textarea
|
name="note"
|
||||||
id="note-{{ alias.id }}"
|
class="form-control"
|
||||||
name="note"
|
rows="2"
|
||||||
class="form-control"
|
placeholder="Alias Note.">{{ alias.note or "" }}</textarea>
|
||||||
rows="2"
|
|
||||||
placeholder="Alias Note.">{{ alias.note or "" }}</textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="">
|
|
||||||
<input type="hidden" name="form-name" value="set-note">
|
|
||||||
<input type="hidden" name="alias-id" value="{{ alias.id }}">
|
|
||||||
|
|
||||||
<a data-alias="{{ alias.id }}"
|
|
||||||
class="save-note btn btn-sm btn-outline-success w-100">
|
|
||||||
Save
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
|
<div class="">
|
||||||
|
<a data-alias="{{ alias.id }}"
|
||||||
|
class="save-note btn btn-sm btn-outline-success w-100">
|
||||||
|
Save
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
@ -409,22 +396,9 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".trigger-email").on("click", function (e) {
|
|
||||||
notie.confirm({
|
|
||||||
text: "SimpleLogin server will send an email to this alias " +
|
|
||||||
"and it will arrive to your inbox, please confirm.",
|
|
||||||
cancelCallback: () => {
|
|
||||||
// nothing to do
|
|
||||||
},
|
|
||||||
submitCallback: () => {
|
|
||||||
$(this).closest("form").submit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".custom-switch-input").change(async function (e) {
|
$(".custom-switch-input").change(async function (e) {
|
||||||
let aliasId = $(this).data("alias");
|
let aliasId = $(this).data("alias");
|
||||||
let alias = $(this).parent().find(".alias").val();
|
let alias = $(this).data("alias-email");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let res = await fetch(`/api/aliases/${aliasId}/toggle`, {
|
let res = await fetch(`/api/aliases/${aliasId}/toggle`, {
|
||||||
|
@ -474,7 +448,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
toastr.success(`Saved`);
|
toastr.success(`Note Saved`);
|
||||||
} else {
|
} else {
|
||||||
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
||||||
// reset to the original value
|
// reset to the original value
|
||||||
|
|
|
@ -33,19 +33,7 @@ def index():
|
||||||
|
|
||||||
# User generates a new email
|
# User generates a new email
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if request.form.get("form-name") == "trigger-email":
|
if request.form.get("form-name") == "create-custom-email":
|
||||||
alias_id = request.form.get("alias-id")
|
|
||||||
alias = Alias.get(alias_id)
|
|
||||||
|
|
||||||
LOG.d("trigger an email to %s", alias)
|
|
||||||
email_utils.send_test_email_alias(alias.email, alias.user.name)
|
|
||||||
|
|
||||||
flash(
|
|
||||||
f"An email sent to {alias.email} is on its way, please check your inbox/spam folder",
|
|
||||||
"success",
|
|
||||||
)
|
|
||||||
|
|
||||||
elif request.form.get("form-name") == "create-custom-email":
|
|
||||||
if current_user.can_create_new_alias():
|
if current_user.can_create_new_alias():
|
||||||
return redirect(url_for("dashboard.custom_alias"))
|
return redirect(url_for("dashboard.custom_alias"))
|
||||||
else:
|
else:
|
||||||
|
@ -69,36 +57,27 @@ def index():
|
||||||
|
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for(
|
url_for(
|
||||||
"dashboard.index", highlight_alias_id=alias.id, query=query,
|
"dashboard.index",
|
||||||
|
highlight_alias_id=alias.id,
|
||||||
|
query=query,
|
||||||
|
sort=sort,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
flash(f"You need to upgrade your plan to create new alias.", "warning")
|
flash(f"You need to upgrade your plan to create new alias.", "warning")
|
||||||
|
|
||||||
elif request.form.get("form-name") == "switch-email-forwarding":
|
|
||||||
alias_id = request.form.get("alias-id")
|
|
||||||
alias: Alias = Alias.get(alias_id)
|
|
||||||
|
|
||||||
LOG.d("switch email forwarding for %s", alias)
|
|
||||||
|
|
||||||
alias.enabled = not alias.enabled
|
|
||||||
if alias.enabled:
|
|
||||||
flash(f"Alias {alias.email} is enabled", "success")
|
|
||||||
else:
|
|
||||||
flash(f"Alias {alias.email} is disabled", "warning")
|
|
||||||
|
|
||||||
db.session.commit()
|
|
||||||
return redirect(
|
|
||||||
url_for("dashboard.index", highlight_alias_id=alias.id, query=query)
|
|
||||||
)
|
|
||||||
|
|
||||||
elif request.form.get("form-name") == "delete-email":
|
elif request.form.get("form-name") == "delete-email":
|
||||||
alias_id = request.form.get("alias-id")
|
alias_id = request.form.get("alias-id")
|
||||||
alias: Alias = Alias.get(alias_id)
|
alias: Alias = Alias.get(alias_id)
|
||||||
if not alias:
|
if not alias:
|
||||||
flash("Unknown error, sorry for the inconvenience", "error")
|
flash("Unknown error, sorry for the inconvenience", "error")
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for("dashboard.index", highlight_alias_id=alias.id, query=query)
|
url_for(
|
||||||
|
"dashboard.index",
|
||||||
|
highlight_alias_id=alias.id,
|
||||||
|
query=query,
|
||||||
|
sort=sort,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
LOG.d("delete gen email %s", alias)
|
LOG.d("delete gen email %s", alias)
|
||||||
|
@ -116,42 +95,7 @@ def index():
|
||||||
LOG.error("alias %s has been added before to DeletedAlias", email)
|
LOG.error("alias %s has been added before to DeletedAlias", email)
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
|
|
||||||
elif request.form.get("form-name") == "set-note":
|
return redirect(url_for("dashboard.index", query=query, sort=sort))
|
||||||
alias_id = request.form.get("alias-id")
|
|
||||||
alias: Alias = Alias.get(alias_id)
|
|
||||||
note = request.form.get("note")
|
|
||||||
|
|
||||||
alias.note = note
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
flash(f"Update note for alias {alias.email}", "success")
|
|
||||||
return redirect(
|
|
||||||
url_for("dashboard.index", highlight_alias_id=alias.id, query=query)
|
|
||||||
)
|
|
||||||
|
|
||||||
elif request.form.get("form-name") == "set-mailbox":
|
|
||||||
alias_id = request.form.get("alias-id")
|
|
||||||
alias: Alias = Alias.get(alias_id)
|
|
||||||
mailbox_email = request.form.get("mailbox")
|
|
||||||
|
|
||||||
mailbox = Mailbox.get_by(email=mailbox_email)
|
|
||||||
if not mailbox or mailbox.user_id != current_user.id:
|
|
||||||
flash("Something went wrong, please retry", "warning")
|
|
||||||
else:
|
|
||||||
alias.mailbox_id = mailbox.id
|
|
||||||
db.session.commit()
|
|
||||||
LOG.d("Set alias %s mailbox to %s", alias, mailbox)
|
|
||||||
|
|
||||||
flash(
|
|
||||||
f"Update mailbox for {alias.email} to {mailbox_email}", "success",
|
|
||||||
)
|
|
||||||
return redirect(
|
|
||||||
url_for(
|
|
||||||
"dashboard.index", highlight_alias_id=alias.id, query=query,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return redirect(url_for("dashboard.index", query=query))
|
|
||||||
|
|
||||||
client_users = (
|
client_users = (
|
||||||
ClientUser.filter_by(user_id=current_user.id)
|
ClientUser.filter_by(user_id=current_user.id)
|
||||||
|
|
Loading…
Reference in a new issue