1 parent
0421994fe6
commit
425ea7449b
138 files changed
+5705
-1012
No files matched your search
+38
-28
@@ -7,7 +7,7 @@ use axum::{Extension, Json};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::auth::imap_auth::{self, AuthResult};
|
||||
use crate::auth::session::{SessionState, SessionStore};
|
||||
use crate::auth::session::{NewAccountSession, SessionState, SessionStore};
|
||||
use crate::auth::user_data;
|
||||
use crate::config::AppConfig;
|
||||
use crate::db;
|
||||
@@ -208,7 +208,7 @@ pub async fn login(
|
||||
.or_else(|| extract_browser_id(&headers));
|
||||
|
||||
if let Some(ref browser_id) = provided_browser_id {
|
||||
let existing_accounts = store.get_browser_accounts(browser_id);
|
||||
let existing_accounts = store.get_browser_accounts_shared(browser_id).await;
|
||||
let duplicate = existing_accounts
|
||||
.iter()
|
||||
.find(|a| a.email == body.email && a.imap_host == imap_host);
|
||||
@@ -308,26 +308,30 @@ pub async fn login(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let (token, account_id) = store.add_account_to_browser_with_timeout(
|
||||
&browser_id,
|
||||
body.email.clone(),
|
||||
body.password,
|
||||
user_hash,
|
||||
imap_host.clone(),
|
||||
imap_port,
|
||||
imap_tls,
|
||||
smtp_host.clone(),
|
||||
smtp_port,
|
||||
smtp_tls,
|
||||
timeout_override,
|
||||
);
|
||||
let (token, account_id) = store
|
||||
.add_account_to_browser_shared(
|
||||
&browser_id,
|
||||
NewAccountSession {
|
||||
email: body.email.clone(),
|
||||
password: body.password,
|
||||
user_hash,
|
||||
imap_host: imap_host.clone(),
|
||||
imap_port,
|
||||
imap_tls,
|
||||
smtp_host: smtp_host.clone(),
|
||||
smtp_port,
|
||||
smtp_tls,
|
||||
timeout_override,
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
let user_agent = headers
|
||||
.get(axum::http::header::USER_AGENT)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
store.set_user_agent(&account_id, user_agent);
|
||||
store.set_user_agent_shared(&account_id, user_agent).await;
|
||||
|
||||
let max_age = session_hours * 3600;
|
||||
let secure = config.environment != "development";
|
||||
@@ -420,7 +424,7 @@ pub async fn list_accounts(
|
||||
.into_response();
|
||||
};
|
||||
|
||||
let browser_exists = store.browser_exists(&browser_id);
|
||||
let browser_exists = store.browser_exists_shared(&browser_id).await;
|
||||
if !browser_exists {
|
||||
tracing::debug!(browser_id = %browser_id, "list_accounts: browser_id not found on server");
|
||||
let clear_browser = clearing_browser_cookie(secure, same_site, cookie_path(&config));
|
||||
@@ -439,7 +443,7 @@ pub async fn list_accounts(
|
||||
let session_map: std::collections::HashMap<String, String> =
|
||||
session_cookies.into_iter().collect();
|
||||
|
||||
let browser_accounts = store.get_browser_accounts(&browser_id);
|
||||
let browser_accounts = store.get_browser_accounts_shared(&browser_id).await;
|
||||
let browser_account_ids: Vec<String> = browser_accounts
|
||||
.iter()
|
||||
.map(|s| s.account_id.clone())
|
||||
@@ -450,13 +454,13 @@ pub async fn list_accounts(
|
||||
|
||||
for session in &browser_accounts {
|
||||
if let Some(token) = session_map.get(&session.account_id) {
|
||||
if let Some(valid_session) = store.get(token) {
|
||||
if let Some(valid_session) = store.get_shared(token).await {
|
||||
valid_accounts.push(serde_json::json!({
|
||||
"id": valid_session.account_id,
|
||||
"email": valid_session.email
|
||||
}));
|
||||
} else {
|
||||
store.remove_account(&session.account_id);
|
||||
store.remove_account_shared(&session.account_id).await;
|
||||
clear_cookies.push(clearing_account_cookie(
|
||||
&session.account_id,
|
||||
secure,
|
||||
@@ -465,7 +469,7 @@ pub async fn list_accounts(
|
||||
));
|
||||
}
|
||||
} else {
|
||||
store.remove_account(&session.account_id);
|
||||
store.remove_account_shared(&session.account_id).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +558,7 @@ pub async fn remove_account(
|
||||
.into_response();
|
||||
};
|
||||
|
||||
let browser_accounts = store.get_browser_accounts(&browser_id);
|
||||
let browser_accounts = store.get_browser_accounts_shared(&browser_id).await;
|
||||
let account_belongs_to_browser = browser_accounts.iter().any(|s| s.account_id == account_id);
|
||||
|
||||
if !account_belongs_to_browser {
|
||||
@@ -573,7 +577,7 @@ pub async fn remove_account(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
store.remove_account(&account_id);
|
||||
store.remove_account_shared(&account_id).await;
|
||||
|
||||
let secure = config.environment != "development";
|
||||
let same_site = same_site_policy(&config);
|
||||
@@ -651,7 +655,8 @@ pub async fn list_active_sessions(
|
||||
Extension(session): Extension<SessionState>,
|
||||
) -> Response {
|
||||
let sessions: Vec<ActiveSessionResponse> = store
|
||||
.get_user_sessions(&session.user_hash)
|
||||
.get_user_sessions_shared(&session.user_hash)
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
let timeout_secs = item
|
||||
@@ -694,7 +699,10 @@ pub async fn revoke_active_session(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
if store.remove_user_session(&session.user_hash, &account_id) {
|
||||
if store
|
||||
.remove_user_session_shared(&session.user_hash, &account_id)
|
||||
.await
|
||||
{
|
||||
Json(serde_json::json!({ "status": "revoked" })).into_response()
|
||||
} else {
|
||||
(
|
||||
@@ -715,7 +723,9 @@ pub async fn revoke_other_sessions(
|
||||
Extension(store): Extension<Arc<SessionStore>>,
|
||||
Extension(session): Extension<SessionState>,
|
||||
) -> Response {
|
||||
let revoked = store.remove_other_user_sessions(&session.user_hash, &session.account_id);
|
||||
let revoked = store
|
||||
.remove_other_user_sessions_shared(&session.user_hash, &session.account_id)
|
||||
.await;
|
||||
Json(serde_json::json!({ "status": "revoked", "count": revoked })).into_response()
|
||||
}
|
||||
|
||||
@@ -732,7 +742,7 @@ pub async fn logout(
|
||||
let same_site = same_site_policy(&config);
|
||||
|
||||
if let Some(ref browser_id) = browser_id {
|
||||
let accounts = store.get_browser_accounts(browser_id);
|
||||
let accounts = store.get_browser_accounts_shared(browser_id).await;
|
||||
for account in accounts {
|
||||
cookies_to_clear.push(clearing_account_cookie(
|
||||
&account.account_id,
|
||||
@@ -741,7 +751,7 @@ pub async fn logout(
|
||||
cookie_path(&config),
|
||||
));
|
||||
}
|
||||
store.remove_browser(browser_id);
|
||||
store.remove_browser_shared(browser_id).await;
|
||||
}
|
||||
|
||||
cookies_to_clear.push(clearing_browser_cookie(
|
||||
|
||||
Reference in new issue
Block a user