From 53cb8080831428ffb492dba40c6f929f46a5cea5 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Tue, 8 Mar 2022 08:43:46 +0530 Subject: [PATCH] feat: demo user banner on login and register pages --- src/pages/auth/mod.rs | 3 ++- src/pages/mod.rs | 6 ++++++ src/settings.rs | 16 ++++++++-------- static/cache/css/main.css | 22 ++++++++++++++++++---- templates/pages/auth/demo.html | 11 +++++++++++ templates/pages/auth/login.html | 2 +- templates/pages/auth/register.html | 2 +- 7 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 templates/pages/auth/demo.html diff --git a/src/pages/auth/mod.rs b/src/pages/auth/mod.rs index f40fc8c..00e59f8 100644 --- a/src/pages/auth/mod.rs +++ b/src/pages/auth/mod.rs @@ -25,9 +25,10 @@ pub mod register; mod test; pub const AUTH_BASE: TemplateFile = TemplateFile::new("authbase", "pages/auth/base.html"); +pub const DEMO: TemplateFile = TemplateFile::new("demo_banner", "pages/auth/demo.html"); pub fn register_templates(t: &mut tera::Tera) { - for template in [AUTH_BASE, login::LOGIN, register::REGISTER].iter() { + for template in [AUTH_BASE, login::LOGIN, register::REGISTER, DEMO].iter() { template.register(t).expect(template.name); } } diff --git a/src/pages/mod.rs b/src/pages/mod.rs index 4948086..3171bd5 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -117,6 +117,9 @@ pub struct Footer<'a> { admin_email: &'a str, source_code: &'a str, git_hash: &'a str, + settings: &'a Settings, + demo_user: &'a str, + demo_password: &'a str, } impl<'a> Footer<'a> { @@ -126,6 +129,9 @@ impl<'a> Footer<'a> { source_code: &settings.source_code, admin_email: &settings.admin_email, git_hash: &GIT_COMMIT_HASH[..8], + demo_user: crate::demo::DEMO_USER, + demo_password: crate::demo::DEMO_PASSWORD, + settings, } } } diff --git a/src/settings.rs b/src/settings.rs index 56e8060..7477aba 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -20,11 +20,11 @@ use std::{env, fs}; use config::{Config, ConfigError, Environment, File}; use derive_more::Display; use log::warn; -use serde::Deserialize; +use serde::*; use url::Url; use validator::Validate; -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Server { pub port: u32, pub domain: String, @@ -41,7 +41,7 @@ impl Server { } } -#[derive(Deserialize, Display, Clone, Debug)] +#[derive(Serialize, Deserialize, Display, Clone, Debug)] #[serde(rename_all = "lowercase")] pub enum LogLevel { #[display(fmt = "debug")] @@ -65,7 +65,7 @@ impl LogLevel { } } -#[derive(Debug, Clone, Deserialize)] +#[derive(Serialize, Debug, Clone, Deserialize)] pub struct Repository { pub root: String, } @@ -84,7 +84,7 @@ impl Repository { } } -#[derive(Deserialize, Display, PartialEq, Clone, Debug)] +#[derive(Deserialize, Serialize, Display, PartialEq, Clone, Debug)] #[serde(rename_all = "lowercase")] pub enum DBType { #[display(fmt = "postgres")] @@ -103,7 +103,7 @@ impl DBType { } } -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone, Deserialize, Serialize)] struct DatabaseBuilder { pub port: u32, pub hostname: String, @@ -131,14 +131,14 @@ impl DatabaseBuilder { } } -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone, Deserialize, Serialize)] pub struct Database { pub url: String, pub pool: u32, pub database_type: DBType, } -#[derive(Debug, Validate, Clone, Deserialize)] +#[derive(Debug, Validate, Clone, Deserialize, Serialize)] pub struct Settings { pub log: LogLevel, pub database: Database, diff --git a/static/cache/css/main.css b/static/cache/css/main.css index 15262c7..7d68123 100644 --- a/static/cache/css/main.css +++ b/static/cache/css/main.css @@ -8,20 +8,24 @@ html { color: #333; } -h1, h2, h3, h4, h5, h6 { +h1, +h2, +h3, +h4, +h5, +h6 { font-family: Arial, Helvetica, sans-serif; font-weight: 500; } h1 { - font-size: 2.0rem; + font-size: 2rem; } h2 { font-size: 1.5rem; } - body { width: 100%; min-height: 100vh; @@ -227,7 +231,6 @@ footer { height: 320px; } - .gist__button-group { display: flex; width: 100%; @@ -249,3 +252,14 @@ footer { cursor: pointer; background-color: #e9e9ed; } + +.auth__demo-user__banner { + margin: auto; + margin-top: 5px; + font-size: 0.8rem; + text-align: center; +} + +.auth__demo-user__cred { + font-family: monospace, monospace; +} diff --git a/templates/pages/auth/demo.html b/templates/pages/auth/demo.html new file mode 100644 index 0000000..f322944 --- /dev/null +++ b/templates/pages/auth/demo.html @@ -0,0 +1,11 @@ +{% if footer.settings.allow_demo %} +

+ Try Kaizen without joining
+ + user: {{ footer.demo_user }} + + + password: {{ footer.demo_password }} + +

+{% endif %} diff --git a/templates/pages/auth/login.html b/templates/pages/auth/login.html index 0f91de1..6236989 100644 --- a/templates/pages/auth/login.html +++ b/templates/pages/auth/login.html @@ -31,7 +31,6 @@ {% endif %} /> -
Forgot password? @@ -42,4 +41,5 @@ New to GitPad? Create an account

+{% include "demo_banner" %} {% endblock %} diff --git a/templates/pages/auth/register.html b/templates/pages/auth/register.html index b8b9255..5a3b17a 100644 --- a/templates/pages/auth/register.html +++ b/templates/pages/auth/register.html @@ -60,7 +60,6 @@ {% endif %} /> -
Forgot password? @@ -71,4 +70,5 @@ Already have an account? Login

+{% include "demo_banner" %} {% endblock %}