1
0
Fork 0

Created base template

Dieser Commit ist enthalten in:
Daniel García 2019-01-19 22:12:52 +01:00
Ursprung 834c847746
Commit 92bbb98d48
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: FC8A7D14C3CD543A
5 geänderte Dateien mit 180 neuen und 186 gelöschten Zeilen

Datei anzeigen

@ -21,27 +21,53 @@ pub fn routes() -> Vec<Route> {
routes![admin_login, post_admin_login, admin_page, invite_user, delete_user] routes![admin_login, post_admin_login, admin_page, invite_user, delete_user]
} }
#[derive(FromForm)]
struct LoginForm {
token: String,
}
const COOKIE_NAME: &'static str = "BWRS_ADMIN"; const COOKIE_NAME: &'static str = "BWRS_ADMIN";
const ADMIN_PATH: &'static str = "/admin"; const ADMIN_PATH: &'static str = "/admin";
#[derive(Serialize)]
struct AdminTemplateData {
users: Vec<Value>,
page_content: String,
error: Option<String>,
}
impl AdminTemplateData {
fn login(error: Option<String>) -> Self {
Self {
users: Vec::new(),
page_content: String::from("admin/admin_login"),
error,
}
}
fn admin(users: Vec<Value>) -> Self {
Self {
users,
page_content: String::from("admin/admin_page"),
error: None,
}
}
fn render(self) -> Result<String, Error> {
CONFIG.templates.render("admin/admin_base", &self).map_err(Into::into)
}
}
#[get("/", rank = 2)] #[get("/", rank = 2)]
fn admin_login(flash: Option<FlashMessage>) -> Result<Html<String>, Error> { fn admin_login(flash: Option<FlashMessage>) -> Result<Html<String>, Error> {
// If there is an error, show it // If there is an error, show it
let msg = flash let msg = flash.map(|msg| format!("{}: {}", msg.name(), msg.msg()));
.map(|msg| format!("{}: {}", msg.name(), msg.msg()))
.unwrap_or_default();
let error = json!({ "error": msg });
// Return the page // Return the page
let text = CONFIG.templates.render("admin/admin_login", &error)?; let text = AdminTemplateData::login(msg).render()?;
Ok(Html(text)) Ok(Html(text))
} }
#[derive(FromForm)]
struct LoginForm {
token: String,
}
#[post("/", data = "<data>")] #[post("/", data = "<data>")]
fn post_admin_login(data: Form<LoginForm>, mut cookies: Cookies, ip: ClientIp) -> Result<Redirect, Flash<Redirect>> { fn post_admin_login(data: Form<LoginForm>, mut cookies: Cookies, ip: ClientIp) -> Result<Redirect, Flash<Redirect>> {
let data = data.into_inner(); let data = data.into_inner();
@ -74,19 +100,12 @@ fn _validate_token(token: &str) -> bool {
} }
} }
#[derive(Serialize)]
struct AdminTemplateData {
users: Vec<Value>,
}
#[get("/", rank = 1)] #[get("/", rank = 1)]
fn admin_page(_token: AdminToken, conn: DbConn) -> Result<Html<String>, Error> { fn admin_page(_token: AdminToken, conn: DbConn) -> Result<Html<String>, Error> {
let users = User::get_all(&conn); let users = User::get_all(&conn);
let users_json: Vec<Value> = users.iter().map(|u| u.to_json(&conn)).collect(); let users_json: Vec<Value> = users.iter().map(|u| u.to_json(&conn)).collect();
let data = AdminTemplateData { users: users_json }; let text = AdminTemplateData::admin(users_json).render()?;
let text = CONFIG.templates.render("admin/admin_page", &data)?;
Ok(Html(text)) Ok(Html(text))
} }

Datei anzeigen

