summaryrefslogtreecommitdiffstats
path: root/models/user/openid.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/user/openid.go')
-rw-r--r--models/user/openid.go18
1 files changed, 7 insertions, 11 deletions
diff --git a/models/user/openid.go b/models/user/openid.go
index 8ca3c7f2c8..8ef0ce5ed7 100644
--- a/models/user/openid.go
+++ b/models/user/openid.go
@@ -5,6 +5,7 @@
package user
import (
+ "context"
"errors"
"fmt"
@@ -41,12 +42,12 @@ func GetUserOpenIDs(uid int64) ([]*UserOpenID, error) {
}
// isOpenIDUsed returns true if the openid has been used.
-func isOpenIDUsed(e db.Engine, uri string) (bool, error) {
+func isOpenIDUsed(ctx context.Context, uri string) (bool, error) {
if len(uri) == 0 {
return true, nil
}
- return e.Get(&UserOpenID{URI: uri})
+ return db.GetEngine(ctx).Get(&UserOpenID{URI: uri})
}
// ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
@@ -64,22 +65,17 @@ func (err ErrOpenIDAlreadyUsed) Error() string {
return fmt.Sprintf("OpenID already in use [oid: %s]", err.OpenID)
}
+// AddUserOpenID adds an pre-verified/normalized OpenID URI to given user.
// NOTE: make sure openid.URI is normalized already
-func addUserOpenID(e db.Engine, openid *UserOpenID) error {
- used, err := isOpenIDUsed(e, openid.URI)
+func AddUserOpenID(ctx context.Context, openid *UserOpenID) error {
+ used, err := isOpenIDUsed(ctx, openid.URI)
if err != nil {
return err
} else if used {
return ErrOpenIDAlreadyUsed{openid.URI}
}
- _, err = e.Insert(openid)
- return err
-}
-
-// AddUserOpenID adds an pre-verified/normalized OpenID URI to given user.
-func AddUserOpenID(openid *UserOpenID) error {
- return addUserOpenID(db.GetEngine(db.DefaultContext), openid)
+ return db.Insert(ctx, openid)
}
// DeleteUserOpenID deletes an openid address of given user.