44 lines
821 B
Go
44 lines
821 B
Go
package admin
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
type (
|
|
State struct {
|
|
Token string
|
|
}
|
|
)
|
|
|
|
func CreateState() *State {
|
|
return &State{
|
|
Token: "you are the WINRAR!!",
|
|
}
|
|
}
|
|
|
|
func HandleLogin(writer http.ResponseWriter, req *http.Request, root *template.Template) int {
|
|
if req.Method != "POST" {
|
|
return 404;
|
|
}
|
|
|
|
body, err := io.ReadAll(req.Body)
|
|
if err != nil {
|
|
fmt.Printf("failed to parse request body!\n");
|
|
return 500;
|
|
}
|
|
|
|
if string(body) != "super epic mega gaming password" {
|
|
return 400;
|
|
}
|
|
|
|
state := CreateState();
|
|
|
|
writer.WriteHeader(200);
|
|
writer.Write([]byte(state.Token))
|
|
|
|
return 200;
|
|
}
|