Registration

This commit is contained in:
daru
2022-04-14 21:12:45 +02:00
parent cf70db1f96
commit 0cc4c3245f
5 changed files with 71 additions and 5 deletions

31
ober.go
View File

@@ -86,7 +86,36 @@ func Register(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
// TODO REGISTER
// check user exists
_, err = ReadUser(register.Username)
if err == nil {
ctx.WriteString("Nicht drängeln")
ctx.SetStatusCode(fasthttp.StatusConflict)
return
}
// check user legit
userData, _, err := GetUserData(register.Username)
if err != nil {
ctx.WriteString(err.Error())
ctx.SetStatusCode(fasthttp.StatusExpectationFailed)
return
}
if userData.Data.MalID != register.MalId {
ctx.WriteString("Dich gibts net auf MAL")
ctx.SetStatusCode(fasthttp.StatusExpectationFailed)
return
}
// REGISTER
user := UserData{
Username: register.Username,
MalId: register.MalId,
}
err = SaveUser(&user)
if err != nil {
addErrorToCtx(ctx, err)
return
}
ctx.SetBody(body)
ctx.SetStatusCode(fasthttp.StatusOK)
}