implement redirect to source on admin login HTML endpoint
This commit is contained in:
parent
4491fbb6f2
commit
a8c6912c25
11 changed files with 58 additions and 25 deletions
|
@ -20,7 +20,7 @@ use actix_web::http::header;
|
||||||
use actix_web::{web, HttpResponse, Responder};
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{RedirectQuery, get_random};
|
use super::{get_random, RedirectQuery};
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::AppData;
|
use crate::AppData;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use sqlx::types::time::OffsetDateTime;
|
use sqlx::types::time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::{RedirectQuery, get_uuid};
|
use super::{get_uuid, RedirectQuery};
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::AppData;
|
use crate::AppData;
|
||||||
|
|
||||||
|
@ -121,8 +121,6 @@ pub mod runners {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[my_codegen::get(path = "crate::V1_API_ROUTES.benches.register")]
|
#[my_codegen::get(path = "crate::V1_API_ROUTES.benches.register")]
|
||||||
async fn register(
|
async fn register(
|
||||||
data: AppData,
|
data: AppData,
|
||||||
|
|
|
@ -51,6 +51,7 @@ lazy_static! {
|
||||||
|
|
||||||
pub static ref CSS: &'static str =
|
pub static ref CSS: &'static str =
|
||||||
FILES.get("./static/cache/bundle/css/main.css").unwrap();
|
FILES.get("./static/cache/bundle/css/main.css").unwrap();
|
||||||
|
|
||||||
pub static ref JS: &'static str =
|
pub static ref JS: &'static str =
|
||||||
FILES.get("./static/cache/bundle/bundle.js").unwrap();
|
FILES.get("./static/cache/bundle/bundle.js").unwrap();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ use my_codegen::{get, post};
|
||||||
use sailfish::TemplateOnce;
|
use sailfish::TemplateOnce;
|
||||||
|
|
||||||
use crate::api::v1::admin::auth::runners;
|
use crate::api::v1::admin::auth::runners;
|
||||||
|
use crate::api::v1::RedirectQuery;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::pages::errors::ErrorPage;
|
use crate::pages::errors::ErrorPage;
|
||||||
use crate::AppData;
|
use crate::AppData;
|
||||||
|
@ -65,15 +66,23 @@ pub async fn login_submit(
|
||||||
id: Identity,
|
id: Identity,
|
||||||
payload: web::Form<runners::Login>,
|
payload: web::Form<runners::Login>,
|
||||||
data: AppData,
|
data: AppData,
|
||||||
|
path: web::Path<RedirectQuery>,
|
||||||
) -> PageResult<impl Responder> {
|
) -> PageResult<impl Responder> {
|
||||||
let payload = payload.into_inner();
|
let payload = payload.into_inner();
|
||||||
match runners::login_runner(&payload, &data).await {
|
match runners::login_runner(&payload, &data).await {
|
||||||
Ok(username) => {
|
Ok(username) => {
|
||||||
id.remember(username);
|
id.remember(username);
|
||||||
|
let path = path.into_inner();
|
||||||
|
if let Some(redirect_to) = path.redirect_to {
|
||||||
|
Ok(HttpResponse::Found()
|
||||||
|
.insert_header((header::LOCATION, redirect_to))
|
||||||
|
.finish())
|
||||||
|
} else {
|
||||||
Ok(HttpResponse::Found()
|
Ok(HttpResponse::Found()
|
||||||
.insert_header((header::LOCATION, PAGES.home))
|
.insert_header((header::LOCATION, PAGES.home))
|
||||||
.finish())
|
.finish())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let status = e.status_code();
|
let status = e.status_code();
|
||||||
let heading = status.canonical_reason().unwrap_or("Error");
|
let heading = status.canonical_reason().unwrap_or("Error");
|
||||||
|
|
|
@ -18,8 +18,6 @@ pub mod join;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod sudo;
|
pub mod sudo;
|
||||||
|
|
||||||
pub use crate::api::v1::admin::get_admin_check_login;
|
|
||||||
|
|
||||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(login::login);
|
cfg.service(login::login);
|
||||||
cfg.service(login::login_submit);
|
cfg.service(login::login_submit);
|
||||||
|
@ -28,10 +26,29 @@ pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod routes {
|
pub mod routes {
|
||||||
|
use crate::middleware::auth::GetLoginRoute;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
pub struct Auth {
|
pub struct Auth {
|
||||||
pub login: &'static str,
|
pub login: &'static str,
|
||||||
pub join: &'static str,
|
pub join: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GetLoginRoute for Auth {
|
||||||
|
fn get_login_route(&self, src: Option<&str>) -> String {
|
||||||
|
if let Some(redirect_to) = src {
|
||||||
|
let mut url = Url::parse("http://x/").unwrap();
|
||||||
|
url.set_path(self.login);
|
||||||
|
url.query_pairs_mut()
|
||||||
|
.append_pair("redirect_to", redirect_to);
|
||||||
|
let path = format!("{}/?{}", url.path(), url.query().unwrap());
|
||||||
|
path
|
||||||
|
} else {
|
||||||
|
self.login.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Auth {
|
impl Auth {
|
||||||
pub const fn new() -> Auth {
|
pub const fn new() -> Auth {
|
||||||
Auth {
|
Auth {
|
||||||
|
|
|
@ -30,6 +30,10 @@ pub fn services(cfg: &mut ServiceConfig) {
|
||||||
errors::services(cfg);
|
errors::services(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_page_check_login() -> crate::CheckLogin<auth::routes::Auth> {
|
||||||
|
crate::CheckLogin::new(crate::PAGES.auth)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -25,7 +25,6 @@ use my_codegen::{get, post};
|
||||||
use sailfish::TemplateOnce;
|
use sailfish::TemplateOnce;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::get_admin_check_login;
|
|
||||||
use crate::api::v1::admin::auth::runners::{login_runner, Login, Password};
|
use crate::api::v1::admin::auth::runners::{login_runner, Login, Password};
|
||||||
use crate::api::v1::admin::campaigns::runners;
|
use crate::api::v1::admin::campaigns::runners;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
|
@ -60,7 +59,7 @@ async fn get_title(
|
||||||
|
|
||||||
#[get(
|
#[get(
|
||||||
path = "PAGES.panel.campaigns.delete",
|
path = "PAGES.panel.campaigns.delete",
|
||||||
wrap = "get_admin_check_login()"
|
wrap = "crate::pages::get_page_check_login()"
|
||||||
)]
|
)]
|
||||||
pub async fn delete_campaign(
|
pub async fn delete_campaign(
|
||||||
id: Identity,
|
id: Identity,
|
||||||
|
@ -86,7 +85,7 @@ pub async fn delete_campaign(
|
||||||
|
|
||||||
#[post(
|
#[post(
|
||||||
path = "PAGES.panel.campaigns.delete",
|
path = "PAGES.panel.campaigns.delete",
|
||||||
wrap = "get_admin_check_login()"
|
wrap = "crate::pages::get_page_check_login()"
|
||||||
)]
|
)]
|
||||||
pub async fn delete_campaign_submit(
|
pub async fn delete_campaign_submit(
|
||||||
id: Identity,
|
id: Identity,
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
//use crate::api::v1::admin::campaigns::{runners, GetFeedbackResp};
|
//use crate::api::v1::admin::campaigns::{runners, GetFeedbackResp};
|
||||||
//use crate::AppData;
|
//use crate::AppData;
|
||||||
//use crate::PAGES;
|
//use crate::PAGES;
|
||||||
//use super::get_admin_check_login;
|
|
||||||
//
|
//
|
||||||
//#[derive(TemplateOnce)]
|
//#[derive(TemplateOnce)]
|
||||||
//#[template(path = "panel/campaigns/get/index.html")]
|
//#[template(path = "panel/campaigns/get/index.html")]
|
||||||
|
@ -41,7 +40,7 @@
|
||||||
//
|
//
|
||||||
//#[get(
|
//#[get(
|
||||||
// path = "PAGES.panel.campaigns.get_feedback",
|
// path = "PAGES.panel.campaigns.get_feedback",
|
||||||
// wrap = "get_admin_check_login()"
|
// wrap = "crate::pages::get_page_check_login()"
|
||||||
//)]
|
//)]
|
||||||
//pub async fn get_feedback(
|
//pub async fn get_feedback(
|
||||||
// id: Identity,
|
// id: Identity,
|
||||||
|
|
|
@ -24,8 +24,6 @@ use crate::api::v1::admin::campaigns::{
|
||||||
use crate::AppData;
|
use crate::AppData;
|
||||||
use crate::PAGES;
|
use crate::PAGES;
|
||||||
|
|
||||||
use super::get_admin_check_login;
|
|
||||||
|
|
||||||
pub mod delete;
|
pub mod delete;
|
||||||
pub mod get;
|
pub mod get;
|
||||||
pub mod new;
|
pub mod new;
|
||||||
|
@ -85,7 +83,10 @@ impl HomePage {
|
||||||
|
|
||||||
const PAGE: &str = "Campaigns";
|
const PAGE: &str = "Campaigns";
|
||||||
|
|
||||||
#[get(path = "PAGES.panel.campaigns.home", wrap = "get_admin_check_login()")]
|
#[get(
|
||||||
|
path = "PAGES.panel.campaigns.home",
|
||||||
|
wrap = "crate::pages::get_page_check_login()"
|
||||||
|
)]
|
||||||
pub async fn home(data: AppData, id: Identity) -> impl Responder {
|
pub async fn home(data: AppData, id: Identity) -> impl Responder {
|
||||||
let username = id.identity().unwrap();
|
let username = id.identity().unwrap();
|
||||||
let campaigns = list_campaign_runner(&username, &data).await.unwrap();
|
let campaigns = list_campaign_runner(&username, &data).await.unwrap();
|
||||||
|
|
|
@ -27,8 +27,6 @@ use crate::pages::errors::ErrorPage;
|
||||||
use crate::AppData;
|
use crate::AppData;
|
||||||
use crate::PAGES;
|
use crate::PAGES;
|
||||||
|
|
||||||
use super::get_admin_check_login;
|
|
||||||
|
|
||||||
#[derive(Clone, TemplateOnce)]
|
#[derive(Clone, TemplateOnce)]
|
||||||
#[template(path = "panel/campaigns/new/index.html")]
|
#[template(path = "panel/campaigns/new/index.html")]
|
||||||
struct NewCampaign<'a> {
|
struct NewCampaign<'a> {
|
||||||
|
@ -55,14 +53,20 @@ lazy_static! {
|
||||||
static ref INDEX: String = NewCampaign::default().render_once().unwrap();
|
static ref INDEX: String = NewCampaign::default().render_once().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(path = "PAGES.panel.campaigns.new", wrap = "get_admin_check_login()")]
|
#[get(
|
||||||
|
path = "PAGES.panel.campaigns.new",
|
||||||
|
wrap = "crate::pages::get_page_check_login()"
|
||||||
|
)]
|
||||||
pub async fn new_campaign() -> impl Responder {
|
pub async fn new_campaign() -> impl Responder {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("text/html; charset=utf-8")
|
.content_type("text/html; charset=utf-8")
|
||||||
.body(&*INDEX)
|
.body(&*INDEX)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post(path = "PAGES.panel.campaigns.new", wrap = "get_admin_check_login()")]
|
#[post(
|
||||||
|
path = "PAGES.panel.campaigns.new",
|
||||||
|
wrap = "crate::pages::get_page_check_login()"
|
||||||
|
)]
|
||||||
pub async fn new_campaign_submit(
|
pub async fn new_campaign_submit(
|
||||||
id: Identity,
|
id: Identity,
|
||||||
payload: web::Json<AddCapmaign>,
|
payload: web::Json<AddCapmaign>,
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
use actix_web::{http, HttpResponse, Responder};
|
use actix_web::{http, HttpResponse, Responder};
|
||||||
use my_codegen::get;
|
use my_codegen::get;
|
||||||
|
|
||||||
pub use crate::api::v1::admin::get_admin_check_login;
|
|
||||||
|
|
||||||
use crate::PAGES;
|
use crate::PAGES;
|
||||||
|
|
||||||
mod campaigns;
|
mod campaigns;
|
||||||
|
@ -49,7 +47,10 @@ pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
campaigns::services(cfg);
|
campaigns::services(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(path = "PAGES.panel.home", wrap = "get_admin_check_login()")]
|
#[get(
|
||||||
|
path = "PAGES.panel.home",
|
||||||
|
wrap = "crate::pages::get_page_check_login()"
|
||||||
|
)]
|
||||||
pub async fn home() -> impl Responder {
|
pub async fn home() -> impl Responder {
|
||||||
HttpResponse::Found()
|
HttpResponse::Found()
|
||||||
.insert_header((http::header::LOCATION, PAGES.panel.campaigns.home))
|
.insert_header((http::header::LOCATION, PAGES.panel.campaigns.home))
|
||||||
|
|
Loading…
Add table
Reference in a new issue