guildgate/main.go

54 lines
1.2 KiB
Go
Raw Normal View History

2020-08-20 12:51:02 -04:00
package main
import (
"log"
"net/http"
)
2020-08-20 13:24:52 -04:00
var Conf *Config
2020-08-20 12:51:02 -04:00
func signupPage(res http.ResponseWriter, req *http.Request) {
if req.Method != "POST" {
http.ServeFile(res, req, "register.html")
return
}
username := req.FormValue("username")
password := req.FormValue("password")
email := req.FormValue("email")
secret := req.FormValue("secret")
2020-08-20 13:24:52 -04:00
if Conf.Secret != "" && Conf.Secret != secret {
log.Printf("Bad secret entered\n")
2020-08-20 12:51:02 -04:00
res.Write([]byte("Get a load of this guy, not knowing the secret code"))
return
}
//insert into LDAP
2020-08-20 13:24:52 -04:00
log.Printf("Attempting to create account for %v", username)
2020-08-20 12:51:02 -04:00
err := createLDAPAccount(username, password, email)
if err == nil {
res.Write([]byte("User created!"))
return
} else {
res.Write([]byte("Failure to create account"))
return
}
}
func homePage(res http.ResponseWriter, req *http.Request) {
http.ServeFile(res, req, "index.html")
}
func main() {
2020-08-20 13:24:52 -04:00
Conf, _ = LoadConfig()
2020-08-20 12:51:02 -04:00
log.Println("Loaded config")
http.HandleFunc("/register", signupPage)
http.HandleFunc("/", homePage)
2020-08-20 13:24:52 -04:00
log.Printf("Guildgate starting on %v\n", Conf.Port)
2020-08-23 17:53:48 -04:00
if Conf.Tls {
http.ListenAndServeTLS(":"+Conf.Port, Conf.Cert, Conf.Key, nil)
} else {
http.ListenAndServe(":"+Conf.Port, nil)
}
2020-08-20 12:51:02 -04:00
}