auth request handler
This commit is contained in:
+5
-5
@@ -1,15 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"fmt"
|
||||||
|
|
||||||
"astraltech.xyz/calendar/v2/webserver"
|
"astraltech.xyz/calendar/v2/webserver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
func HandleAuthRequest(username string, password string) bool {
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
fmt.Printf("Handling Auth request for %s", username)
|
||||||
var test_html string = "Hello, world"
|
return false
|
||||||
w.Write([]byte(test_html))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -18,6 +17,7 @@ func main() {
|
|||||||
|
|
||||||
webserver.ServeLoginPage("/login", webserver.CustomizableLoginData{
|
webserver.ServeLoginPage("/login", webserver.CustomizableLoginData{
|
||||||
ServiceName: "Astral Calendar",
|
ServiceName: "Astral Calendar",
|
||||||
|
AuthRequestFunction: HandleAuthRequest,
|
||||||
})
|
})
|
||||||
webserver.EnableLogoRoute()
|
webserver.EnableLogoRoute()
|
||||||
webserver.EnableStaticRoute()
|
webserver.EnableStaticRoute()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ type LoginPageData struct {
|
|||||||
|
|
||||||
type CustomizableLoginData struct {
|
type CustomizableLoginData struct {
|
||||||
ServiceName string
|
ServiceName string
|
||||||
|
AuthRequestFunction func(string, string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var LoginPageDataCustomizations CustomizableLoginData
|
var LoginPageDataCustomizations CustomizableLoginData
|
||||||
@@ -28,7 +29,13 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if r.Method == http.MethodPost {
|
if r.Method == http.MethodPost {
|
||||||
username := r.FormValue("username")
|
username := r.FormValue("username")
|
||||||
if strings.Contains(username, "/") {
|
if strings.Contains(username, "/") {
|
||||||
tmpl.Execute(w, LoginPageData{IsHiddenClassList: ""})
|
tmpl.Execute(w, LoginPageData{IsHiddenClassList: "", LoginData: LoginPageDataCustomizations})
|
||||||
|
}
|
||||||
|
password := r.FormValue("password")
|
||||||
|
|
||||||
|
auth_success := LoginPageDataCustomizations.AuthRequestFunction(username, password)
|
||||||
|
if auth_success == false {
|
||||||
|
tmpl.Execute(w, LoginPageData{IsHiddenClassList: "", LoginData: LoginPageDataCustomizations})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user