aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAKP <tom@tdpain.net>2022-08-31 12:51:29 +0100
committerAKP <tom@tdpain.net>2022-08-31 12:51:29 +0100
commit14ca4920e1abe1abf36d998bb92918b361dc67b8 (patch)
tree9f943bab0f898a5f455b797993db2785383c1fa8
parentd78c2af7aacf64ea4a348841e1264c9198a829b3 (diff)
Replace faulty error assertion
mattn/go-sqlite3 returns errors as `sqlite3.Error`, not `*sqlite3.Error` as was in use. This commit switches references of the latter with the former in user registration logic. This commit also removes some duplicated code from the user registration process. Fixes #2 Signed-off-by: AKP <tom@tdpain.net>
-rw-r--r--walrss/internal/core/users.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/walrss/internal/core/users.go b/walrss/internal/core/users.go
index dfd2c86..5e7c80c 100644
--- a/walrss/internal/core/users.go
+++ b/walrss/internal/core/users.go
@@ -33,12 +33,7 @@ func RegisterUser(st *state.State, email, password string) (*db.User, error) {
u.Password = hash
- if _, err := st.Data.NewInsert().Model(u).Exec(context.Background()); err != nil {
- if e, ok := err.(*sqlite3.Error); ok {
- if e.Code == sqlite3.ErrConstraint {
- return nil, NewUserError("email address in use")
- }
- }
+ if err := coreRegisterUser(st, u); err != nil {
return nil, err
}
@@ -51,16 +46,23 @@ func RegisterUserOIDC(st *state.State, email string) (*db.User, error) {
Email: email,
}
+ if err := coreRegisterUser(st, u); err != nil {
+ return nil, err
+ }
+
+ return u, nil
+}
+
+func coreRegisterUser(st *state.State, u *db.User) error {
if _, err := st.Data.NewInsert().Model(u).Exec(context.Background()); err != nil {
- if e, ok := err.(*sqlite3.Error); ok {
+ if e, ok := err.(sqlite3.Error); ok {
if e.Code == sqlite3.ErrConstraint {
- return nil, NewUserError("email address in use")
+ return NewUserError("email address in use")
}
}
- return nil, err
+ return err
}
-
- return u, nil
+ return nil
}
func AreUserCredentialsCorrect(st *state.State, email, password string) (bool, error) {