1
0
Fork 0
mirror of https://git.42l.fr/neil/sncf.git synced 2024-04-25 02:50:27 +02:00

now using database pool for db. Fixes #21

This commit is contained in:
neil 2020-11-03 17:02:03 +01:00
parent f07c8f960f
commit 6760517c70
2 changed files with 16 additions and 12 deletions

View file

@ -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),

View file

@ -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(&params.token, &conn)
let formdata = web::block(move || Form::get_from_token(&params.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"));