login: Update last_login_at timestamp
This commit is contained in:
parent
ff55d1f254
commit
8d7e7b9004
15
.sqlx/query-0d211d66bd0e769d095f83e529c2b5a356289b8ed220e569336a4f5909c4ba9d.json
generated
Normal file
15
.sqlx/query-0d211d66bd0e769d095f83e529c2b5a356289b8ed220e569336a4f5909c4ba9d.json
generated
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "UPDATE users SET last_login_utc = $1 WHERE user_id = $2",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Timestamp",
|
||||||
|
"Uuid"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "0d211d66bd0e769d095f83e529c2b5a356289b8ed220e569336a4f5909c4ba9d"
|
||||||
|
}
|
@ -1,16 +1,17 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "INSERT INTO login_sessions (login_session_token_hash, user_id, started_at_utc, xsrf_secret)\n VALUES ($1, $2, NOW(), $3)",
|
"query": "INSERT INTO login_sessions (login_session_token_hash, user_id, started_at_utc, xsrf_secret)\n VALUES ($1, $2, $3, $4)",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Left": [
|
"Left": [
|
||||||
"Bytea",
|
"Bytea",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
|
"Timestamp",
|
||||||
"Bytea"
|
"Bytea"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "cfc3e3102493b5b385bcab8eb8d4ea73d38cfb32cdf5c34b6cc76738669490fd"
|
"hash": "d3ca3c38b26b5ab49a027ada2e3973adcd81f3333de2f06f6bf848d08902bee9"
|
||||||
}
|
}
|
15
src/store.rs
15
src/store.rs
@ -312,15 +312,26 @@ impl IdCoopStoreTxn<'_, '_> {
|
|||||||
login_session_token_hash: &[u8; LOGIN_SESSION_TOKEN_HASH_BYTES],
|
login_session_token_hash: &[u8; LOGIN_SESSION_TOKEN_HASH_BYTES],
|
||||||
user_id: Uuid,
|
user_id: Uuid,
|
||||||
xsrf_secret: &[u8; LOGIN_SESSION_XSRF_SECRET_BYTES],
|
xsrf_secret: &[u8; LOGIN_SESSION_XSRF_SECRET_BYTES],
|
||||||
|
now: DateTime<Utc>,
|
||||||
) -> eyre::Result<()> {
|
) -> eyre::Result<()> {
|
||||||
|
let now = now.naive_utc();
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO login_sessions (login_session_token_hash, user_id, started_at_utc, xsrf_secret)
|
"INSERT INTO login_sessions (login_session_token_hash, user_id, started_at_utc, xsrf_secret)
|
||||||
VALUES ($1, $2, NOW(), $3)",
|
VALUES ($1, $2, $3, $4)",
|
||||||
login_session_token_hash, user_id, xsrf_secret
|
login_session_token_hash, user_id, now, xsrf_secret
|
||||||
)
|
)
|
||||||
.execute(&mut **self.txn)
|
.execute(&mut **self.txn)
|
||||||
.await
|
.await
|
||||||
.context("failed to create login session")?;
|
.context("failed to create login session")?;
|
||||||
|
sqlx::query!(
|
||||||
|
"UPDATE users SET last_login_utc = $1 WHERE user_id = $2",
|
||||||
|
now,
|
||||||
|
user_id
|
||||||
|
)
|
||||||
|
.execute(&mut **self.txn)
|
||||||
|
.await
|
||||||
|
.context("failed to bump login time")?;
|
||||||
|
//
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ use crate::{
|
|||||||
config::{Configuration, PasswordHashingConfig},
|
config::{Configuration, PasswordHashingConfig},
|
||||||
passwords::{check_hash, create_password_hash},
|
passwords::{check_hash, create_password_hash},
|
||||||
store::IdCoopStore,
|
store::IdCoopStore,
|
||||||
utils::RandGen,
|
utils::{Clock, RandGen},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@ -361,6 +361,7 @@ pub(crate) async fn post_login(
|
|||||||
SecureClientIp(src_ip): SecureClientIp,
|
SecureClientIp(src_ip): SecureClientIp,
|
||||||
Extension(ratelimiters): Extension<Arc<Ratelimiters>>,
|
Extension(ratelimiters): Extension<Arc<Ratelimiters>>,
|
||||||
Extension(mut randgen): Extension<RandGen>,
|
Extension(mut randgen): Extension<RandGen>,
|
||||||
|
Extension(clock): Extension<Clock>,
|
||||||
DesiredLocale(locale): DesiredLocale,
|
DesiredLocale(locale): DesiredLocale,
|
||||||
ambient: Ambient,
|
ambient: Ambient,
|
||||||
Form(form_raw): Form<LoginFormRaw>,
|
Form(form_raw): Form<LoginFormRaw>,
|
||||||
@ -491,7 +492,12 @@ pub(crate) async fn post_login(
|
|||||||
store
|
store
|
||||||
.txn(|mut txn| {
|
.txn(|mut txn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
txn.create_login_session(&login_session_token_hash, user.user_id, &xsrf_secret)
|
txn.create_login_session(
|
||||||
|
&login_session_token_hash,
|
||||||
|
user.user_id,
|
||||||
|
&xsrf_secret,
|
||||||
|
clock.now_utc(),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user