Handle unique constraint for user registration.

Returns an error if the same username or email already exists.
This commit is contained in:
Victor Vrantchan
2021-02-20 18:24:39 -05:00
parent 6caa73b637
commit 695856b205
2 changed files with 17 additions and 5 deletions

View File

@@ -151,6 +151,11 @@ func checkSqlite(err error) error {
}
switch sErr.Code {
case sqlite.SQLITE_CONSTRAINT_UNIQUE:
c := strings.Split(sErr.Msg, ": ")
if kv, ok := constraintsUnique[c[len(c)-1]]; ok {
return Error{invalid: kv}
}
case sqlite.SQLITE_CONSTRAINT_CHECK:
c := strings.Split(sErr.Msg, ": ")
if kv, ok := constraints[c[len(c)-1]]; ok {