summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorskyblue <ssx205@gmail.com>2014-04-09 00:26:12 +0800
committerskyblue <ssx205@gmail.com>2014-04-09 00:26:12 +0800
commitd4565483e67dfd17f723114d5849b2ce6895c077 (patch)
treeef81132a3560ce7b64bb6928ce237c42324b4bf5 /models
parent22feddf804c7fbf3418cbbc8e7302da271da4e5a (diff)
downloadgitea-d4565483e67dfd17f723114d5849b2ce6895c077.tar.gz
gitea-d4565483e67dfd17f723114d5849b2ce6895c077.zip
add id for oauth2
Diffstat (limited to 'models')
-rw-r--r--models/oauth2.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/models/oauth2.go b/models/oauth2.go
index a17d4e30fa..10771d6a73 100644
--- a/models/oauth2.go
+++ b/models/oauth2.go
@@ -1,6 +1,9 @@
package models
-import "fmt"
+import (
+ "errors"
+ "fmt"
+)
// OT: Oauth2 Type
const (
@@ -9,12 +12,18 @@ const (
OT_TWITTER
)
+var (
+ ErrOauth2RecordNotExists = errors.New("not exists oauth2 record")
+ ErrOauth2NotAssociatedWithUser = errors.New("not associated with user")
+)
+
type Oauth2 struct {
- Uid int64 `xorm:"pk"` // userId
+ Id int64
+ Uid int64 `xorm:"pk"` // userId
+ User *User `xorm:"-"`
Type int `xorm:"pk unique(oauth)"` // twitter,github,google...
Identity string `xorm:"pk unique(oauth)"` // id..
Token string `xorm:"VARCHAR(200) not null"`
- //RefreshTime time.Time `xorm:"created"`
}
func AddOauth2(oa *Oauth2) (err error) {
@@ -24,8 +33,8 @@ func AddOauth2(oa *Oauth2) (err error) {
return nil
}
-func GetOauth2User(identity string) (u *User, err error) {
- oa := &Oauth2{}
+func GetOauth2(identity string) (oa *Oauth2, err error) {
+ oa = &Oauth2{}
oa.Identity = identity
exists, err := orm.Get(oa)
if err != nil {
@@ -35,5 +44,9 @@ func GetOauth2User(identity string) (u *User, err error) {
err = fmt.Errorf("not exists oauth2: %s", identity)
return
}
- return GetUserById(oa.Uid)
+ if oa.Uid == 0 {
+ return oa, ErrOauth2NotAssociatedWithUser
+ }
+ oa.User, err = GetUserById(oa.Uid)
+ return
}