login page

This commit is contained in:
realaravinth
2021-03-30 13:47:42 +05:30
parent 79348eaf85
commit 76b9f11430
12 changed files with 539 additions and 15 deletions

View File

@@ -22,6 +22,10 @@ pub mod mcaptcha;
pub mod meta;
pub fn services(cfg: &mut ServiceConfig) {
// meta
cfg.service(meta::build_details);
cfg.service(meta::health);
// auth
cfg.service(auth::signout);
cfg.service(auth::signin);
@@ -53,10 +57,6 @@ pub fn services(cfg: &mut ServiceConfig) {
// pow
cfg.service(mcaptcha::pow::get_config);
// meta
cfg.service(meta::build_details);
cfg.service(meta::health);
}
#[cfg(test)]

View File

@@ -16,6 +16,7 @@
*/
use std::env;
use actix_files::Files;
use actix_identity::{CookieIdentityPolicy, IdentityService};
use actix_web::{
client::Client, error::InternalError, http::StatusCode, middleware, web::JsonConfig, App,
@@ -30,6 +31,7 @@ mod errors;
//mod routes;
mod api;
mod settings;
//mod templates;
#[cfg(test)]
#[macro_use]
mod tests;
@@ -65,14 +67,17 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
let client = Client::default();
App::new()
.configure(v1_services)
.wrap(middleware::Logger::default())
.wrap(get_identity_service())
.wrap(middleware::Compress::default())
.data(data.clone())
.data(client.clone())
.wrap(middleware::NormalizePath::default())
.wrap(middleware::NormalizePath::new(
middleware::normalize::TrailingSlash::Trim,
))
.app_data(get_json_err())
.configure(v1_services)
.service(Files::new("/", "./static"))
})
.bind(SETTINGS.server.get_ip())
.unwrap()

24
src/templates/mod.rs Normal file
View File

@@ -0,0 +1,24 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use actix_web::web::ServiceConfig;
mod routes;
pub fn services(cfg: &mut ServiceConfig) {
cfg.service(routes::login);
}

34
src/templates/routes.rs Normal file
View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use sailfish::TemplateOnce;
#[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)
}