pub async fn for_request(request: &HttpRequest) -> Result<Self, TelescopeError> {
        // Extract the authenticated identities from the request.
        let identity: Option<AuthenticationCookie> =
            Identity::extract(request).await?.identity().await;

        // If the user is authenticated.
        if let Some(authenticated) = identity {
            // Create a navbar instance to modify and return.
            let mut navbar = Self::userless(request);

            // Check if there is an authenticated RCOS account
            if let Some(user_id) = authenticated.get_user_id().await? {
                // If there is make a navbar with the user ID.
                // Get the navbar auth for this user.
                let navbar_auth = Authentication::get(user_id).await?;
                // Modify navbar as necessary.
                navbar.user_id = Some(user_id);
                navbar.is_admin = navbar_auth.is_admin();
                navbar.is_coordinator = navbar_auth.is_coordinating();
                navbar.is_mentor = navbar_auth.is_mentoring();
                navbar.is_student = navbar_auth.is_student();
                // Return modified navbar.
                return Ok(navbar);
            } else {
                // Otherwise the user is in the middle of creating an account.
                navbar.creating_account = true;
                return Ok(navbar);
            }
        } else {
            // If the user is not authenticated or there is no user ID, return a default navbar.
            return Ok(Self::userless(request));
        }
    }
/// Create a navbar and fill appropriately based on request parameters.
Create a navbar and fill appropriately based on request parameters.
Create a navbar and fill appropriately based on request parameters .
pub async fn for_request(request: &HttpRequest) -> Result<Self, TelescopeError> {
        // Extract the authenticated identities from the request.
        let identity: Option<AuthenticationCookie> =
            Identity::extract(request).await?.identity().await;
        // If the user is authenticated.
        if let Some(authenticated) = identity {
            // Create a navbar instance to modify and return.
            let mut navbar = Self::userless(request);
            // Check if there is an authenticated RCOS account
            if let Some(user_id) = authenticated.get_user_id().await? {
                // If there is make a navbar with the user ID.
                // Get the navbar auth for this user.
                let navbar_auth = Authentication::get(user_id).await?;
                // Modify navbar as necessary.
                navbar.user_id = Some(user_id);
                navbar.is_admin = navbar_auth.is_admin();
                navbar.is_coordinator = navbar_auth.is_coordinating();
                navbar.is_mentor = navbar_auth.is_mentoring();
                navbar.is_student = navbar_auth.is_student();
                // Return modified navbar.
                return Ok(navbar);
            } else {
                // Otherwise the user is in the middle of creating an account.
                navbar.creating_account = true;
                return Ok(navbar);
            }
        } else {
            // If the user is not authenticated or there is no user ID, return a default navbar.
            return Ok(Self::userless(request));
        }
    }
pub async fn for_request ( request : & HttpRequest ) -> Result < Self , TelescopeError > { // Extract the authenticated identities from the request. let identity : Option < AuthenticationCookie > = Identity :: extract ( request ) . await ? . identity ( ) . await ; // If the user is authenticated. if let Some ( authenticated ) = identity { // Create a navbar instance to modify and return. let mut navbar = Self :: userless ( request ) ; // Check if there is an authenticated RCOS account if let Some ( user_id ) = authenticated . get_user_id ( ) . await ? { // If there is make a navbar with the user ID. // Get the navbar auth for this user. let navbar_auth = Authentication :: get ( user_id ) . await ? ; // Modify navbar as necessary. navbar . user_id = Some ( user_id ) ; navbar . is_admin = navbar_auth . is_admin ( ) ; navbar . is_coordinator = navbar_auth . is_coordinating ( ) ; navbar . is_mentor = navbar_auth . is_mentoring ( ) ; navbar . is_student = navbar_auth . is_student ( ) ; // Return modified navbar. return Ok ( navbar ) ; } else { // Otherwise the user is in the middle of creating an account. navbar . creating_account = true ; return Ok ( navbar ) ; } } else { // If the user is not authenticated or there is no user ID, return a default navbar. return Ok ( Self :: userless ( request ) ) ; } }
Create a navbar and fill appropriately based on request parameters.
Create a navbar and fill appropriately based on request parameters .
request
&HttpRequest
request
&HttpRequest