diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-05-20 22:08:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 22:08:52 +0800 |
commit | fd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch) | |
tree | 50038348ec10485f72344f3ac80324e04abc1283 /models/user/openid.go | |
parent | d81e31ad7826a81fc7139f329f250594610a274b (diff) | |
download | gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip |
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context
* remove some unnecessary wrap functions
Diffstat (limited to 'models/user/openid.go')
-rw-r--r-- | models/user/openid.go | 18 |
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. |