summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/render/mod.rs14
-rw-r--r--src/server.rs24
2 files changed, 31 insertions, 7 deletions
diff --git a/src/render/mod.rs b/src/render/mod.rs
index 3b63a68..a824bd6 100644
--- a/src/render/mod.rs
+++ b/src/render/mod.rs
@@ -32,6 +32,20 @@ fn render_in_page<'a>(content: Box<RenderBox + 'a>) -> String {
}).into_string().unwrap()
}
+pub fn login_page() -> String {
+ render_in_page(box_html! {
+ h1 { : "Log in" }
+ form(method="post") {
+ p { : "Username" }
+ input(type="text", name="username") {}
+ p { : "Password" }
+ input(type="text", name="password") {}
+ p {}
+ input(type="submit", value="Log in") {}
+ }
+ })
+}
+
fn unit_table<'a>(units: &'a [&unit::Unit]) -> Box<RenderBox + 'a> {
fn render_unit<'a>(unit: &'a unit::Unit) -> Box<RenderBox + 'a> {
box_html! {
diff --git a/src/server.rs b/src/server.rs
index 9e63cb3..f34489f 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -5,7 +5,7 @@ use iron_sessionstorage::backends::SignedCookieBackend;
use iron::status;
use iron::modifiers::Header;
use iron::headers::ContentType;
-use iron::{Iron, Request, IronResult, Response, Chain, Listening};
+use iron::{Iron, IronError, Request, IronResult, Response, Chain, Listening};
use iron::error::{HttpResult};
use router::Router;
use systemd::unit;
@@ -33,12 +33,6 @@ impl iron_sessionstorage::Value for Login {
fn overview(r: &mut Request) -> IronResult<Response> {
let mut _value = try!(r.session().get::<Login>());
- let name = r.extensions
- .get::<Router>()
- .unwrap()
- .find("name")
- .unwrap_or("World").to_owned();
-
let units = unit::get_units("*").unwrap();
let sections = ["service", "timer", "socket", "target", "slice", "mount",
@@ -98,10 +92,26 @@ fn unit_status(r: &mut Request) -> IronResult<Response> {
render::unit_status(&unit, &log))))
}
+fn login(r: &mut Request) -> IronResult<Response> {
+ Ok(Response::with((status::Ok,
+ Header(ContentType::html()),
+ render::login_page())))
+}
+
+fn login_submit(r: &mut Request) -> IronResult<Response> {
+ Ok(Response::with((status::Ok,
+ Header(ContentType::plaintext()),
+ "login")))
+ // TODO: Need this to get params:
+ // https://github.com/iron/params
+}
+
pub fn serve(port: u16) -> HttpResult<Listening> {
let secret = b"secret2".to_vec();
let router = router!(
root: get "/" => overview,
+ login: get "/login" => login,
+ login_submit: post "/login" => login_submit,
details: get "/status/:unit" => unit_status,
journal: get "/journal/:unit" => journal,
css: get "/static/main.css" => Static::new(""),