-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): add LoggedInRepository as abstraction
- Loading branch information
1 parent
ca5db4b
commit 42f026c
Showing
6 changed files
with
89 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use leptos::*; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use surrealdb::sql::Thing; | ||
|
||
use crate::{hooks::use_database, model::User, repository::SessionRepository}; | ||
|
||
use super::UserRepository; | ||
|
||
pub struct LoggedInRepository {} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct LoggenInRelation { | ||
user_id: String, | ||
session_id: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct LoggedInModel { | ||
id: Thing, | ||
users: Vec<Thing>, | ||
} | ||
|
||
impl LoggedInRepository { | ||
const TABLE: &str = "logged_in"; | ||
|
||
pub async fn find_user_via_session(session_id: &str) -> Option<User> { | ||
let db = use_database().await; | ||
|
||
let Ok(mut response) = db | ||
.query(format!( | ||
"select id, <-{relation}<-{user_table} as users from {session_id};", | ||
relation = Self::TABLE, | ||
user_table = UserRepository::TABLE | ||
)) | ||
.await | ||
else { | ||
return None; | ||
}; | ||
|
||
let Ok(Some(result)): Result<Option<LoggedInModel>, surrealdb::Error> = response.take(0) | ||
else { | ||
return None; | ||
}; | ||
|
||
let Some(user) = result.users.get(0) else { | ||
return None; | ||
}; | ||
|
||
User::get_by_id(user.id.clone()).await | ||
} | ||
|
||
pub async fn attach_user_to_session(user: &str, session: &str) -> Result<(), ()> { | ||
let db = use_database().await; | ||
|
||
if let Err(e) = db | ||
.query(format!( | ||
"RELATE {user}->{table}->{session}", | ||
table = Self::TABLE | ||
)) | ||
.await | ||
{ | ||
error!( | ||
"Error creating a relation between user ({}) and session ({}): {e:?}", | ||
user, session | ||
); | ||
if let Err(e) = SessionRepository::delete(session).await { | ||
error!("Error deleting session ({session}): {e:?}"); | ||
}; | ||
return Err(()); | ||
}; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,6 @@ pub fn ImpressumView(cx: Scope) -> impl IntoView { | |
view! { cx, | ||
<section class="impressum"> | ||
<div> | ||
<h1>Impressum</h1> | ||
<h2 id="m3">Verantwortlicher</h2> | ||
|
||
<h1>"Datenschutzerklärung"</h1> | ||
<h2 id="m4158">"Präambel"</h2> | ||
<p>"Mit der folgenden Datenschutzerklärung möchten wir Sie darüber aufklären, welche Arten Ihrer personenbezogenen Daten (nachfolgend auch kurz als \"Daten\" bezeichnet) wir zu welchen Zwecken und in welchem Umfang im Rahmen der Bereitstellung unserer Applikation verarbeiten."</p> | ||
|
@@ -16,7 +13,7 @@ pub fn ImpressumView(cx: Scope) -> impl IntoView { | |
<h2>"Inhaltsübersicht"</h2> | ||
<ul class="index"> | ||
<li><a class="index-link" href="#m4158">"Präambel"</a></li> | ||
<li><a class="index-link" href="#m3">"Verantwortlicher"</a></li> | ||
<li><a class="index-link" href="#m3">"Kontakt"</a></li> | ||
<li><a class="index-link" href="#mOverview">"Übersicht der Verarbeitungen"</a></li> | ||
<li><a class="index-link" href="#m2427">"Maßgebliche Rechtsgrundlagen"</a></li> | ||
<li><a class="index-link" href="#m27">"Sicherheitsmaßnahmen"</a></li> | ||
|
@@ -32,7 +29,9 @@ pub fn ImpressumView(cx: Scope) -> impl IntoView { | |
<li><a class="index-link" href="#m328">Plugins und eingebettete Funktionen sowie Inhalte</a></li> | ||
<li><a class="index-link" href="#m15">Änderung und Aktualisierung der Datenschutzerklärung</a></li> | ||
</ul> | ||
<h2 id="m3">Verantwortlicher</h2> | ||
<h2 id="m3">"Kontakt"</h2> | ||
E-Mail-Adresse: | ||
<p><a href="mailto:[email protected]">"[email protected]"</a></p> | ||
<h2 id="m2427">Maßgebliche Rechtsgrundlagen</h2> | ||
<p><strong>Maßgebliche Rechtsgrundlagen nach der DSGVO: </strong>Im Folgenden erhalten Sie eine Übersicht der Rechtsgrundlagen der DSGVO, auf deren Basis wir personenbezogene Daten verarbeiten. Bitte nehmen Sie zur Kenntnis, dass neben den Regelungen der DSGVO nationale Datenschutzvorgaben in Ihrem bzw. unserem Wohn- oder Sitzland gelten können. Sollten ferner im Einzelfall speziellere Rechtsgrundlagen maßgeblich sein, teilen wir Ihnen diese in der Datenschutzerklärung mit.</p> | ||
<ul> | ||
|