summaryrefslogtreecommitdiff
path: root/internal/db/bundb/user.go
diff options
context:
space:
mode:
authorLibravatar Dominik Süß <dominik@suess.wtf>2022-12-06 14:15:56 +0100
committerLibravatar GitHub <noreply@github.com>2022-12-06 14:15:56 +0100
commit199b685f430910910e43476caa9ccec6a441d020 (patch)
treeb928c97deae38f8194e51b5e7a69766ddd1a0763 /internal/db/bundb/user.go
parent[feature] media: add webp support (#1155) (diff)
downloadgotosocial-199b685f430910910e43476caa9ccec6a441d020.tar.xz
[feature] overhaul the oidc system (#961)
* [feature] overhaul the oidc system this allows for more flexible username handling and prevents account takeover using old email addresses * [feature] add migration path for old OIDC users * [feature] nicer error reporting for users * [docs] document the new OIDC flow * [fix] return early on oidc error * [docs]: add comments on the finalization logic
Diffstat (limited to 'internal/db/bundb/user.go')
-rw-r--r--internal/db/bundb/user.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/db/bundb/user.go b/internal/db/bundb/user.go
index ab3cc0f67..e7983556f 100644
--- a/internal/db/bundb/user.go
+++ b/internal/db/bundb/user.go
@@ -40,6 +40,7 @@ func (u *userDB) init() {
{Name: "AccountID"},
{Name: "Email"},
{Name: "ConfirmationToken"},
+ {Name: "ExternalID"},
}, func(u1 *gtsmodel.User) *gtsmodel.User {
u2 := new(gtsmodel.User)
*u2 = *u1
@@ -104,6 +105,24 @@ func (u *userDB) GetUserByEmailAddress(ctx context.Context, emailAddress string)
return &user, nil
}, emailAddress)
}
+func (u *userDB) GetUserByExternalID(ctx context.Context, id string) (*gtsmodel.User, db.Error) {
+
+ return u.cache.Load("ExternalID", func() (*gtsmodel.User, error) {
+ var user gtsmodel.User
+
+ q := u.conn.
+ NewSelect().
+ Model(&user).
+ Relation("Account").
+ Where("? = ?", bun.Ident("user.external_id"), id)
+
+ if err := q.Scan(ctx); err != nil {
+ return nil, u.conn.ProcessError(err)
+ }
+
+ return &user, nil
+ }, id)
+}
func (u *userDB) GetUserByConfirmationToken(ctx context.Context, confirmationToken string) (*gtsmodel.User, db.Error) {
return u.cache.Load("ConfirmationToken", func() (*gtsmodel.User, error) {