add login page to webserver
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ func main() {
|
|||||||
read_config()
|
read_config()
|
||||||
init_dav_client()
|
init_dav_client()
|
||||||
|
|
||||||
webserver.ServeWebpage("/login", LoginHandler)
|
webserver.ServeLoginPage("/login")
|
||||||
webserver.ServeWebserver()
|
webserver.ServeWebserver()
|
||||||
|
|
||||||
// calDavData := get_caldav_data(serverConfig.Username, serverConfig.Password)
|
// calDavData := get_caldav_data(serverConfig.Username, serverConfig.Password)
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package webserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoginPageData struct {
|
||||||
|
IsHiddenClassList string
|
||||||
|
}
|
||||||
|
|
||||||
|
func loginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
tmpl := template.Must(template.ParseFiles("webserver/pages/login_page.html"))
|
||||||
|
if r.Method == http.MethodGet {
|
||||||
|
tmpl.Execute(w, LoginPageData{IsHiddenClassList: "hidden"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method == http.MethodPost {
|
||||||
|
username := r.FormValue("username")
|
||||||
|
if strings.Contains(username, "/") {
|
||||||
|
tmpl.Execute(w, LoginPageData{IsHiddenClassList: ""})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<title>Astral Tech - Login</title>
|
||||||
|
|
||||||
|
<link
|
||||||
|
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
|
||||||
|
rel="stylesheet"
|
||||||
|
/>
|
||||||
|
<link rel="stylesheet" href="static/style.css" />
|
||||||
|
<link rel="stylesheet" href="static/error/error.css" />
|
||||||
|
<link rel="stylesheet" href="static/card.css" />
|
||||||
|
<link rel="stylesheet" href="static/login_page.css" />
|
||||||
|
|
||||||
|
<img id="logo_image" alt="logo" src="/logo" />
|
||||||
|
<form id="login_card" class="card" method="POST">
|
||||||
|
<div id="welcome_text">
|
||||||
|
Welcome to Astral Tech, Please Sign in to your account below
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="error {{.IsHiddenClassList}}">
|
||||||
|
⚠️ Invalid username or password.
|
||||||
|
<button class="close_error_button">X</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="input_label">Username</label><br />
|
||||||
|
<input type="text" name="username" placeholder="" required />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="input_label">Password</label><br />
|
||||||
|
<div class="password_box">
|
||||||
|
<input type="password" name="password" placeholder="" required />
|
||||||
|
<button type="button" class="show_password_toggle closed"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script src="/static/error/error.js" type="text/javascript"></script>
|
||||||
|
<script
|
||||||
|
src="/static/javascript/show_password.js"
|
||||||
|
type="text/javascript"
|
||||||
|
></script>
|
||||||
@@ -5,8 +5,15 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var routes []string
|
||||||
|
|
||||||
|
func ServeLoginPage(route string) {
|
||||||
|
ServeWebpage(route, loginHandler)
|
||||||
|
}
|
||||||
|
|
||||||
func ServeWebpage(url string, handler func(http.ResponseWriter, *http.Request)) {
|
func ServeWebpage(url string, handler func(http.ResponseWriter, *http.Request)) {
|
||||||
http.HandleFunc(url, handler)
|
http.HandleFunc(url, handler)
|
||||||
|
routes = append(routes, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServeWebserver() {
|
func ServeWebserver() {
|
||||||
|
|||||||
Reference in New Issue
Block a user