pub struct AuthUser {
pub sub: String,
pub name: String,
pub email: String,
pub role: String,
pub permissions: Vec<String>,
pub exp: usize,
pub iat: usize,
}Expand description
AuthUser — Representasi pengguna yang terautentikasi. Berfungsi sebagai Model data JWT sekaligus Custom Extractor (Dependency Injection).
Fields§
§sub: String§name: String§email: String§role: String§permissions: Vec<String>§exp: usize§iat: usizeImplementations§
Source§impl AuthUser
impl AuthUser
pub fn new( user_id: i64, email: String, role: String, permissions: Vec<String>, hours: usize, ) -> AuthUser
pub fn with_name( user_id: i64, name: impl Into<String>, email: String, role: String, permissions: Vec<String>, hours: usize, ) -> AuthUser
Sourcepub fn display_name(&self) -> &str
pub fn display_name(&self) -> &str
Ambil nama tampilan pengguna. Jika nama kosong, gunakan bagian awal email.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AuthUser
impl<'de> Deserialize<'de> for AuthUser
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<AuthUser, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<AuthUser, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<S> FromRequestParts<S> for AuthUser
Implementasi Extractor agar AuthUser bisa langsung disuntikkan ke parameter Controller.
impl<S> FromRequestParts<S> for AuthUser
Implementasi Extractor agar AuthUser bisa langsung disuntikkan ke parameter Controller.
Source§type Rejection = AppError
type Rejection = AppError
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request_parts<'life0, 'life1, 'async_trait>(
parts: &'life0 mut Parts,
_state: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<AuthUser, <AuthUser as FromRequestParts<S>>::Rejection>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AuthUser: 'async_trait,
fn from_request_parts<'life0, 'life1, 'async_trait>(
parts: &'life0 mut Parts,
_state: &'life1 S,
) -> Pin<Box<dyn Future<Output = Result<AuthUser, <AuthUser as FromRequestParts<S>>::Rejection>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AuthUser: 'async_trait,
Perform the extraction.
Source§impl HasRolesAndPermissions for AuthUser
impl HasRolesAndPermissions for AuthUser
Source§fn can(&self, permission: &str) -> bool
fn can(&self, permission: &str) -> bool
Cek apakah pengguna memiliki izin tertentu.
Pengguna dengan role
admin atau superadmin otomatis memiliki semua izin.Source§fn has_any_role(&self, roles: &[&str]) -> bool
fn has_any_role(&self, roles: &[&str]) -> bool
Cek apakah pengguna memiliki salah satu dari daftar peran.
Source§fn has_all_roles(&self, roles: &[&str]) -> bool
fn has_all_roles(&self, roles: &[&str]) -> bool
Cek apakah pengguna memiliki semua peran dalam daftar.
Source§impl Serialize for AuthUser
impl Serialize for AuthUser
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Forget for AuthUser
impl Freeze for AuthUser
impl Move for AuthUser
impl RefUnwindSafe for AuthUser
impl Send for AuthUser
impl Sync for AuthUser
impl Unpin for AuthUser
impl UnsafeUnpin for AuthUser
impl UnwindSafe for AuthUser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more