@ -352,6 +352,7 @@ fn load_templates(path: String) -> Handlebars {
reg!("email/pw_hint_some"); reg!("email/pw_hint_some");
reg!("email/send_org_invite"); reg!("email/send_org_invite");
reg!("admin/admin_base");
reg!("admin/admin_login"); reg!("admin/admin_login");
reg!("admin/admin_page"); reg!("admin/admin_page");

Datei anzeigen

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bitwarden_rs Admin Panel</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css"
integrity="sha256-azvvU9xKluwHFJ0Cpgtf0CYzK7zgtOznnzxV4924X1w=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.js" integrity="sha256-tCQ/BldMlN2vWe5gAiNoNb5svoOgVUhlUgv7UjONKKQ="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/identicon.js/2.3.3/identicon.min.js" integrity="sha256-nYoL3nK/HA1e1pJvLwNPnpKuKG9q89VFX862r5aohmA="
crossorigin="anonymous"></script>
<style>
body {
padding-top: 70px;
}
img {
width: 48px;
height: 48px;
}
</style>
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top shadow">
<a class="navbar-brand" href="#">Bitwarden_rs</a>
<div class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/admin">Admin Panel</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/">Vault</a>
</li>
</ul>
</div>
</nav>
{{> (page_content) }}
</body>
</html>

Datei anzeigen

@ -1,34 +1,4 @@
<!DOCTYPE html> <main class="container">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bitwarden_rs Admin Panel</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha256-azvvU9xKluwHFJ0Cpgtf0CYzK7zgtOznnzxV4924X1w=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<style>
body { padding-top: 70px; }
</style>
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top shadow">
<a class="navbar-brand" href="#">Bitwarden_rs</a>
<div class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/admin">Admin Panel</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/">Vault</a>
</li>
</ul>
</div>
</nav>
<main class="container">
{{#if error}} {{#if error}}
<div class="align-items-center p-3 mb-3 text-white-50 bg-warning rounded shadow"> <div class="align-items-center p-3 mb-3 text-white-50 bg-warning rounded shadow">
<div> <div>
@ -48,7 +18,4 @@
</form> </form>
</div> </div>
</div> </div>
</main> </main>
</body>
</html>

Datei anzeigen

@ -1,26 +1,42 @@
<!DOCTYPE html> <main class="container">
<html lang="en"> <div id="users-block" class="my-3 p-3 bg-white rounded shadow">
<h6 class="border-bottom pb-2 mb-0">Registered Users</h6>
<head> <div id="users-list">
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> {{#each users}}
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <div class="media pt-3">
<title>Bitwarden_rs Admin Panel</title> <img class="mr-2 rounded identicon" data-src="{{Email}}">
<div class="media-body pb-3 mb-0 small border-bottom">
<div class="d-flex justify-content-between">
<strong>{{Name}}</strong>
<a class="tmp-del mr-3" href="" onclick='deleteUser("{{Id}}", "{{Email}}");'>Delete User</a>
</div>
<span class="d-block">{{Email}}</span>
</div>
</div>
{{/each}}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css" </div>
integrity="sha256-azvvU9xKluwHFJ0Cpgtf0CYzK7zgtOznnzxV4924X1w=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.js" integrity="sha256-tCQ/BldMlN2vWe5gAiNoNb5svoOgVUhlUgv7UjONKKQ="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/identicon.js/2.3.3/identicon.min.js" integrity="sha256-nYoL3nK/HA1e1pJvLwNPnpKuKG9q89VFX862r5aohmA="
crossorigin="anonymous"></script>
<style> <small class="d-block text-right mt-3">
body { padding-top: 70px; } <a id="reload-btn" href="">Reload users</a>
img { width: 48px; height: 48px; } </small>
</style> </div>
<script> <div id="invite-form-block" class="align-items-center p-3 mb-3 text-white-50 bg-secondary rounded shadow">
<div>
<h6 class="mb-0 text-white">Invite User</h6>
<small>Email:</small>
<form class="form-inline" id="invite-form">
<input type="email" class="form-control w-50 mr-2" id="email-invite" placeholder="Enter email">
<button type="submit" class="btn btn-primary">Invite</button>
</form>
</div>
</div>
</main>
<script>
function reload() { window.location.reload(); } function reload() { window.location.reload(); }
function identicon(email) { function identicon(email) {
const data = new Identicon(md5(email), { size: 48, format: 'svg' }); const data = new Identicon(md5(email), { size: 48, format: 'svg' });
@ -64,61 +80,4 @@
e.src = identicon(e.dataset.src); e.src = identicon(e.dataset.src);
}); });
}); });
</script> </script>
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top shadow">
<a class="navbar-brand" href="#">Bitwarden_rs</a>
<div class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/admin">Admin Panel</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/">Vault</a>
</li>
</ul>
</div>
</nav>
<main class="container">
<div id="users-block" class="my-3 p-3 bg-white rounded shadow">
<h6 class="border-bottom pb-2 mb-0">Registered Users</h6>
<div id="users-list">
{{#each users}}
<div class="media pt-3">
{{!-- row.find(".tmp-icon").attr("src", identicon(user.Email)) --}}
<img class="mr-2 rounded identicon" data-src="{{Email}}">
<div class="media-body pb-3 mb-0 small border-bottom">
<div class="d-flex justify-content-between">
<strong>{{Name}}</strong>
<a class="tmp-del mr-3" href="" onclick='deleteUser("{{Id}}", "{{Email}}");'>Delete User</a>
</div>
<span class="d-block">{{Email}}</span>
</div>
</div>
{{/each}}
</div>
<small class="d-block text-right mt-3">
<a id="reload-btn" href="">Reload users</a>
</small>
</div>
<div id="invite-form-block" class="align-items-center p-3 mb-3 text-white-50 bg-secondary rounded shadow">
<div>
<h6 class="mb-0 text-white">Invite User</h6>
<small>Email:</small>
<form class="form-inline" id="invite-form">
<input type="email" class="form-control w-50 mr-2" id="email-invite" placeholder="Enter email">
<button type="submit" class="btn btn-primary">Invite</button>
</form>
</div>
</div>
</main>
</body>
</html>