Struct rocket_auth::User[][src]

pub struct User {
    pub is_admin: bool,
    // some fields omitted
}

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]

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.

impl PartialEq<User> for User[src]

impl Serialize for User[src]

impl StructuralEq for User[src]

impl StructuralPartialEq for User[src]

impl TryFrom<Row> for User[src]

type Error = Error

The type returned in the event of a conversion error.

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]

impl<T, I> AsResult<T, I> for T where
    I: Input, 

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[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]

impl<T> IntoCollection<T> for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,