mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-07-05 15:58:32 +07:00
Removed register GET request in favor of POST, and did required HTTP api changes
This commit is contained in:
31
api.go
31
api.go
@ -23,16 +23,18 @@ func (a authMiddleware) Serve(ctx *iris.Context) {
|
||||
} else {
|
||||
if correctPassword(password, au.Password) {
|
||||
// Password ok
|
||||
if err := ctx.ReadJSON(&postData); err == nil {
|
||||
// Check that the subdomain belongs to the user
|
||||
if au.Subdomain == postData.Subdomain {
|
||||
ctx.Next()
|
||||
if au.allowedFrom(ctx.RequestIP()) {
|
||||
// Update is allowed from remote addr
|
||||
if err := ctx.ReadJSON(&postData); err == nil {
|
||||
if au.Subdomain == postData.Subdomain {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// JSON error
|
||||
ctx.JSON(iris.StatusBadRequest, iris.Map{"error": "bad data"})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// JSON error
|
||||
ctx.JSON(iris.StatusBadRequest, iris.Map{"error": "bad data"})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// Wrong password
|
||||
@ -44,17 +46,19 @@ func (a authMiddleware) Serve(ctx *iris.Context) {
|
||||
}
|
||||
|
||||
func webRegisterPost(ctx *iris.Context) {
|
||||
// Create new user
|
||||
nu, err := DB.Register(cidrslice{})
|
||||
var regJSON iris.Map
|
||||
var regStatus int
|
||||
cslice := cidrslice{}
|
||||
_ = ctx.ReadJSON(&cslice)
|
||||
// Create new user
|
||||
nu, err := DB.Register(cslice)
|
||||
if err != nil {
|
||||
errstr := fmt.Sprintf("%v", err)
|
||||
regJSON = iris.Map{"error": errstr}
|
||||
regStatus = iris.StatusInternalServerError
|
||||
log.WithFields(log.Fields{"error": err.Error()}).Debug("Error in registration")
|
||||
} else {
|
||||
regJSON = iris.Map{"username": nu.Username, "password": nu.Password, "fulldomain": nu.Subdomain + "." + DNSConf.General.Domain, "subdomain": nu.Subdomain}
|
||||
regJSON = iris.Map{"username": nu.Username, "password": nu.Password, "fulldomain": nu.Subdomain + "." + DNSConf.General.Domain, "subdomain": nu.Subdomain, "allowfrom": nu.AllowFrom.JSON()}
|
||||
regStatus = iris.StatusCreated
|
||||
|
||||
log.WithFields(log.Fields{"user": nu.Username.String()}).Debug("Created new user")
|
||||
@ -62,11 +66,6 @@ func webRegisterPost(ctx *iris.Context) {
|
||||
ctx.JSON(regStatus, regJSON)
|
||||
}
|
||||
|
||||
func webRegisterGet(ctx *iris.Context) {
|
||||
// This is placeholder for now
|
||||
webRegisterPost(ctx)
|
||||
}
|
||||
|
||||
func webUpdatePost(ctx *iris.Context) {
|
||||
// User auth done in middleware
|
||||
a := ACMETxt{}
|
||||
|
Reference in New Issue
Block a user