Struct rocket_auth::User [−][src]
The User
guard can be used to restrict content so it can only be viewed by authenticated users.
#[get("/private-content")] fn private_content(user: User) -> &'static str { "If you can see this, you are logged in." }
Fields
is_admin: bool
Implementations
impl User
[src]
pub fn set_password(&mut self, new: &str) -> Result<(), Error>
[src]
This method allows to reset the password of a user.
In order for the new password to be saved, it must be passed to a Users
instance.
This function is meant for cases where the user lost their password.
In case the user is authenticated,
you can change it more easily with change_password
.
This function will fail in case the password is not secure enough.
#[get("/reset-password/<id>/<new_password>")] fn reset_password(id: i32, new_password: String, users: State<Users>) -> Result<(), Error> { let mut user = users.get_by_id(id)?; user.set_password(&new_password); users.modify(&user)?; Ok(()) }
pub fn id(&self) -> i32
[src]
This is an accessor function for the private id
field.
This field is private so it is not modified by accident when updating a user.
#[get("/show-my-id")] fn show_my_id(user: User) -> String { format!("Your user_id is: {}", user.id()) }
pub fn email(&self) -> &str
[src]
This is an accessor field for the private email
field.
This field is private so an email cannot be updated without checking whether it is valid.
#[get("/show-my-email")] fn show_my_email(user: User) -> String { format!("Your user_id is: {}", user.email()) }
pub fn set_email(&mut self, email: &str) -> Result<(), Error>
[src]
This functions allows to easily modify the email of a user.
In case the input is not a valid email, it will return an error.
In case the user corresponds to the authenticated client, it’s easier to use Auth::change_email
.
#[get("/set-email/<email>")] fn show_my_email(email: String, auth: Auth) -> Result<String, Error> { let mut user = auth.get_user().unwrap(); user.set_email(&email)?; auth.users.modify(&user)?; Ok("Your user email was changed".into()) }
Trait Implementations
impl Clone for User
[src]
impl Debug for User
[src]
impl<'de> Deserialize<'de> for User
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Eq for User
[src]
impl<'a, 'r> FromRequest<'a, 'r> for User
[src]
type Error = Error
The associated error to be returned if derivation fails.
fn from_request(request: &'a Request<'_>) -> Outcome<User, Error>
[src]
impl PartialEq<User> for User
[src]
impl Serialize for User
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralEq for User
[src]
impl StructuralPartialEq for User
[src]
impl TryFrom<Row> for User
[src]
Auto Trait Implementations
impl RefUnwindSafe for User
impl Send for User
impl Sync for User
impl Unpin for User
impl UnwindSafe for User
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, I> AsResult<T, I> for T where
I: Input,
I: Input,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> Erased for T
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoCollection<T> for T
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
A: Array<Item = T>,
pub fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,