BasicOIDC/src/controllers/base_controller.rs

39 lines
931 B
Rust

use std::fmt::Display;
use actix_web::HttpResponse;
use askama::Template;
use crate::constants::LOGIN_ROUTE;
/// Create a redirect user response
pub fn redirect_user(uri: &str) -> HttpResponse {
HttpResponse::Found()
.append_header(("Location", uri))
.finish()
}
/// Redirect user to authenticate him
pub fn redirect_user_for_login<P: Display>(redirect_uri: P) -> HttpResponse {
HttpResponse::Found()
.append_header((
"Location",
format!(
"{}?redirect={}",
LOGIN_ROUTE,
urlencoding::encode(&redirect_uri.to_string())
),
))
.finish()
}
/// Fatal error page message
#[derive(Template)]
#[template(path = "fatal_error.html")]
struct FatalErrorPage {
message: &'static str,
}
pub fn build_fatal_error_page(msg: &'static str) -> String {
FatalErrorPage { message: msg }.render().unwrap()
}