mirror of
https://git.42l.fr/neil/sncf.git
synced 2024-05-25 11:52:14 +02:00
now using database pool for db. Fixes #21
This commit is contained in:
parent
f07c8f960f
commit
6760517c70
|
@ -9,12 +9,12 @@ use crate::DbConn;
|
|||
|
||||
#[table_name = "form"]
|
||||
#[derive(Serialize, Insertable)]
|
||||
pub struct InsertableForm<'b> {
|
||||
pub struct InsertableForm {
|
||||
pub created_at: NaiveDateTime,
|
||||
pub lastvisit_at: NaiveDateTime,
|
||||
pub token: &'b str,
|
||||
pub nc_username: &'b str,
|
||||
pub nc_password: &'b str,
|
||||
pub token: String,
|
||||
pub nc_username: String,
|
||||
pub nc_password: String,
|
||||
}
|
||||
|
||||
impl Form {
|
||||
|
@ -45,9 +45,9 @@ impl Form {
|
|||
}
|
||||
|
||||
pub fn insert<'b>(
|
||||
i_form: InsertableForm<'b>,
|
||||
i_form: InsertableForm,
|
||||
conn: &DbConn,
|
||||
) -> Result<InsertableForm<'b>, diesel::result::Error> {
|
||||
) -> Result<InsertableForm, diesel::result::Error> {
|
||||
match diesel::insert_into(form).values(&i_form).execute(conn) {
|
||||
Ok(_) => Ok(i_form),
|
||||
Err(e) => Err(e),
|
||||
|
|
|
@ -156,7 +156,8 @@ pub async fn forward_login(
|
|||
})?;
|
||||
|
||||
// check if the link exists in DB. if it does, update lastvisit_at.
|
||||
let formdata = Form::get_from_token(¶ms.token, &conn)
|
||||
let formdata = web::block(move || Form::get_from_token(¶ms.token, &conn))
|
||||
.await
|
||||
.map_err(|e| {
|
||||
eprintln!("error_forwardlogin_db_get (diesel error): {}", e);
|
||||
crash(get_lang(&req), "error_forwardlogin_db_get")
|
||||
|
@ -237,17 +238,20 @@ pub async fn forward_register(
|
|||
|
||||
let token = gen_token(45);
|
||||
|
||||
let token_mv = token.clone();
|
||||
|
||||
// store the result in DB
|
||||
let form_result = Form::insert(
|
||||
let form_result = web::block(move || Form::insert(
|
||||
InsertableForm {
|
||||
created_at: Utc::now().naive_utc(),
|
||||
lastvisit_at: Utc::now().naive_utc(),
|
||||
token: &token,
|
||||
nc_username: &nc_username,
|
||||
nc_password: &nc_password,
|
||||
token: token_mv,
|
||||
nc_username,
|
||||
nc_password,
|
||||
},
|
||||
&conn,
|
||||
);
|
||||
))
|
||||
.await;
|
||||
|
||||
if form_result.is_err() {
|
||||
return Err(crash(lang, "error_forwardregister_db"));
|
||||
|
|
Loading…
Reference in a new issue