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,
|
||||
Form(add): Form<Mail>,
|
||||
) -> Result<Redirect, Error> {
|
||||
let mail = format!("{}@{}", add.mail, state.mail_domain);
|
||||
|
||||
let has_mail = sqlx::query!(
|
||||
"SELECT COUNT(*) FROM emails WHERE id != $1 AND mail = $2",
|
||||
user,
|
||||
add.mail
|
||||
mail
|
||||
)
|
||||
.fetch_one(&state.db)
|
||||
.await?
|
||||
|
|
@ -748,7 +750,7 @@ async fn add_mail(
|
|||
sqlx::query!(
|
||||
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'primary') ON CONFLICT DO NOTHING",
|
||||
user,
|
||||
add.mail
|
||||
mail
|
||||
)
|
||||
.execute(&state.db)
|
||||
.await?;
|
||||
|
|
@ -762,10 +764,12 @@ async fn add_list(
|
|||
User(user): User,
|
||||
Form(add): Form<Mail>,
|
||||
) -> Result<Redirect, Error> {
|
||||
let mail = format!("{}@{}", add.mail, state.mail_domain);
|
||||
|
||||
let has_mail = sqlx::query!(
|
||||
"SELECT COUNT(*) FROM emails WHERE id != $1 AND mail = $2",
|
||||
user,
|
||||
add.mail
|
||||
mail
|
||||
)
|
||||
.fetch_one(&state.db)
|
||||
.await?
|
||||
|
|
@ -778,7 +782,7 @@ async fn add_list(
|
|||
sqlx::query!(
|
||||
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'list') ON CONFLICT DO NOTHING",
|
||||
user,
|
||||
add.mail
|
||||
mail
|
||||
)
|
||||
.execute(&state.db)
|
||||
.await?;
|
||||
|
|
@ -871,6 +875,8 @@ async fn alias_add(
|
|||
User(user): User,
|
||||
Form(alias): Form<NewAlias>,
|
||||
) -> Result<Redirect, Error> {
|
||||
let alias_email = format!("{}@{}", alias.alias, state.mail_domain);
|
||||
|
||||
let mut tx = state.db.begin().await?;
|
||||
|
||||
let can_use_mail = sqlx::query!(
|
||||
|
|
@ -888,7 +894,7 @@ async fn alias_add(
|
|||
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)
|
||||
.await?
|
||||
.count
|
||||
|
|
@ -901,14 +907,14 @@ async fn alias_add(
|
|||
sqlx::query!(
|
||||
"INSERT INTO emails (id, mail, type) VALUES ($1, $2, 'alias') ON CONFLICT DO NOTHING",
|
||||
user,
|
||||
alias.alias
|
||||
alias_email
|
||||
)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"INSERT INTO alias (alias, type, dest) VALUES ($1, 'alias', $2) ON CONFLICT DO NOTHING",
|
||||
alias.alias,
|
||||
alias_email,
|
||||
alias.mail
|
||||
)
|
||||
.execute(&mut *tx)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{% 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"
|
||||
class="btn btn-primary {{ button_classes }}"
|
||||
data-bs-toggle="modal"
|
||||
|
|
@ -65,15 +65,26 @@
|
|||
name="{{ payload | nth(n=idx*2) }}"
|
||||
value="{{ payload | nth(n=idx*2 + 1) }}" />
|
||||
{% endfor %}
|
||||
{% if fixed_domain %}
|
||||
<div class="input-group">
|
||||
<input type="text"
|
||||
class="form-control"
|
||||
placeholder="Mail"
|
||||
aria-label="Mail"
|
||||
aria-describedby="{{ modal_id }}Label"
|
||||
name="{{ input_name }}" />
|
||||
<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"
|
||||
{% if prefill %} placeholder="mail@{{ mail_domain }}" {% else %} placeholder="mail@example.com" {% endif %}
|
||||
name="{{ input_name }}"
|
||||
{% if prefill %}value="@{{ mail_domain }}"{% endif %}>
|
||||
placeholder="mail@example.com"
|
||||
name="{{ input_name }}" />
|
||||
<label for="{{ modal_id }}Input">Email address</label>
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
|
@ -145,7 +156,8 @@
|
|||
add_text="Add a alias",
|
||||
action="/alias/add",
|
||||
input_name="alias",
|
||||
payload=["mail", mail.primary])
|
||||
payload=["mail", mail.primary],
|
||||
fixed_domain=true)
|
||||
}}
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
@ -157,7 +169,7 @@
|
|||
action="/mail/add",
|
||||
input_name="mail",
|
||||
payload=[],
|
||||
prefill=true)
|
||||
fixed_domain=true)
|
||||
}}
|
||||
<h2 class="title is-2 mt-2">Lists</h2>
|
||||
<ul class="list-group">
|
||||
|
|
@ -203,7 +215,7 @@
|
|||
action="/list/add",
|
||||
input_name="mail",
|
||||
payload=[],
|
||||
prefill=true)
|
||||
fixed_domain=true)
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue