mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
frontend: logout and add sitekey
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use actix_identity::Identity;
|
use actix_identity::Identity;
|
||||||
|
use actix_web::http::header;
|
||||||
use actix_web::{get, post, web, HttpResponse, Responder};
|
use actix_web::{get, post, web, HttpResponse, Responder};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -246,12 +247,14 @@ pub async fn set_email(
|
|||||||
Ok(HttpResponse::Ok())
|
Ok(HttpResponse::Ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/api/v1/signout")]
|
#[get("/logout")]
|
||||||
pub async fn signout(id: Identity) -> impl Responder {
|
pub async fn signout(id: Identity) -> impl Responder {
|
||||||
if let Some(_) = id.identity() {
|
if let Some(_) = id.identity() {
|
||||||
id.forget();
|
id.forget();
|
||||||
}
|
}
|
||||||
HttpResponse::Ok()
|
HttpResponse::TemporaryRedirect()
|
||||||
|
.set_header(header::LOCATION, "/login")
|
||||||
|
.body("")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if user is authenticated
|
/// Check if user is authenticated
|
||||||
|
|||||||
@@ -124,13 +124,13 @@ async fn auth_works() {
|
|||||||
// 5. signout
|
// 5. signout
|
||||||
let signout_resp = test::call_service(
|
let signout_resp = test::call_service(
|
||||||
&mut app,
|
&mut app,
|
||||||
test::TestRequest::post()
|
test::TestRequest::get()
|
||||||
.uri("/api/v1/signout")
|
.uri("/logout")
|
||||||
.cookie(cookies)
|
.cookie(cookies)
|
||||||
.to_request(),
|
.to_request(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(signout_resp.status(), StatusCode::OK);
|
assert_eq!(signout_resp.status(), StatusCode::TEMPORARY_REDIRECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
|||||||
@@ -20,30 +20,23 @@ use sailfish::TemplateOnce;
|
|||||||
|
|
||||||
#[derive(Clone, TemplateOnce)]
|
#[derive(Clone, TemplateOnce)]
|
||||||
#[template(path = "auth/login/index.html")]
|
#[template(path = "auth/login/index.html")]
|
||||||
struct IndexPage {
|
struct IndexPage<'a> {
|
||||||
name: String,
|
name: &'a str,
|
||||||
title: String,
|
title: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for IndexPage {
|
impl<'a> Default for IndexPage<'a> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
IndexPage {
|
IndexPage {
|
||||||
name: "mCaptcha".into(),
|
name: "mCaptcha",
|
||||||
title: "Login".into(),
|
title: "Login",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IndexPage {
|
#[get("/login")]
|
||||||
pub fn run(&self) -> Result<String, &'static str> {
|
|
||||||
let index = self.clone().render_once().unwrap();
|
|
||||||
Ok(index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/")]
|
|
||||||
pub async fn login() -> impl Responder {
|
pub async fn login() -> impl Responder {
|
||||||
let body = IndexPage::default().run().unwrap();
|
let body = IndexPage::default().render_once().unwrap();
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("text/html; charset=utf-8")
|
.content_type("text/html; charset=utf-8")
|
||||||
.body(body)
|
.body(body)
|
||||||
|
|||||||
@@ -20,31 +20,23 @@ use sailfish::TemplateOnce;
|
|||||||
|
|
||||||
#[derive(TemplateOnce, Clone)]
|
#[derive(TemplateOnce, Clone)]
|
||||||
#[template(path = "auth/register/index.html")]
|
#[template(path = "auth/register/index.html")]
|
||||||
pub struct IndexPage {
|
struct IndexPage<'a> {
|
||||||
pub name: String,
|
name: &'a str,
|
||||||
pub title: String,
|
title: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for IndexPage {
|
impl<'a> Default for IndexPage<'a> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
IndexPage {
|
IndexPage {
|
||||||
name: "mCaptcha".into(),
|
name: "mCaptcha",
|
||||||
title: "Join".into(),
|
title: "Join",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IndexPage {
|
|
||||||
pub fn run(&self) -> Result<String, &'static str> {
|
|
||||||
let index = self.clone().render_once().unwrap();
|
|
||||||
|
|
||||||
Ok(index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/join")]
|
#[get("/join")]
|
||||||
pub async fn join() -> impl Responder {
|
pub async fn join() -> impl Responder {
|
||||||
let body = IndexPage::default().run().unwrap();
|
let body = IndexPage::default().render_once().unwrap();
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("text/html; charset=utf-8")
|
.content_type("text/html; charset=utf-8")
|
||||||
.body(body)
|
.body(body)
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ mod panel;
|
|||||||
pub fn services(cfg: &mut ServiceConfig) {
|
pub fn services(cfg: &mut ServiceConfig) {
|
||||||
cfg.service(auth::login::login);
|
cfg.service(auth::login::login);
|
||||||
cfg.service(auth::register::join);
|
cfg.service(auth::register::join);
|
||||||
|
|
||||||
|
// panel
|
||||||
cfg.service(panel::panel);
|
cfg.service(panel::panel);
|
||||||
|
cfg.service(panel::sitekey::add_sitekey);
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[cfg(not(tarpaulin_include))]
|
//#[cfg(not(tarpaulin_include))]
|
||||||
|
|||||||
@@ -15,37 +15,42 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* 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 actix_web::{get, HttpResponse, Responder};
|
||||||
use sailfish::TemplateOnce;
|
use sailfish::TemplateOnce;
|
||||||
|
|
||||||
|
use crate::api::v1::auth::is_authenticated;
|
||||||
|
|
||||||
|
pub mod sitekey;
|
||||||
|
|
||||||
#[derive(TemplateOnce, Clone)]
|
#[derive(TemplateOnce, Clone)]
|
||||||
#[template(path = "panel/index.html")]
|
#[template(path = "panel/index.html")]
|
||||||
pub struct IndexPage {
|
pub struct IndexPage<'a> {
|
||||||
pub name: String,
|
pub name: &'a str,
|
||||||
pub title: String,
|
pub title: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
const TITLE: &str = "Dashboard";
|
const TITLE: &str = "Dashboard";
|
||||||
|
|
||||||
impl Default for IndexPage {
|
impl<'a> Default for IndexPage<'a> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
IndexPage {
|
IndexPage {
|
||||||
name: "mCaptcha".into(),
|
name: "mCaptcha",
|
||||||
title: "Home".into(),
|
title: TITLE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IndexPage {
|
#[get("/")]
|
||||||
pub fn run(&self) -> Result<String, &'static str> {
|
pub async fn panel(id: Identity) -> impl Responder {
|
||||||
let index = self.clone().render_once().unwrap();
|
if is_authenticated(&id).is_err() {
|
||||||
Ok(index)
|
return HttpResponse::TemporaryRedirect()
|
||||||
|
.set_header(header::LOCATION, "/login")
|
||||||
|
.body("");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/panel")]
|
let body = IndexPage::default().render_once().unwrap();
|
||||||
pub async fn panel() -> impl Responder {
|
|
||||||
let body = IndexPage::default().run().unwrap();
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("text/html; charset=utf-8")
|
.content_type("text/html; charset=utf-8")
|
||||||
.body(body)
|
.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;
|
padding: 0;
|
||||||
margin: 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 login from './auth/login';
|
||||||
import * as register from './auth/register';
|
import * as register from './auth/register';
|
||||||
import * as panel from './panel/index';
|
import * as panel from './panel/index';
|
||||||
|
import './auth/forms.scss';
|
||||||
|
import './panel/main.scss';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
router.register('/', login.index);
|
router.register('/', login.index);
|
||||||
router.register('/join', register.index);
|
router.register('/register', register.index);
|
||||||
router.register('/panel/', panel.index);
|
router.register('/panel/', panel.index);
|
||||||
router.register('/panel/layout.html/', 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">
|
<. include!("../../components/headers.html"); .> <. include!("../header/index.html");
|
||||||
<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">
|
<main>
|
||||||
<!-- insert Javascript for adding more levels as needed -->
|
<. include!("../taskbar/index.html"); .> <.
|
||||||
<label class="sitekey-form__label" for="level1">Level 1</label>
|
include!("../help-banner/index.html"); .>
|
||||||
|
<!-- Main content container -->
|
||||||
|
<div class="inner-container">
|
||||||
|
<!-- Main menu/ important actions roaster -->
|
||||||
|
|
||||||
|
<. include!("../add-site-key/form.html"); .>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- end of container -->
|
||||||
<input
|
</main>
|
||||||
class="sitekey-form__input"
|
<. include!("../../components/footers.html"); .>
|
||||||
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>
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<li class="secondary-menu__section-partition"></li>
|
<li class="secondary-menu__section-partition"></li>
|
||||||
-->
|
-->
|
||||||
<li class="secondary-menu__item">
|
<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="" />
|
<img class="secondary-menu__icon" src="<.= crate::FILES.get("./static/img/svg/home.svg").unwrap() .>" alt="" />
|
||||||
<div class="secondary-menu__item-name">
|
<div class="secondary-menu__item-name">
|
||||||
Overview
|
Overview
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="secondary-menu__item">
|
<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="" />
|
<img class="secondary-menu__icon" src="<.= crate::FILES.get("./static/img/svg/key.svg").unwrap() .>" alt="" />
|
||||||
<div class="secondary-menu__item-name">
|
<div class="secondary-menu__item-name">
|
||||||
Site Keys
|
Site Keys
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
<div class="inner-container">
|
<div class="inner-container">
|
||||||
<!-- Main menu/ important actions roaster -->
|
<!-- Main menu/ important actions roaster -->
|
||||||
|
|
||||||
<. include!("./add-site-key/index.html"); .>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- end of container -->
|
<!-- end of container -->
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ main {
|
|||||||
margin: auto 20px;
|
margin: auto 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.task-bar__icon {
|
||||||
|
color: $light-text;
|
||||||
|
}
|
||||||
|
|
||||||
.task-bar__icon:hover {
|
.task-bar__icon:hover {
|
||||||
cursor: grab;
|
cursor: grab;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,11 @@
|
|||||||
-->
|
-->
|
||||||
<li class="task-bar__spacer"></li>
|
<li class="task-bar__spacer"></li>
|
||||||
<li class="task-bar__action">
|
<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>
|
||||||
<li class="task-bar__action">
|
<li class="task-bar__action">
|
||||||
<img class="task-bar__icon" src="<.=
|
<img class="task-bar__icon" src="<.=
|
||||||
@@ -13,11 +17,14 @@
|
|||||||
|
|
||||||
<li class="task-bar__action">
|
<li class="task-bar__action">
|
||||||
<img class="task-bar__icon" src="<.=
|
<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>
|
||||||
|
|
||||||
<li class="task-bar__action">
|
<li class="task-bar__action">
|
||||||
|
<a href="/logout">
|
||||||
<img class="task-bar__icon" src="<.=
|
<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>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user