1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! Login and logout

use crate::error::TelescopeError;
use crate::templates::auth;
use crate::templates::page::Page;
use crate::web::services::auth::identity::Identity;
use actix_web::http::header::LOCATION;
use actix_web::{HttpRequest, HttpResponse};

#[get("/login")]
/// Login page. Users go here and are presented options to login with a variety
/// of identity providers.
pub async fn login_page(req: HttpRequest) -> Result<Page, TelescopeError> {
    auth::login().in_page(&req, "RCOS Login").await
}

#[get("/logout")]
/// Logout service. This just logs the user out and then redirects them to the
/// homepage.
pub async fn logout(identity: Identity) -> HttpResponse {
    // Forget the user's identity
    identity.forget();
    // Redirect the user to the homepage.
    HttpResponse::Found().header(LOCATION, "/").finish()
}