summaryrefslogtreecommitdiff
path: root/src/request_handler/views.rs
blob: ee020eb5fb940ca6acece525957184ae3c0e2033 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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()
}