implement redirect to source on admin login endpoint
This commit is contained in:
parent
bc63926d18
commit
4491fbb6f2
4 changed files with 21 additions and 10 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::get_random;
|
use super::{RedirectQuery, get_random};
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::AppData;
|
use crate::AppData;
|
||||||
|
|
||||||
|
@ -231,12 +231,20 @@ async fn register(
|
||||||
async fn login(
|
async fn login(
|
||||||
id: Identity,
|
id: Identity,
|
||||||
payload: web::Json<runners::Login>,
|
payload: web::Json<runners::Login>,
|
||||||
|
path: web::Query<RedirectQuery>,
|
||||||
data: AppData,
|
data: AppData,
|
||||||
) -> ServiceResult<impl Responder> {
|
) -> ServiceResult<impl Responder> {
|
||||||
let payload = payload.into_inner();
|
let payload = payload.into_inner();
|
||||||
let username = runners::login_runner(&payload, &data).await?;
|
let username = runners::login_runner(&payload, &data).await?;
|
||||||
|
let path = path.into_inner();
|
||||||
id.remember(username);
|
id.remember(username);
|
||||||
Ok(HttpResponse::Ok())
|
if let Some(redirect_to) = path.redirect_to {
|
||||||
|
Ok(HttpResponse::Found()
|
||||||
|
.insert_header((header::LOCATION, redirect_to))
|
||||||
|
.finish())
|
||||||
|
} else {
|
||||||
|
Ok(HttpResponse::Ok().into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[my_codegen::get(
|
#[my_codegen::get(
|
||||||
path = "crate::V1_API_ROUTES.admin.auth.logout",
|
path = "crate::V1_API_ROUTES.admin.auth.logout",
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub mod campaigns;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
pub use super::{get_random, get_uuid};
|
pub use super::{get_random, get_uuid, RedirectQuery};
|
||||||
|
|
||||||
pub fn services(cfg: &mut ServiceConfig) {
|
pub fn services(cfg: &mut ServiceConfig) {
|
||||||
auth::services(cfg);
|
auth::services(cfg);
|
||||||
|
|
|
@ -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::get_uuid;
|
use super::{RedirectQuery, get_uuid};
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::AppData;
|
use crate::AppData;
|
||||||
|
|
||||||
|
@ -121,16 +121,13 @@ pub mod runners {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct Query {
|
|
||||||
pub redirect_to: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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,
|
||||||
id: Identity,
|
id: Identity,
|
||||||
path: web::Query<Query>,
|
path: web::Query<RedirectQuery>,
|
||||||
) -> ServiceResult<HttpResponse> {
|
) -> ServiceResult<HttpResponse> {
|
||||||
let uuid = runners::register_runner(&data).await?;
|
let uuid = runners::register_runner(&data).await?;
|
||||||
id.remember(uuid.to_string());
|
id.remember(uuid.to_string());
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
use actix_web::web::ServiceConfig;
|
use actix_web::web::ServiceConfig;
|
||||||
|
use serde::Deserialize;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub mod admin;
|
pub mod admin;
|
||||||
|
@ -45,3 +46,8 @@ pub fn get_random(len: usize) -> String {
|
||||||
pub fn get_uuid() -> Uuid {
|
pub fn get_uuid() -> Uuid {
|
||||||
Uuid::new_v4()
|
Uuid::new_v4()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct RedirectQuery {
|
||||||
|
pub redirect_to: Option<String>,
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue