feat: mod navbars and base templates, setup loading templates and fix
ctx loading
This commit is contained in:
parent
ac470262d1
commit
2d07f7f0ca
8 changed files with 30 additions and 55 deletions
1
Makefile
1
Makefile
|
@ -33,6 +33,7 @@ define test_workspaces
|
|||
$(call test_databases)
|
||||
$(call test_forges)
|
||||
$(call test_federation)
|
||||
DATABASE_URL=${SQLITE_DATABASE_URL}\
|
||||
cargo test --no-fail-fast
|
||||
endef
|
||||
|
||||
|
|
|
@ -64,9 +64,9 @@ async fn main() {
|
|||
pretty_env_logger::init();
|
||||
lazy_static::initialize(&pages::TEMPLATES);
|
||||
|
||||
let ctx = Ctx::new(settings.clone()).await;
|
||||
let db = sqlite::get_data(Some(settings.clone())).await;
|
||||
let federate = get_federate(Some(settings.clone())).await;
|
||||
let ctx = WebCtx::new( Ctx::new(settings.clone()).await);
|
||||
let db = WebDB::new(sqlite::get_data(Some(settings.clone())).await);
|
||||
let federate = WebFederate::new(get_federate(Some(settings.clone())).await);
|
||||
|
||||
let socket_addr = settings.server.get_ip();
|
||||
|
||||
|
|
|
@ -23,12 +23,17 @@ use tera::*;
|
|||
|
||||
use crate::settings::Settings;
|
||||
use crate::static_assets::ASSETS;
|
||||
use crate::PAGES;
|
||||
use crate::{GIT_COMMIT_HASH, VERSION};
|
||||
|
||||
pub mod auth;
|
||||
mod errors;
|
||||
pub mod routes;
|
||||
|
||||
pub use errors::ERROR_KEY;
|
||||
pub use routes::PAGES;
|
||||
|
||||
pub const TITLE_KEY: &str = "title";
|
||||
|
||||
pub struct TemplateFile {
|
||||
pub name: &'static str,
|
||||
pub path: &'static str,
|
||||
|
@ -56,15 +61,15 @@ pub const PAYLOAD_KEY: &str = "payload";
|
|||
pub const BASE: TemplateFile = TemplateFile::new("base", "components/base.html");
|
||||
pub const FOOTER: TemplateFile = TemplateFile::new("footer", "components/footer.html");
|
||||
pub const PUB_NAV: TemplateFile = TemplateFile::new("pub_nav", "components/nav/pub.html");
|
||||
pub const AUTH_NAV: TemplateFile = TemplateFile::new("auth_nav", "components/nav/auth.html");
|
||||
|
||||
lazy_static! {
|
||||
pub static ref TEMPLATES: Tera = {
|
||||
let mut tera = Tera::default();
|
||||
for t in [BASE, FOOTER, PUB_NAV, AUTH_NAV].iter() {
|
||||
for t in [BASE, FOOTER, PUB_NAV ].iter() {
|
||||
t.register(&mut tera).unwrap();
|
||||
}
|
||||
errors::register_templates(&mut tera);
|
||||
auth::register_templates(&mut tera);
|
||||
tera.autoescape_on(vec![".html", ".sql"]);
|
||||
//auth::register_templates(&mut tera);
|
||||
//gists::register_templates(&mut tera);
|
||||
|
@ -115,7 +120,9 @@ impl<'a> Footer<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {}
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
auth::services(cfg);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -129,7 +136,8 @@ mod tests {
|
|||
let mut tera2 = Tera::default();
|
||||
for t in [
|
||||
BASE, FOOTER, PUB_NAV,
|
||||
AUTH_NAV,
|
||||
auth::AUTH_CHALLENGE,
|
||||
auth::AUTH_ADD,
|
||||
// auth::AUTH_BASE,
|
||||
// auth::login::LOGIN,
|
||||
// auth::register::REGISTER,
|
||||
|
|
|
@ -25,13 +25,16 @@ pub const PAGES: Pages = Pages::new();
|
|||
pub struct Pages {
|
||||
/// home page
|
||||
pub home: &'static str,
|
||||
/// auth routes
|
||||
pub auth: Auth,
|
||||
}
|
||||
|
||||
impl Pages {
|
||||
/// create new instance of Routes
|
||||
const fn new() -> Pages {
|
||||
let home = "/";
|
||||
Pages { home }
|
||||
let auth = Auth::new();
|
||||
Pages { home, auth }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +44,7 @@ pub struct Auth {
|
|||
/// logout route
|
||||
pub logout: &'static str,
|
||||
/// login route
|
||||
pub login: &'static str,
|
||||
pub add: &'static str,
|
||||
|
||||
/// verify route
|
||||
pub verify: &'static str,
|
||||
|
@ -50,11 +53,11 @@ pub struct Auth {
|
|||
impl Auth {
|
||||
/// create new instance of Authentication route
|
||||
pub const fn new() -> Auth {
|
||||
let login = "/login";
|
||||
let add = "/add";
|
||||
let logout = "/logout";
|
||||
let verify = "/verify";
|
||||
Auth {
|
||||
login,
|
||||
add,
|
||||
logout,
|
||||
verify,
|
||||
}
|
||||
|
|
|
@ -24,8 +24,9 @@ pub use crate::db::BoxDB;
|
|||
pub use crate::federate::{get_federate, ArcFederate};
|
||||
use crate::settings::{DBType, Settings};
|
||||
|
||||
|
||||
//use actix_web::cookie::Cookie;
|
||||
use crate::errors::*;
|
||||
use crate::*;
|
||||
use actix_web::test;
|
||||
use actix_web::{
|
||||
body::{BoxBody, EitherBody},
|
||||
|
@ -34,8 +35,6 @@ use actix_web::{
|
|||
http::StatusCode,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use crate::errors::*;
|
||||
use crate::*;
|
||||
|
||||
//pub mod sqlx_postgres {
|
||||
// use super::*;
|
||||
|
@ -71,7 +70,6 @@ pub mod sqlx_sqlite {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! get_cookie {
|
||||
($resp:expr) => {
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="{{ assets.css }}" />
|
||||
<title>Gists</title>
|
||||
<title>{% block title %} {% endblock %}</title>
|
||||
<title>{% block title %} {% endblock %} | Starchart </title>
|
||||
</head>
|
||||
<body>
|
||||
<header>{% block nav %} {% endblock %}</header>
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
<nav class="nav__container">
|
||||
<input type="checkbox" class="nav__toggle" id="nav__toggle" />
|
||||
|
||||
<div class="nav__header">
|
||||
<a class="nav__logo-container" href="/">
|
||||
<p class="nav__home-btn">GitPad</p>
|
||||
</a>
|
||||
<label class="nav__hamburger-menu" for="nav__toggle">
|
||||
<span class="nav__hamburger-inner"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="nav__spacer"></div>
|
||||
|
||||
<div class="nav__link-group">
|
||||
<div class="nav__link-container">
|
||||
<a class="nav__link" rel="noreferrer" href="{{ page.gist.new }}">New Paste</a>
|
||||
</div>
|
||||
{% if loggedin_user %}
|
||||
<div class="nav__link-container">
|
||||
<a class="nav__link" rel="noreferrer" href="{{ loggedin_user }}">Profile</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="nav__link-container">
|
||||
<a class="nav__link" rel="noreferrer" href="{{ page.auth.logout }}">Log out</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<div class="nav__header">
|
||||
<a class="nav__logo-container" href="/">
|
||||
<p class="nav__home-btn">GitPad</p>
|
||||
<p class="nav__home-btn">STARCHART</p>
|
||||
</a>
|
||||
<label class="nav__hamburger-menu" for="nav__toggle">
|
||||
<span class="nav__hamburger-inner"></span>
|
||||
|
@ -14,13 +14,7 @@
|
|||
|
||||
<div class="nav__link-group">
|
||||
<div class="nav__link-container">
|
||||
<a class="nav__link" rel="noreferrer" href="/explore">Explore</a>
|
||||
</div>
|
||||
<div class="nav__link-container">
|
||||
<a class="nav__link" rel="noreferrer" href="{{ page.auth.login }}">Login</a>
|
||||
</div>
|
||||
<div class="nav__link-container">
|
||||
<a class="nav__link" rel="noreferrer" href="{{ page.auth.register }}">Register</a>
|
||||
<a class="nav__link" rel="noreferrer" href="{{ page.auth.add }}">Spider Forge</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
Loading…
Reference in a new issue