let dbclient_rw = match data.pool_rw.get().await {
Ok(c) => c,
Err(e) => {
log::error!("Pool RW error {}", e);
return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
}
};
let stmt = match dbclient_rw
.prepare("insert into auth.reset_tokens values ($1, $2, NULL, NOW(), NULL);")
.await
{
Ok(stmt) => stmt,
Err(e) => {
log::error!("Pool RW statement error {}", e);
return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
}
};
let token = Uuid::new_v4();
let inserted = match dbclient_rw.execute(&stmt, &[&form.login, &token]).await {
Ok(c) => c,
Err(e) => {
log::error!("Pool RW execute insert error {}", e);
return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
}
};
if inserted == 0 {
log::error!("Pool RW execute insert row error");
return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
}
let token_url = format!("{}reset-game-pwd-{}.html", data.base_url, token);
log::info!(
"Sending {} type {} to {}",
token_url,
form.contact_type,
form.login
);