mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 02:25:41 +00:00
frontend integration
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -23,6 +23,7 @@ use actix_web::{
|
||||
HttpServer,
|
||||
};
|
||||
//use awc::Client;
|
||||
use cache_buster::Files as FileMap;
|
||||
use lazy_static::lazy_static;
|
||||
use log::info;
|
||||
|
||||
@@ -32,7 +33,7 @@ mod errors;
|
||||
mod api;
|
||||
mod docs;
|
||||
mod settings;
|
||||
//mod templates;
|
||||
mod templates;
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
mod tests;
|
||||
@@ -46,6 +47,11 @@ lazy_static! {
|
||||
|
||||
// pub static ref OPEN_API_DOC: String = env::var("OPEN_API_DOCS").unwrap();
|
||||
pub static ref S: String = env::var("S").unwrap();
|
||||
|
||||
pub static ref FILES: FileMap = FileMap::load();
|
||||
pub static ref JS: &'static str = FILES.get("./static/bundle/main.js").unwrap();
|
||||
pub static ref CSS: &'static str = FILES.get("./static/bundle/main.css").unwrap();
|
||||
|
||||
}
|
||||
|
||||
pub static OPEN_API_DOC: &str = env!("OPEN_API_DOCS");
|
||||
@@ -84,8 +90,9 @@ async fn main() -> std::io::Result<()> {
|
||||
))
|
||||
.configure(v1::services)
|
||||
.configure(docs::services)
|
||||
.configure(templates::services)
|
||||
.app_data(get_json_err())
|
||||
.service(Files::new("/", "./frontend/dist").index_file("index.html"))
|
||||
.service(Files::new("/", "./prod"))
|
||||
})
|
||||
.bind(SETTINGS.server.get_ip())
|
||||
.unwrap()
|
||||
|
||||
34
src/templates/auth/login.rs
Normal file
34
src/templates/auth/login.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use actix_web::{get, HttpResponse, Responder};
|
||||
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
#[derive(Clone, TemplateOnce)]
|
||||
#[template(path = "auth/login/index.html")]
|
||||
struct IndexPage {
|
||||
name: String,
|
||||
title: String,
|
||||
}
|
||||
|
||||
impl Default for IndexPage {
|
||||
fn default() -> Self {
|
||||
IndexPage {
|
||||
name: "mCaptcha".into(),
|
||||
title: "Login".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexPage {
|
||||
pub fn run(&self) -> Result<String, &'static str> {
|
||||
let index = self.clone().render_once().unwrap();
|
||||
Ok(index)
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
pub async fn login() -> impl Responder {
|
||||
let body = IndexPage::default().run().unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body)
|
||||
}
|
||||
2
src/templates/auth/mod.rs
Normal file
2
src/templates/auth/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod login;
|
||||
pub mod register;
|
||||
34
src/templates/auth/register.rs
Normal file
34
src/templates/auth/register.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use actix_web::{get, HttpResponse, Responder};
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
#[derive(TemplateOnce, Clone)]
|
||||
#[template(path = "auth/register/index.html")]
|
||||
pub struct IndexPage {
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
}
|
||||
|
||||
impl Default for IndexPage {
|
||||
fn default() -> Self {
|
||||
IndexPage {
|
||||
name: "mCaptcha".into(),
|
||||
title: "Join".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexPage {
|
||||
pub fn run(&self) -> Result<String, &'static str> {
|
||||
let index = self.clone().render_once().unwrap();
|
||||
|
||||
Ok(index)
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/join")]
|
||||
pub async fn join() -> impl Responder {
|
||||
let body = IndexPage::default().run().unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body)
|
||||
}
|
||||
@@ -17,8 +17,11 @@
|
||||
|
||||
use actix_web::web::ServiceConfig;
|
||||
|
||||
mod routes;
|
||||
mod auth;
|
||||
mod panel;
|
||||
|
||||
pub fn services(cfg: &mut ServiceConfig) {
|
||||
cfg.service(routes::login);
|
||||
cfg.service(auth::login::login);
|
||||
cfg.service(auth::register::join);
|
||||
cfg.service(panel::panel);
|
||||
}
|
||||
|
||||
35
src/templates/panel/mod.rs
Normal file
35
src/templates/panel/mod.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use actix_web::{get, HttpResponse, Responder};
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
#[derive(TemplateOnce, Clone)]
|
||||
#[template(path = "panel/index.html")]
|
||||
pub struct IndexPage {
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
}
|
||||
|
||||
const TITLE: &str = "Dashboard";
|
||||
|
||||
impl Default for IndexPage {
|
||||
fn default() -> Self {
|
||||
IndexPage {
|
||||
name: "mCaptcha".into(),
|
||||
title: "Home".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexPage {
|
||||
pub fn run(&self) -> Result<String, &'static str> {
|
||||
let index = self.clone().render_once().unwrap();
|
||||
Ok(index)
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/panel")]
|
||||
pub async fn panel() -> impl Responder {
|
||||
let body = IndexPage::default().run().unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body)
|
||||
}
|
||||
@@ -16,19 +16,13 @@
|
||||
*/
|
||||
|
||||
use sailfish::TemplateOnce;
|
||||
//use au
|
||||
|
||||
#[derive(TemplateOnce, Default)]
|
||||
#[template(path = "signin.stpl")]
|
||||
struct SignIn;
|
||||
|
||||
use actix_web::{get, post, web, HttpResponse, Responder};
|
||||
//use awc::Client;
|
||||
|
||||
#[get("/login/")]
|
||||
pub async fn login() -> impl Responder {
|
||||
let body = SignIn::default().render_once().unwrap();
|
||||
// .map_err(|_| ServiceError::InternalError)?;
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body)
|
||||
}
|
||||
//#[get("/")]
|
||||
//pub async fn login() -> impl Responder {
|
||||
// let body = SignIn::default().render_once().unwrap();
|
||||
// // .map_err(|_| ServiceError::InternalError)?;
|
||||
// HttpResponse::Ok()
|
||||
// .content_type("text/html; charset=utf-8")
|
||||
// .body(body)
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user