mirror of
https://github.com/donl/gPanel.git
synced 2026-05-25 22:06:55 -06:00
33 lines
573 B
Go
33 lines
573 B
Go
// Package api handles all API calls
|
|
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
var auth struct {
|
|
User string `json:"user"`
|
|
Pass string `json:"pass"`
|
|
}
|
|
|
|
func Authentication(res http.ResponseWriter, req *http.Request) bool {
|
|
err := json.NewDecoder(req.Body).Decode(&auth)
|
|
|
|
if err != nil {
|
|
http.Error(res, err.Error(), 400)
|
|
return false
|
|
} else {
|
|
|
|
if auth.User == "root" && auth.Pass == "root" {
|
|
res.WriteHeader(200)
|
|
res.Write([]byte("success"))
|
|
return true
|
|
} else {
|
|
http.Error(res, "Authentication failed", 401)
|
|
return false
|
|
}
|
|
|
|
}
|
|
|
|
}
|