Merge pull request #136 from simple-login/refactor
Refactor: remove unused POST
This commit is contained in:
commit
c8ed1437f1
|
@ -110,9 +110,6 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="col text-right">
|
||||
<form method="post">
|
||||
<input type="hidden" name="form-name" value="switch-email-forwarding">
|
||||
<input type="hidden" name="alias-id" value="{{ alias.id }}">
|
||||
<label class="custom-switch cursor"
|
||||
data-toggle="tooltip"
|
||||
{% if alias.enabled %}
|
||||
|
@ -131,13 +128,13 @@
|
|||
{% endif %}
|
||||
style="padding-left: 0px"
|
||||
>
|
||||
<input type="hidden" name="alias" class="alias" value="{{ alias.email }}">
|
||||
<input type="checkbox" class="custom-switch-input" data-alias="{{ alias.id }}"
|
||||
<input type="checkbox" class="custom-switch-input"
|
||||
data-alias="{{ alias.id }}"
|
||||
data-alias-email="{{ alias.email }}"
|
||||
{{ "checked" if alias.enabled else "" }}>
|
||||
|
||||
<span class="custom-switch-indicator"></span>
|
||||
</label>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -218,14 +215,14 @@
|
|||
<div class="collapse" id="alias-{{ alias.id }}">
|
||||
|
||||
{% if mailboxes|length > 1 %}
|
||||
<form method="post">
|
||||
<div class="small-text mt-2">Current mailbox</div>
|
||||
<div class="d-flex">
|
||||
<div class="flex-grow-1 mr-2">
|
||||
<select id="mailbox-{{ alias.id }}"
|
||||
class="form-control form-control-sm custom-select" name="mailbox">
|
||||
{% for mailbox in mailboxes %}
|
||||
<option value="{{ mailbox.id }}" {% if mailbox.id == alias_info.mailbox.id %} selected {% endif %}>
|
||||
<option value="{{ mailbox.id }}" {% if mailbox.id == alias_info.mailbox.id %}
|
||||
selected {% endif %}>
|
||||
{{ mailbox.email }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
|
@ -233,9 +230,6 @@
|
|||
</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
|
||||
|
@ -243,16 +237,13 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
{% elif alias_info.mailbox != None and alias_info.mailbox.email != current_user.email %}
|
||||
<div class="small-text">
|
||||
Owned by <b>{{ alias_info.mailbox.email }}</b> mailbox
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="post">
|
||||
<div class="d-flex mt-2">
|
||||
|
||||
<div class="flex-grow-1 mr-2">
|
||||
<textarea
|
||||
id="note-{{ alias.id }}"
|
||||
|
@ -263,16 +254,12 @@
|
|||
</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>
|
||||
</form>
|
||||
|
||||
<div class="row mt-3">
|
||||
<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) {
|
||||
let aliasId = $(this).data("alias");
|
||||
let alias = $(this).parent().find(".alias").val();
|
||||
let alias = $(this).data("alias-email");
|
||||
|
||||
try {
|
||||
let res = await fetch(`/api/aliases/${aliasId}/toggle`, {
|
||||
|
@ -474,7 +448,7 @@
|
|||
});
|
||||
|
||||
if (res.ok) {
|
||||
toastr.success(`Saved`);
|
||||
toastr.success(`Note Saved`);
|
||||
} else {
|
||||
toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
|
||||
// reset to the original value
|
||||
|
|
|
@ -33,19 +33,7 @@ def index():
|
|||
|
||||
# User generates a new email
|
||||
if request.method == "POST":
|
||||
if request.form.get("form-name") == "trigger-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 request.form.get("form-name") == "create-custom-email":
|
||||
if current_user.can_create_new_alias():
|
||||
return redirect(url_for("dashboard.custom_alias"))
|
||||
else:
|
||||
|
@ -69,36 +57,27 @@ def index():
|
|||
|
||||
return redirect(
|
||||
url_for(
|
||||
"dashboard.index", highlight_alias_id=alias.id, query=query,
|
||||
"dashboard.index",
|
||||
highlight_alias_id=alias.id,
|
||||
query=query,
|
||||
sort=sort,
|
||||
)
|
||||
)
|
||||
else:
|
||||
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":
|
||||
alias_id = request.form.get("alias-id")
|
||||
alias: Alias = Alias.get(alias_id)
|
||||
if not alias:
|
||||
flash("Unknown error, sorry for the inconvenience", "error")
|
||||
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)
|
||||
|
@ -116,42 +95,7 @@ def index():
|
|||
LOG.error("alias %s has been added before to DeletedAlias", email)
|
||||
db.session.rollback()
|
||||
|
||||
elif request.form.get("form-name") == "set-note":
|
||||
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))
|
||||
return redirect(url_for("dashboard.index", query=query, sort=sort))
|
||||
|
||||
client_users = (
|
||||
ClientUser.filter_by(user_id=current_user.id)
|
||||
|
|
Loading…
Reference in a new issue