This commit is contained in:
parent
cb0806f690
commit
29cf990363
2 changed files with 5 additions and 5 deletions
|
@ -15,7 +15,7 @@ impl CSRF for User {
|
||||||
///
|
///
|
||||||
/// This is useful for htmx requests to update the CSRF token in place.
|
/// This is useful for htmx requests to update the CSRF token in place.
|
||||||
async fn update_csrf(&self) -> PreEscaped<String> {
|
async fn update_csrf(&self) -> PreEscaped<String> {
|
||||||
html! { script { (format!("document.getElementById('csrf').value = '{}';", self.get_csrf().await)) }; }
|
html! { script { (format!("document.querySelectorAll('.csrf').forEach(element => {{ element.value = '{}'; }});", self.get_csrf().await)) }; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get CSRF Token for the current session
|
/// Get CSRF Token for the current session
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub trait Sessions {
|
||||||
fn api_key(&self, name: &str) -> impl std::future::Future<Output = Session>;
|
fn api_key(&self, name: &str) -> impl std::future::Future<Output = Session>;
|
||||||
fn session(&self) -> impl std::future::Future<Output = Session>;
|
fn session(&self) -> impl std::future::Future<Output = Session>;
|
||||||
fn list_sessions(&self) -> impl std::future::Future<Output = Vec<Session>>;
|
fn list_sessions(&self) -> impl std::future::Future<Output = Vec<Session>>;
|
||||||
fn end_session(&self) -> impl std::future::Future<Output = ()>;
|
fn end_session(&self, id: &str) -> impl std::future::Future<Output = ()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sessions for User {
|
impl Sessions for User {
|
||||||
|
@ -60,9 +60,9 @@ impl Sessions for User {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// End a user session
|
/// End a user session
|
||||||
async fn end_session(&self) {
|
async fn end_session(&self, id: &str) {
|
||||||
sqlx::query("DELETE FROM user_session WHERE token = $1")
|
sqlx::query("DELETE FROM user_session WHERE id = $1")
|
||||||
.bind(&self.session)
|
.bind(id)
|
||||||
.execute(get_pg!())
|
.execute(get_pg!())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue