frontend: logout and add sitekey
This commit is contained in:
parent
a5cfa3b305
commit
6e63771868
17 changed files with 255 additions and 104 deletions
|
@ -17,6 +17,7 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use actix_identity::Identity;
|
||||
use actix_web::http::header;
|
||||
use actix_web::{get, post, web, HttpResponse, Responder};
|
||||
use log::debug;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -246,12 +247,14 @@ pub async fn set_email(
|
|||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
#[post("/api/v1/signout")]
|
||||
#[get("/logout")]
|
||||
pub async fn signout(id: Identity) -> impl Responder {
|
||||
if let Some(_) = id.identity() {
|
||||
id.forget();
|
||||
}
|
||||
HttpResponse::Ok()
|
||||
HttpResponse::TemporaryRedirect()
|
||||
.set_header(header::LOCATION, "/login")
|
||||
.body("")
|
||||
}
|
||||
|
||||
/// Check if user is authenticated
|
||||
|
|
|
@ -124,13 +124,13 @@ async fn auth_works() {
|
|||
// 5. signout
|
||||
let signout_resp = test::call_service(
|
||||
&mut app,
|
||||
test::TestRequest::post()
|
||||
.uri("/api/v1/signout")
|
||||
test::TestRequest::get()
|
||||
.uri("/logout")
|
||||
.cookie(cookies)
|
||||
.to_request(),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(signout_resp.status(), StatusCode::OK);
|
||||
assert_eq!(signout_resp.status(), StatusCode::TEMPORARY_REDIRECT);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
|
|
|
@ -20,30 +20,23 @@ use sailfish::TemplateOnce;
|
|||
|
||||
#[derive(Clone, TemplateOnce)]
|
||||
#[template(path = "auth/login/index.html")]
|
||||
struct IndexPage {
|
||||
name: String,
|
||||
title: String,
|
||||
struct IndexPage<'a> {
|
||||
name: &'a str,
|
||||
title: &'a str,
|
||||
}
|
||||
|
||||
impl Default for IndexPage {
|
||||
impl<'a> Default for IndexPage<'a> {
|
||||
fn default() -> Self {
|
||||
IndexPage {
|
||||
name: "mCaptcha".into(),
|
||||
title: "Login".into(),
|
||||
name: "mCaptcha",
|
||||
title: "Login",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexPage {
|
||||
pub fn run(&self) -> Result<String, &'static str> {
|
||||
let index = self.clone().render_once().unwrap();
|
||||
Ok(index)
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
#[get("/login")]
|
||||
pub async fn login() -> impl Responder {
|
||||
let body = IndexPage::default().run().unwrap();
|
||||
let body = IndexPage::default().render_once().unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body)
|
||||
|
|
|
@ -20,31 +20,23 @@ use sailfish::TemplateOnce;
|
|||
|
||||
#[derive(TemplateOnce, Clone)]
|
||||
#[template(path = "auth/register/index.html")]
|
||||
pub struct IndexPage {
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
struct IndexPage<'a> {
|
||||
name: &'a str,
|
||||
title: &'a str,
|
||||
}
|
||||
|
||||
impl Default for IndexPage {
|
||||
impl<'a> Default for IndexPage<'a> {
|
||||
fn default() -> Self {
|
||||
IndexPage {
|
||||
name: "mCaptcha".into(),
|
||||
title: "Join".into(),
|
||||
name: "mCaptcha",
|
||||
title: "Join",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
let body = IndexPage::default().render_once().unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body)
|
||||
|
|
|
@ -23,7 +23,10 @@ mod panel;
|
|||
pub fn services(cfg: &mut ServiceConfig) {
|
||||
cfg.service(auth::login::login);
|
||||
cfg.service(auth::register::join);
|
||||
|
||||
// panel
|
||||
cfg.service(panel::panel);
|
||||
cfg.service(panel::sitekey::add_sitekey);
|
||||
}
|
||||
|
||||
//#[cfg(not(tarpaulin_include))]
|
||||
|
|
|
@ -15,37 +15,42 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use actix_identity::Identity;
|
||||
use actix_web::http::header;
|
||||
use actix_web::{get, HttpResponse, Responder};
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
use crate::api::v1::auth::is_authenticated;
|
||||
|
||||
pub mod sitekey;
|
||||
|
||||
#[derive(TemplateOnce, Clone)]
|
||||
#[template(path = "panel/index.html")]
|
||||
pub struct IndexPage {
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
pub struct IndexPage<'a> {
|
||||
pub name: &'a str,
|
||||
pub title: &'a str,
|
||||
}
|
||||
|
||||
const TITLE: &str = "Dashboard";
|
||||
|
||||
impl Default for IndexPage {
|
||||
impl<'a> Default for IndexPage<'a> {
|
||||
fn default() -> Self {
|
||||
IndexPage {
|
||||
name: "mCaptcha".into(),
|
||||
title: "Home".into(),
|
||||
name: "mCaptcha",
|
||||
title: TITLE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexPage {
|
||||
pub fn run(&self) -> Result<String, &'static str> {
|
||||
let index = self.clone().render_once().unwrap();
|
||||
Ok(index)
|
||||
#[get("/")]
|
||||
pub async fn panel(id: Identity) -> impl Responder {
|
||||
if is_authenticated(&id).is_err() {
|
||||
return HttpResponse::TemporaryRedirect()
|
||||
.set_header(header::LOCATION, "/login")
|
||||
.body("");
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/panel")]
|
||||
pub async fn panel() -> impl Responder {
|
||||
let body = IndexPage::default().run().unwrap();
|
||||
let body = IndexPage::default().render_once().unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body)
|
||||
|
|
45
src/templates/panel/sitekey.rs
Normal file
45
src/templates/panel/sitekey.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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::{get, HttpResponse, Responder};
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
#[derive(TemplateOnce, Clone)]
|
||||
#[template(path = "panel/add-site-key/index.html")]
|
||||
pub struct IndexPage<'a> {
|
||||
pub name: &'a str,
|
||||
pub title: &'a str,
|
||||
}
|
||||
|
||||
const TITLE: &str = "Add Site Key";
|
||||
|
||||
impl<'a> Default for IndexPage<'a> {
|
||||
fn default() -> Self {
|
||||
IndexPage {
|
||||
name: "mCaptcha",
|
||||
title: TITLE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/sitekey/add")]
|
||||
pub async fn add_sitekey() -> impl Responder {
|
||||
let body = IndexPage::default().render_once().unwrap();
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(body)
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2,3 +2,8 @@
|
|||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ import {Router} from './router';
|
|||
import * as login from './auth/login';
|
||||
import * as register from './auth/register';
|
||||
import * as panel from './panel/index';
|
||||
import './auth/forms.scss';
|
||||
import './panel/main.scss';
|
||||
|
||||
const router = new Router();
|
||||
|
||||
router.register('/', login.index);
|
||||
router.register('/join', register.index);
|
||||
router.register('/register', register.index);
|
||||
router.register('/panel/', panel.index);
|
||||
router.register('/panel/layout.html/', panel.index);
|
||||
|
||||
|
|
48
templates/panel/add-site-key/form.html
Normal file
48
templates/panel/add-site-key/form.html
Normal file
|
@ -0,0 +1,48 @@
|
|||
<form class="sitekey-form" action="/something" method="post">
|
||||
<div class="sitekey-form__title-flex-container">
|
||||
<b class="sitekey-form__title">Add Site Key</b>
|
||||
</div>
|
||||
<div class="sitekey-form__add-level-flex-container">
|
||||
<label class="sitekey-form__label" for="description">Description</label>
|
||||
</div>
|
||||
<input
|
||||
class="sitekey-form__input"
|
||||
type="text/"
|
||||
name="description"
|
||||
id="description"
|
||||
value=""
|
||||
/>
|
||||
|
||||
<div class="sitekey-form__add-level-flex-container">
|
||||
<!-- insert Javascript for adding more levels as needed -->
|
||||
<label class="sitekey-form__label" for="level1">Level 1</label>
|
||||
</div>
|
||||
|
||||
<input
|
||||
class="sitekey-form__input"
|
||||
type="text/"
|
||||
name="level1"
|
||||
id="level1"
|
||||
value=""
|
||||
/>
|
||||
|
||||
<div class="sitekey-form__add-level-flex-container">
|
||||
<label class="sitekey-form__label" for="level1">Level 2</label>
|
||||
</div>
|
||||
|
||||
<div class="sitekey-form__add-level-flex-container">
|
||||
<!--
|
||||
<div class="sitekey-form__add-level-spacer"></div>
|
||||
-->
|
||||
<input
|
||||
class="sitekey-form__input--add-level"
|
||||
type="text/"
|
||||
name="level2"
|
||||
id="level2"
|
||||
value=""
|
||||
/>
|
||||
|
||||
<button class="sitekey-form__add-level">Add Level</button>
|
||||
</div>
|
||||
<button class="sitekey-form__submit" type="submit">Submit</button>
|
||||
</form>
|
|
@ -1,48 +1,15 @@
|
|||
<form class="sitekey-form" action="/something" method="post">
|
||||
<div class="sitekey-form__title-flex-container">
|
||||
<b class="sitekey-form__title">Add Site Key</b>
|
||||
</div>
|
||||
<div class="sitekey-form__add-level-flex-container">
|
||||
<label class="sitekey-form__label" for="description">Description</label>
|
||||
</div>
|
||||
<input
|
||||
class="sitekey-form__input"
|
||||
type="text/"
|
||||
name="description"
|
||||
id="description"
|
||||
value=""
|
||||
/>
|
||||
<. include!("../../components/headers.html"); .> <. include!("../header/index.html");
|
||||
.>
|
||||
|
||||
<div class="sitekey-form__add-level-flex-container">
|
||||
<!-- insert Javascript for adding more levels as needed -->
|
||||
<label class="sitekey-form__label" for="level1">Level 1</label>
|
||||
<main>
|
||||
<. include!("../taskbar/index.html"); .> <.
|
||||
include!("../help-banner/index.html"); .>
|
||||
<!-- Main content container -->
|
||||
<div class="inner-container">
|
||||
<!-- Main menu/ important actions roaster -->
|
||||
|
||||
<. include!("../add-site-key/form.html"); .>
|
||||
</div>
|
||||
|
||||
<input
|
||||
class="sitekey-form__input"
|
||||
type="text/"
|
||||
name="level1"
|
||||
id="level1"
|
||||
value=""
|
||||
/>
|
||||
|
||||
<div class="sitekey-form__add-level-flex-container">
|
||||
<label class="sitekey-form__label" for="level1">Level 2</label>
|
||||
</div>
|
||||
|
||||
<div class="sitekey-form__add-level-flex-container">
|
||||
<!--
|
||||
<div class="sitekey-form__add-level-spacer"></div>
|
||||
-->
|
||||
<input
|
||||
class="sitekey-form__input--add-level"
|
||||
type="text/"
|
||||
name="level2"
|
||||
id="level2"
|
||||
value=""
|
||||
/>
|
||||
|
||||
<button class="sitekey-form__add-level">Add Level</button>
|
||||
</div>
|
||||
<button class="sitekey-form__submit" type="submit">Submit</button>
|
||||
</form>
|
||||
<!-- end of container -->
|
||||
</main>
|
||||
<. include!("../../components/footers.html"); .>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<li class="secondary-menu__section-partition"></li>
|
||||
-->
|
||||
<li class="secondary-menu__item">
|
||||
<a class="secondary-menu__item-link" href="">
|
||||
<a class="secondary-menu__item-link" href="/panel">
|
||||
<img class="secondary-menu__icon" src="<.= crate::FILES.get("./static/img/svg/home.svg").unwrap() .>" alt="" />
|
||||
<div class="secondary-menu__item-name">
|
||||
Overview
|
||||
|
@ -19,7 +19,7 @@
|
|||
</a>
|
||||
</li>
|
||||
<li class="secondary-menu__item">
|
||||
<a class="secondary-menu__item-link" href="">
|
||||
<a class="secondary-menu__item-link" href="/panel/sitekey">
|
||||
<img class="secondary-menu__icon" src="<.= crate::FILES.get("./static/img/svg/key.svg").unwrap() .>" alt="" />
|
||||
<div class="secondary-menu__item-name">
|
||||
Site Keys
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
<div class="inner-container">
|
||||
<!-- Main menu/ important actions roaster -->
|
||||
|
||||
<. include!("./add-site-key/index.html"); .>
|
||||
</div>
|
||||
<!-- end of container -->
|
||||
</main>
|
||||
|
|
|
@ -126,6 +126,10 @@ main {
|
|||
margin: auto 20px;
|
||||
}
|
||||
|
||||
.task-bar__icon {
|
||||
color: $light-text;
|
||||
}
|
||||
|
||||
.task-bar__icon:hover {
|
||||
cursor: grab;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,11 @@
|
|||
-->
|
||||
<li class="task-bar__spacer"></li>
|
||||
<li class="task-bar__action">
|
||||
<button class="main-menu__add-site">+ New Site</button>
|
||||
<a class="task-bar__link" href="/panel/sitekey/add">
|
||||
<button class="main-menu__add-site">
|
||||
+ New Site
|
||||
</button>
|
||||
</a>
|
||||
</li>
|
||||
<li class="task-bar__action">
|
||||
<img class="task-bar__icon" src="<.=
|
||||
|
@ -13,11 +17,14 @@
|
|||
|
||||
<li class="task-bar__action">
|
||||
<img class="task-bar__icon" src="<.=
|
||||
crate::FILES.get("./static/img/svg/bell.svg").unwrap() .>" alt="Notifications" />
|
||||
crate::FILES.get("./static/img/svg/bell.svg").unwrap() .>"
|
||||
alt="Notifications" />
|
||||
</li>
|
||||
|
||||
<li class="task-bar__action">
|
||||
<a href="/logout">
|
||||
<img class="task-bar__icon" src="<.=
|
||||
crate::FILES.get("./static/img/svg/log-out.svg").unwrap() .>" alt="Profile" />
|
||||
crate::FILES.get("./static/img/svg/log-out.svg").unwrap() .>" alt="Profile"
|
||||
/></a>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue