-
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.
Chore: Rework UI structure, automatic authorization
Add: Support for changing password Add: Error banner in the UI Add: Cookie on successful login using the token or IdToken flows
- Loading branch information
1 parent
5fad4c0
commit 8363604
Showing
39 changed files
with
955 additions
and
228 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,87 @@ | ||
use actix_web::cookie::time::{Duration, OffsetDateTime}; | ||
use actix_web::cookie::{Cookie, Expiration, SameSite}; | ||
use actix_web::{HttpRequest, HttpResponse, Responder}; | ||
use std::borrow::Cow; | ||
|
||
pub struct SetCookie<'c, I> { | ||
k: Cow<'c, str>, | ||
v: Cow<'c, str>, | ||
i: I, | ||
} | ||
|
||
impl<'c, I> SetCookie<'c, I> { | ||
pub fn new<N, V>(k: N, v: V, i: I) -> Self | ||
where | ||
I: Responder, | ||
N: Into<Cow<'c, str>>, | ||
V: Into<Cow<'c, str>>, | ||
{ | ||
Self { | ||
k: k.into(), | ||
v: v.into(), | ||
i, | ||
} | ||
} | ||
} | ||
|
||
impl<'c, I> Responder for SetCookie<'c, I> | ||
where | ||
I: Responder, | ||
{ | ||
type Body = I::Body; | ||
|
||
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> { | ||
let mut inner_response = self.i.respond_to(req); | ||
let mut cookie = Cookie::new(self.k, self.v); | ||
cookie.set_secure(true); | ||
cookie.set_expires(Expiration::DateTime( | ||
OffsetDateTime::now_utc() + Duration::days(30), | ||
)); | ||
cookie.set_same_site(SameSite::None); | ||
cookie.set_path("/"); | ||
|
||
inner_response.add_cookie(&cookie).unwrap(); | ||
inner_response | ||
} | ||
} | ||
|
||
pub struct MaybeCookie<'c, I> { | ||
cookie: Option<SetCookie<'c, I>>, | ||
i: Option<I>, | ||
} | ||
|
||
impl<'c, I> MaybeCookie<'c, I> { | ||
pub fn some(cookie: SetCookie<'c, I>) -> Self { | ||
Self { | ||
cookie: Some(cookie), | ||
i: None, | ||
} | ||
} | ||
} | ||
|
||
impl<'c, I> MaybeCookie<'c, I> | ||
where | ||
I: Responder, | ||
{ | ||
pub fn none(i: I) -> Self { | ||
Self { | ||
cookie: None, | ||
i: Some(i), | ||
} | ||
} | ||
} | ||
|
||
impl<'c, I> Responder for MaybeCookie<'c, I> | ||
where | ||
I: Responder, | ||
{ | ||
type Body = I::Body; | ||
|
||
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> { | ||
match (self.cookie, self.i) { | ||
(Some(c), _) => c.respond_to(req), | ||
(None, Some(i)) => i.respond_to(req), | ||
_ => unreachable!(), | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
server/wilford/src/routes/v1/user/supports_password_change.rs
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,24 @@ | ||
use crate::authorization::combined::CombinedAuthorizationProvider; | ||
use crate::authorization::AuthorizationProvider; | ||
use crate::routes::auth::Auth; | ||
use crate::routes::{WConfig, WDatabase}; | ||
use actix_web::web; | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize)] | ||
pub struct Response { | ||
/// Whether a password change is supported | ||
password_change_supported: bool, | ||
} | ||
|
||
/// Check if a password change is supported | ||
pub async fn supports_password_change( | ||
config: WConfig, | ||
database: WDatabase, | ||
_: Auth, | ||
) -> web::Json<Response> { | ||
let provider = CombinedAuthorizationProvider::new(&config, &database); | ||
web::Json(Response { | ||
password_change_supported: provider.supports_password_change(), | ||
}) | ||
} |
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,21 @@ | ||
<template> | ||
<MaterialBanner | ||
title="Error" | ||
type="error" | ||
icon="mdi-alert-circle-outline" | ||
:text="modelValue" | ||
@close="$emit('update', undefined)" | ||
/> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent} from "vue" | ||
import MaterialBanner from "@/components/MaterialBanner.vue"; | ||
export default defineComponent({ | ||
components: {MaterialBanner}, | ||
props: { | ||
modelValue: String | ||
} | ||
}) | ||
</script> |
Oops, something went wrong.