chore: import MCTF services
- Added all seven issued service trees without omissions. - Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
commit
13f936bee9
1222 files changed
+21280
No files matched your search
Executable
+70
@@ -0,0 +1,70 @@
|
||||
use dioxus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct AuthUser {
|
||||
pub username: String,
|
||||
pub token: String,
|
||||
pub workspace_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum AuthState {
|
||||
Checking,
|
||||
Guest,
|
||||
User(AuthUser),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Auth(pub Signal<AuthState>);
|
||||
|
||||
impl AuthState {
|
||||
pub fn user(&self) -> Option<&AuthUser> {
|
||||
match self {
|
||||
Self::User(user) => Some(user),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_cloned(&self) -> Option<AuthUser> {
|
||||
self.user().cloned()
|
||||
}
|
||||
|
||||
pub fn is_guest(&self) -> bool {
|
||||
matches!(self, Self::Guest)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "web"), allow(dead_code))]
|
||||
const STORAGE_KEY: &str = "pamsave.auth";
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
pub fn persist(user: &AuthUser) {
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
let _ = LocalStorage::set(STORAGE_KEY, user);
|
||||
}
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
pub fn restore() -> Option<AuthUser> {
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
LocalStorage::get::<AuthUser>(STORAGE_KEY).ok()
|
||||
}
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
pub fn clear_persisted() {
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
LocalStorage::delete(STORAGE_KEY);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "web"))]
|
||||
pub fn persist(_user: &AuthUser) {}
|
||||
|
||||
#[cfg(not(feature = "web"))]
|
||||
pub fn restore() -> Option<AuthUser> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "web"))]
|
||||
pub fn clear_persisted() {}
|
||||
Reference in new issue
Block a user