feat: resend registration email
This commit is contained in:
parent
da0679b93e
commit
00f8b0693f
14
.sqlx/query-5c492ff7ad44ae4876bae9b9ba947d12ad03cda345ba6d1120e38081fdb1fa06.json
generated
Normal file
14
.sqlx/query-5c492ff7ad44ae4876bae9b9ba947d12ad03cda345ba6d1120e38081fdb1fa06.json
generated
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM registration WHERE userId = $1;",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int4"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "5c492ff7ad44ae4876bae9b9ba947d12ad03cda345ba6d1120e38081fdb1fa06"
|
||||
}
|
@ -48,6 +48,7 @@ pub fn init(cfg: &mut ServiceConfig) {
|
||||
cfg.service(user::post_changepassword::post);
|
||||
cfg.service(user::get_register::get);
|
||||
cfg.service(user::post_register::post);
|
||||
cfg.service(user::post_resend_registration::post);
|
||||
|
||||
cfg.service(availability::delete::delete);
|
||||
cfg.service(availability::get_new::get);
|
||||
|
@ -28,6 +28,7 @@ pub mod post_new;
|
||||
pub mod post_register;
|
||||
pub mod post_reset;
|
||||
pub mod post_toggle;
|
||||
pub mod post_resend_registration;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "user/new_or_edit.html")]
|
||||
|
42
web/src/endpoints/user/post_resend_registration.rs
Normal file
42
web/src/endpoints/user/post_resend_registration.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::{
|
||||
endpoints::IdPath,
|
||||
mail::Mailer,
|
||||
models::{Registration, Role, User},
|
||||
utils::ApplicationError,
|
||||
};
|
||||
|
||||
#[actix_web::post("/users/{id}/resend-registration")]
|
||||
pub async fn post(
|
||||
user: web::ReqData<User>,
|
||||
pool: web::Data<PgPool>,
|
||||
path: web::Path<IdPath>,
|
||||
mailer: web::Data<Mailer>,
|
||||
) -> Result<impl Responder, ApplicationError> {
|
||||
if user.role != Role::AreaManager && user.role != Role::Admin {
|
||||
return Err(ApplicationError::Unauthorized);
|
||||
}
|
||||
|
||||
let Some(user_in_db) = User::read_by_id(pool.get_ref(), path.id).await? else {
|
||||
return Ok(HttpResponse::NotFound().finish());
|
||||
};
|
||||
|
||||
if user.role == Role::AreaManager && user.area_id != user_in_db.area_id {
|
||||
return Err(ApplicationError::Unauthorized);
|
||||
}
|
||||
|
||||
if user_in_db.password.is_some() || user_in_db.salt.is_some() || user_in_db.last_login.is_some()
|
||||
{
|
||||
return Ok(HttpResponse::BadRequest().finish());
|
||||
}
|
||||
|
||||
Registration::delete_all_for_user(pool.get_ref(), user_in_db.id).await?;
|
||||
let registration = Registration::insert_new_for_user(pool.get_ref(), user_in_db.id).await?;
|
||||
mailer
|
||||
.send_registration_mail(&user_in_db, ®istration.token)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().finish())
|
||||
}
|
@ -45,6 +45,14 @@ impl Registration {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_all_for_user(pool: &PgPool, user_id: i32) -> Result<()> {
|
||||
sqlx::query!("DELETE FROM registration WHERE userId = $1;", user_id)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Token for Registration {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
{% block content %}
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<div class="container is-fluid">
|
||||
<div class="level">
|
||||
<div class="level-left">
|
||||
<h3 class="title is-3">
|
||||
@ -110,6 +110,14 @@
|
||||
</svg>
|
||||
<span>Löschen</span>
|
||||
</button>
|
||||
{% if u.password.is_none() && u.salt.is_none() && u.last_login.is_none() %}
|
||||
<button class="button is-warning is-light" hx-post="/users/{{ u.id }}/resend-registration">
|
||||
<svg class="icon">
|
||||
<use href="/static/feather-sprite.svg#send" />
|
||||
</svg>
|
||||
<span>Registrierungsmail erneut senden</span>
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user