avoid amending reglogs on register

This commit is contained in:
Azareal 2020-04-05 07:27:20 +10:00
parent 49a3837621
commit 22af6f19cd
1 changed files with 10 additions and 10 deletions

View File

@ -266,7 +266,7 @@ func AccountRegisterSubmit(w http.ResponseWriter, r *http.Request, user *c.User)
} }
regLog := c.RegLogItem{Username: name, Email: email, FailureReason: regErrReason, Success: regSuccess, IP: user.GetIP()} regLog := c.RegLogItem{Username: name, Email: email, FailureReason: regErrReason, Success: regSuccess, IP: user.GetIP()}
if !c.Config.DisableRegLog { if !c.Config.DisableRegLog && regSuccess {
_, err := regLog.Create() _, err := regLog.Create()
if err != nil { if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
@ -286,32 +286,32 @@ func AccountRegisterSubmit(w http.ResponseWriter, r *http.Request, user *c.User)
group = c.Config.ActivationGroup group = c.Config.ActivationGroup
} }
addReason := func(reason string) error { pushLog := func(reason string) error {
if c.Config.DisableRegLog { if !c.Config.DisableRegLog {
regLog.FailureReason += reason + "|"
_, err := regLog.Create()
return err
}
return nil return nil
} }
regLog.FailureReason += reason
return regLog.Commit()
}
// TODO: Do the registration attempt logging a little less messily (without having to amend the result after the insert)
uid, err := c.Users.Create(name, password, email, group, active) uid, err := c.Users.Create(name, password, email, group, active)
if err != nil { if err != nil {
regLog.Success = false regLog.Success = false
if err == c.ErrAccountExists { if err == c.ErrAccountExists {
err = addReason("username-exists") err = pushLog("username-exists")
if err != nil { if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
return c.LocalError(p.GetErrorPhrase("register_username_unavailable"), w, r, user) return c.LocalError(p.GetErrorPhrase("register_username_unavailable"), w, r, user)
} else if err == c.ErrLongUsername { } else if err == c.ErrLongUsername {
err = addReason("username-too-long") err = pushLog("username-too-long")
if err != nil { if err != nil {
return c.InternalError(err, w, r) return c.InternalError(err, w, r)
} }
return c.LocalError(p.GetErrorPhrase("register_username_too_long_prefix")+strconv.Itoa(c.Config.MaxUsernameLength), w, r, user) return c.LocalError(p.GetErrorPhrase("register_username_too_long_prefix")+strconv.Itoa(c.Config.MaxUsernameLength), w, r, user)
} }
err2 := addReason("internal-error") err2 := pushLog("internal-error")
if err2 != nil { if err2 != nil {
return c.InternalError(err2, w, r) return c.InternalError(err2, w, r)
} }