diff --git a/src/data.rs b/src/data.rs index 80c51876..bc998d38 100644 --- a/src/data.rs +++ b/src/data.rs @@ -16,6 +16,7 @@ */ //! App data: redis cache, database connections, etc. use std::sync::Arc; +use std::thread; use actix::prelude::*; use argon2_creds::{Config, ConfigBuilder, PasswordPolicy}; @@ -145,12 +146,6 @@ impl Data { #[cfg(not(tarpaulin_include))] /// create new instance of app data pub async fn new() -> Arc { - let db = PgPoolOptions::new() - .max_connections(SETTINGS.database.pool) - .connect(&SETTINGS.database.url) - .await - .expect("Unable to form database pool"); - let creds = ConfigBuilder::default() .username_case_mapped(true) .profanity(true) @@ -159,9 +154,19 @@ impl Data { .build() .unwrap(); - log::info!("Initializing credential manager"); - //creds.init(); - log::info!("Initialized credential manager"); + let c = creds.clone(); + + let init = thread::spawn(move || { + log::info!("Initializing credential manager"); + c.init(); + log::info!("Initialized credential manager"); + }); + + let db = PgPoolOptions::new() + .max_connections(SETTINGS.database.pool) + .connect(&SETTINGS.database.url) + .await + .expect("Unable to form database pool"); let data = Data { creds, @@ -170,6 +175,8 @@ impl Data { mailer: Self::get_mailer(), }; + init.join().unwrap(); + Arc::new(data) } diff --git a/src/email/verification.rs b/src/email/verification.rs index 5e4eed2e..2bef92e6 100644 --- a/src/email/verification.rs +++ b/src/email/verification.rs @@ -112,7 +112,8 @@ mod tests { .unwrap(); let client = Client::default(); - let mut resp = client.get("http://localhost:1080/email") + let mut resp = client + .get("http://localhost:1080/email") .send() .await .unwrap(); @@ -120,7 +121,8 @@ mod tests { let data = &data[0]; let smtp = SETTINGS.smtp.as_ref().unwrap(); - let from_addr = &data["headers"]["from"];["address"]; + let from_addr = &data["headers"]["from"]; + ["address"]; assert!(from_addr.to_string().contains(&smtp.from)); diff --git a/src/pages/auth/email_verify.rs b/src/pages/auth/email_verify.rs new file mode 100644 index 00000000..fd537e6b --- /dev/null +++ b/src/pages/auth/email_verify.rs @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 Aravinth Manivannan + * + * 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 . + */ + +//! Email operations: verification, notification, etc +use lettre::{ + message::{header, MultiPart, SinglePart}, + AsyncTransport, Message, +}; +use sailfish::TemplateOnce; + +use crate::errors::*; +use crate::Data; +use crate::SETTINGS; + +const PAGE: &str = "Login"; + +#[derive(Clone, Default, TemplateOnce)] +#[template(path = "auth/email-verification/index.html")] +struct IndexPage { + email: String, +} + + +lazy_static! { + static ref INDEX: String = IndexPage::default().render_once().unwrap(); +} + +#[get(path = "PAGES.auth.login")] +pub async fn email_verification() -> impl Responder { + HttpResponse::Ok() + .content_type("text/html; charset=utf-8") + .body(&*INDEX) +} + +//TODO +// Design cookie system to handle registration to showing this page, +// verifying email and discarding the cookie diff --git a/templates/auth/email-verification/index.html b/templates/auth/email-verification/index.html new file mode 100644 index 00000000..c4a3c5f4 --- /dev/null +++ b/templates/auth/email-verification/index.html @@ -0,0 +1,28 @@ +<. include!("../../components/headers/index.html"); .> +
+
+
+ + " + class="auth__logo" alt="mcaptcha logo" /> + +
+

+ Please verify your email address to continue +

+ An email has been sent to + +
+

+ New to mCaptcha? + + Create an account + +

+
+<. include!("../../components/footers.html"); .> diff --git a/templates/auth/email-verification/index.ts b/templates/auth/email-verification/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/templates/auth/email-verification/main.scss b/templates/auth/email-verification/main.scss new file mode 100644 index 00000000..e69de29b diff --git a/templates/components/headers/csp.html b/templates/components/headers/csp.html index b53d1641..8e1e2de9 100644 --- a/templates/components/headers/csp.html +++ b/templates/components/headers/csp.html @@ -1,4 +1,6 @@ + diff --git a/templates/email/verification/index.html b/templates/email/verification/index.html index a318d10a..71bae108 100644 --- a/templates/email/verification/index.html +++ b/templates/email/verification/index.html @@ -20,9 +20,16 @@

Please verify your email address to continue.

- +
+ +

If you were not able to see the verification button, click the following diff --git a/templates/main.scss b/templates/main.scss index c487c4d8..ec66d6d0 100644 --- a/templates/main.scss +++ b/templates/main.scss @@ -48,7 +48,7 @@ nav { /* needed for the floated layout */ clear: both; grid-area: navbar; - height: 100%; +// height: 100%; } .tmp-layout { diff --git a/templates/panel/index.html b/templates/panel/index.html index 3c9f5f54..51387c50 100644 --- a/templates/panel/index.html +++ b/templates/panel/index.html @@ -10,7 +10,7 @@

    It looks like you don't have any sitekeys. Click - here> to add new sitekey. + here to add new sitekey.

diff --git a/templates/panel/navbar/index.html b/templates/panel/navbar/index.html index 4256ecbc..78e2dad4 100644 --- a/templates/panel/navbar/index.html +++ b/templates/panel/navbar/index.html @@ -1,12 +1,18 @@