Fix mail_domain from the server
This commit is contained in:
parent
e8e9e9df8c
commit
1563a1aea0
2 changed files with 44 additions and 26 deletions
20
src/main.rs
20
src/main.rs
|
|
@ -732,10 +732,12 @@ async fn add_mail(
|
||||||
User(user): User,
|
User(user): User,
|
||||||
Form(add): Form<Mail>,
|
Form(add): Form<Mail>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let mail = format!("{}@{}", add.mail, state.mail_domain);
|
||||||
|
|
||||||
let has_mail = sqlx::query!(
|
let has_mail = sqlx::query!(
|
||||||
"SELECT COUNT(*) FROM emails WHERE id != $1 AND mail = $2",
|
"SELECT COUNT(*) FROM emails WHERE id != $1 AND mail = $2",
|
||||||
user,
|
user,
|
||||||
add.mail
|
mail
|
||||||
)
|
)
|
||||||
.fetch_one(&state.db)
|
.fetch_one(&state.db)
|
||||||
.await?
|
.await?
|
||||||
|
|
@ -748,7 +750,7 @@ async fn add_mail(
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'primary') ON CONFLICT DO NOTHING",
|
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'primary') ON CONFLICT DO NOTHING",
|
||||||
user,
|
user,
|
||||||
add.mail
|
mail
|
||||||
)
|
)
|
||||||
.execute(&state.db)
|
.execute(&state.db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -762,10 +764,12 @@ async fn add_list(
|
||||||
User(user): User,
|
User(user): User,
|
||||||
Form(add): Form<Mail>,
|
Form(add): Form<Mail>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let mail = format!("{}@{}", add.mail, state.mail_domain);
|
||||||
|
|
||||||
let has_mail = sqlx::query!(
|
let has_mail = sqlx::query!(
|
||||||
"SELECT COUNT(*) FROM emails WHERE id != $1 AND mail = $2",
|
"SELECT COUNT(*) FROM emails WHERE id != $1 AND mail = $2",
|
||||||
user,
|
user,
|
||||||
add.mail
|
mail
|
||||||
)
|
)
|
||||||
.fetch_one(&state.db)
|
.fetch_one(&state.db)
|
||||||
.await?
|
.await?
|
||||||
|
|
@ -778,7 +782,7 @@ async fn add_list(
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'list') ON CONFLICT DO NOTHING",
|
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'list') ON CONFLICT DO NOTHING",
|
||||||
user,
|
user,
|
||||||
add.mail
|
mail
|
||||||
)
|
)
|
||||||
.execute(&state.db)
|
.execute(&state.db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -871,6 +875,8 @@ async fn alias_add(
|
||||||
User(user): User,
|
User(user): User,
|
||||||
Form(alias): Form<NewAlias>,
|
Form(alias): Form<NewAlias>,
|
||||||
) -> Result<Redirect, Error> {
|
) -> Result<Redirect, Error> {
|
||||||
|
let alias_email = format!("{}@{}", alias.alias, state.mail_domain);
|
||||||
|
|
||||||
let mut tx = state.db.begin().await?;
|
let mut tx = state.db.begin().await?;
|
||||||
|
|
||||||
let can_use_mail = sqlx::query!(
|
let can_use_mail = sqlx::query!(
|
||||||
|
|
@ -888,7 +894,7 @@ async fn alias_add(
|
||||||
return Ok(UserError::UnauthorizedAliasDest(alias.mail).into());
|
return Ok(UserError::UnauthorizedAliasDest(alias.mail).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let has_mail = sqlx::query!("SELECT COUNT(*) FROM emails WHERE mail = $1", alias.alias)
|
let has_mail = sqlx::query!("SELECT COUNT(*) FROM emails WHERE mail = $1", alias_email)
|
||||||
.fetch_one(&mut *tx)
|
.fetch_one(&mut *tx)
|
||||||
.await?
|
.await?
|
||||||
.count
|
.count
|
||||||
|
|
@ -901,14 +907,14 @@ async fn alias_add(
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'alias') ON CONFLICT DO NOTHING",
|
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'alias') ON CONFLICT DO NOTHING",
|
||||||
user,
|
user,
|
||||||
alias.alias
|
alias_email
|
||||||
)
|
)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO alias (alias, type, dest) VALUES ($1, 'alias', $2) ON CONFLICT DO NOTHING",
|
"INSERT INTO alias (alias, type, dest) VALUES ($1, 'alias', $2) ON CONFLICT DO NOTHING",
|
||||||
alias.alias,
|
alias_email,
|
||||||
alias.mail
|
alias.mail
|
||||||
)
|
)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endmacro delete_modal %}
|
{% endmacro delete_modal %}
|
||||||
{% macro add_modal(modal_id, add_button, add_text, action, payload, button_classes, input_name, prefill=false) %}
|
{% macro add_modal(modal_id, add_button, add_text, action, payload, button_classes, input_name, fixed_domain=false) %}
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="btn btn-primary {{ button_classes }}"
|
class="btn btn-primary {{ button_classes }}"
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
|
|
@ -65,15 +65,26 @@
|
||||||
name="{{ payload | nth(n=idx*2) }}"
|
name="{{ payload | nth(n=idx*2) }}"
|
||||||
value="{{ payload | nth(n=idx*2 + 1) }}" />
|
value="{{ payload | nth(n=idx*2 + 1) }}" />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<div class="form-floating mb-3">
|
{% if fixed_domain %}
|
||||||
<input type="email"
|
<div class="input-group">
|
||||||
class="form-control"
|
<input type="text"
|
||||||
id="{{ modal_id }}Input"
|
class="form-control"
|
||||||
{% if prefill %} placeholder="mail@{{ mail_domain }}" {% else %} placeholder="mail@example.com" {% endif %}
|
placeholder="Mail"
|
||||||
name="{{ input_name }}"
|
aria-label="Mail"
|
||||||
{% if prefill %}value="@{{ mail_domain }}"{% endif %}>
|
aria-describedby="{{ modal_id }}Label"
|
||||||
<label for="{{ modal_id }}Input">Email address</label>
|
name="{{ input_name }}" />
|
||||||
</div>
|
<span class="input-group-text" id="{{ modal_id }}Label">@{{ mail_domain }}</span>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="form-floating mb-3">
|
||||||
|
<input type="email"
|
||||||
|
class="form-control"
|
||||||
|
id="{{ modal_id }}Input"
|
||||||
|
placeholder="mail@example.com"
|
||||||
|
name="{{ input_name }}" />
|
||||||
|
<label for="{{ modal_id }}Input">Email address</label>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|
@ -125,10 +136,10 @@
|
||||||
payload=["mail", mail.primary])
|
payload=["mail", mail.primary])
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
<h3>Aliases</h3>
|
<h3>Aliases</h3>
|
||||||
<ul class="list-group mt-1">
|
<ul class="list-group mt-1">
|
||||||
{% set alias_idx = loop.index %}
|
{% set alias_idx = loop.index %}
|
||||||
{% for alias in mail.aliases %}
|
{% for alias in mail.aliases %}
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
{{ alias }}
|
{{ alias }}
|
||||||
{{ self::delete_modal(modal_id="aliasDelete" ~ alias_idx ~ loop.index,
|
{{ self::delete_modal(modal_id="aliasDelete" ~ alias_idx ~ loop.index,
|
||||||
|
|
@ -137,16 +148,17 @@
|
||||||
payload=["mail", alias])
|
payload=["mail", alias])
|
||||||
}}
|
}}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{{ self::add_modal(modal_id="addAlias" ~ loop.index,
|
{{ self::add_modal(modal_id="addAlias" ~ loop.index,
|
||||||
add_button="Add Alias",
|
add_button="Add Alias",
|
||||||
button_classes="mt-2 w-25",
|
button_classes="mt-2 w-25",
|
||||||
add_text="Add a alias",
|
add_text="Add a alias",
|
||||||
action="/alias/add",
|
action="/alias/add",
|
||||||
input_name="alias",
|
input_name="alias",
|
||||||
payload=["mail", mail.primary])
|
payload=["mail", mail.primary],
|
||||||
}}
|
fixed_domain=true)
|
||||||
|
}}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
@ -157,7 +169,7 @@
|
||||||
action="/mail/add",
|
action="/mail/add",
|
||||||
input_name="mail",
|
input_name="mail",
|
||||||
payload=[],
|
payload=[],
|
||||||
prefill=true)
|
fixed_domain=true)
|
||||||
}}
|
}}
|
||||||
<h2 class="title is-2 mt-2">Lists</h2>
|
<h2 class="title is-2 mt-2">Lists</h2>
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
|
|
@ -203,7 +215,7 @@
|
||||||
action="/list/add",
|
action="/list/add",
|
||||||
input_name="mail",
|
input_name="mail",
|
||||||
payload=[],
|
payload=[],
|
||||||
prefill=true)
|
fixed_domain=true)
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue