summaryrefslogtreecommitdiff
path: root/src/request_handler/views.rs
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2018-11-26 12:33:37 +0100
committerYves Fischer <yvesf-git@xapek.org>2018-11-26 12:36:07 +0100
commit63636d00ca56ee37f9cb9db3fece81d615e21a1a (patch)
tree970f86c8ed2abd32d6af964b0f7cfb34f9bd8d45 /src/request_handler/views.rs
parent20242a8d3cc2e9a70812f34fcc50c170a654f6c6 (diff)
downloadnginx-auth-totp-63636d00ca56ee37f9cb9db3fece81d615e21a1a.tar.gz
nginx-auth-totp-63636d00ca56ee37f9cb9db3fece81d615e21a1a.zip
Refactor html views
Diffstat (limited to 'src/request_handler/views.rs')
-rw-r--r--src/request_handler/views.rs138
1 files changed, 138 insertions, 0 deletions
diff --git a/src/request_handler/views.rs b/src/request_handler/views.rs
new file mode 100644
index 0000000..ee020eb
--- /dev/null
+++ b/src/request_handler/views.rs
@@ -0,0 +1,138 @@
+use horrorshow::Template;
+
+pub(in super) fn info_debug<'a>(path_rest: &'a str, cookies: Vec<(String, String)>) -> String {
+ (html! {
+ : horrorshow::helper::doctype::HTML;
+ html {
+ head {
+ title: "Hello world!";
+ }
+ body {
+ h1(id = "heading") {
+ : "Hello! This is <html />";
+ : "And path rest is: ";
+ : path_rest;
+ : "... ok :)";
+ }
+ h2: "Valid cookies are:";
+ table(border="1") {
+ thead {
+ th: "Cookie value";
+ th: "Valid until";
+ }
+ tbody {
+ @ for (name, valid_until) in cookies {
+ tr {
+ td: name;
+ td: valid_until;
+ }
+ }
+ }
+ }
+ }
+ }
+ }).into_string().unwrap()
+}
+
+pub(in super) fn info<'a>(path_rest: &'a str) -> String {
+ (html! {
+ : horrorshow::helper::doctype::HTML;
+ html {
+ head {
+ title: "Hello world!";
+ }
+ body {
+ h1(id = "heading") {
+ : "Hello! This is <html />";
+ : "And path rest is: ";
+ : path_rest;
+ : "... ok :)";
+ }
+ }
+ }
+ }).into_string().unwrap()
+}
+
+pub(in super) fn login_is_logged_in() -> String {
+ (html! {
+ : horrorshow::helper::doctype::HTML;
+ html {
+ head {
+ title: "TOTP Login";
+ }
+ body {
+ h1(id = "heading") {
+ : "Currently logged in"
+ }
+ }
+ }
+ }).into_string().unwrap()
+}
+
+pub(in super) fn login_login_form<'a>(redirect: &'a str) -> String {
+ (html! {
+ : horrorshow::helper::doctype::HTML;
+ html {
+ head {
+ title: "TOTP Login";
+ }
+ body {
+ h1(id = "heading") {
+ : "Login"
+ }
+ form(method="POST") {
+ label(for="token") {
+ : "Enter TOTP token"
+ }
+ input(name="token",id="token",type="text");
+ input(name="redirect", type="hidden", value=redirect);
+ input(name="send",type="submit",value="Submit");
+ }
+ }
+ }
+ }).into_string().unwrap()
+}
+
+pub(in super) fn login_auth_success(redirect: &String) -> String {
+ (html! {
+ : horrorshow::helper::doctype::HTML;
+ html {
+ head {
+ title: "TOTP Successful";
+ meta(http-equiv="refresh", content=format!("3; URL={}", redirect))
+ }
+ body {
+ h1(id = "heading") {
+ : "Login succesful"
+ }
+ a(href=redirect) {
+ : "Try again... redirecting to ";
+ }
+ span {
+ : format!("{}", redirect)
+ }
+ }
+ }
+ }).into_string().unwrap()
+}
+
+
+pub(in super) fn login_auth_fail() -> String {
+ (html! {
+ : horrorshow::helper::doctype::HTML;
+ html {
+ head {
+ title: "TOTP Login failed";
+ meta(http-equiv="refresh", content="1")
+ }
+ body {
+ h1(id = "heading") {
+ : "Login failed"
+ }
+ a(href="login") {
+ : "Try again... "
+ }
+ }
+ }
+ }).into_string().unwrap()
+} \ No newline at end of file