Finish authentication (#659)

This commit is contained in:
Geometrically
2023-07-18 15:02:54 -07:00
committed by GitHub
parent ec80c2b9db
commit 4bb47d7e01
10 changed files with 217 additions and 75 deletions

View File

@@ -182,7 +182,7 @@ pub struct ReportTypeId(pub i32);
#[sqlx(transparent)]
pub struct FileId(pub i64);
#[derive(Copy, Clone, Debug, Type, Deserialize, Serialize)]
#[derive(Copy, Clone, Debug, Type, Deserialize, Serialize, Eq, PartialEq, Hash)]
#[sqlx(transparent)]
pub struct PatId(pub i64);
@@ -200,7 +200,7 @@ pub struct ThreadId(pub i64);
#[sqlx(transparent)]
pub struct ThreadMessageId(pub i64);
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize, Eq, PartialEq, Hash)]
#[sqlx(transparent)]
pub struct SessionId(pub i64);

View File

@@ -146,7 +146,7 @@ impl PersonalAccessToken {
}
if !remaining_strings.is_empty() {
let pat_ids_parsed: Vec<i64> = pat_strings
let pat_ids_parsed: Vec<i64> = remaining_strings
.iter()
.flat_map(|x| parse_base62(&x.to_string()).ok())
.map(|x| x as i64)
@@ -159,7 +159,7 @@ impl PersonalAccessToken {
ORDER BY created DESC
",
&pat_ids_parsed,
&pat_strings
&remaining_strings
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>(),
@@ -214,8 +214,9 @@ impl PersonalAccessToken {
let mut redis = redis.get().await?;
let res = cmd("GET")
.arg(format!("{}:{}", PATS_USERS_NAMESPACE, user_id.0))
.query_async::<_, Option<Vec<i64>>>(&mut redis)
.await?;
.query_async::<_, Option<String>>(&mut redis)
.await?
.and_then(|x| serde_json::from_str::<Vec<i64>>(&x).ok());
if let Some(res) = res {
return Ok(res.into_iter().map(PatId).collect());
@@ -251,6 +252,10 @@ impl PersonalAccessToken {
clear_pats: Vec<(Option<PatId>, Option<String>, Option<UserId>)>,
redis: &deadpool_redis::Pool,
) -> Result<(), DatabaseError> {
if clear_pats.is_empty() {
return Ok(());
}
let mut redis = redis.get().await?;
let mut cmd = cmd("DEL");

View File

@@ -187,7 +187,7 @@ impl Session {
}
if !remaining_strings.is_empty() {
let session_ids_parsed: Vec<i64> = session_strings
let session_ids_parsed: Vec<i64> = remaining_strings
.iter()
.flat_map(|x| parse_base62(&x.to_string()).ok())
.map(|x| x as i64)
@@ -201,7 +201,7 @@ impl Session {
ORDER BY created DESC
",
&session_ids_parsed,
&session_strings.into_iter().map(|x| x.to_string()).collect::<Vec<_>>(),
&remaining_strings.into_iter().map(|x| x.to_string()).collect::<Vec<_>>(),
)
.fetch_many(exec)
.try_filter_map(|e| async {
@@ -258,8 +258,9 @@ impl Session {
let mut redis = redis.get().await?;
let res = cmd("GET")
.arg(format!("{}:{}", SESSIONS_USERS_NAMESPACE, user_id.0))
.query_async::<_, Option<Vec<i64>>>(&mut redis)
.await?;
.query_async::<_, Option<String>>(&mut redis)
.await?
.and_then(|x| serde_json::from_str::<Vec<i64>>(&x).ok());
if let Some(res) = res {
return Ok(res.into_iter().map(SessionId).collect());
@@ -295,6 +296,10 @@ impl Session {
clear_sessions: Vec<(Option<SessionId>, Option<String>, Option<UserId>)>,
redis: &deadpool_redis::Pool,
) -> Result<(), DatabaseError> {
if clear_sessions.is_empty() {
return Ok(());
}
let mut redis = redis.get().await?;
let mut cmd = cmd("DEL");