diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-08 12:41:37 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-08 12:41:37 -0400 |
commit | b5064298036c25b492c9b4547ed5314f928ceaeb (patch) | |
tree | d1baffcc17a610e6d72986d643284a055f04aebc /models | |
parent | 115a349131242201953a3f5693141679049355c6 (diff) | |
parent | 24d0ca4aa02bd4245cd4c91f71b918c5da1d2e7d (diff) | |
download | gitea-b5064298036c25b492c9b4547ed5314f928ceaeb.tar.gz gitea-b5064298036c25b492c9b4547ed5314f928ceaeb.zip |
Merge branch 'dev' of github.com:gogits/gogs into dev
Diffstat (limited to 'models')
-rw-r--r-- | models/oauth2.go | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/models/oauth2.go b/models/oauth2.go index a17d4e30fa..4da9800670 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -1,6 +1,6 @@ package models -import "fmt" +import "errors" // OT: Oauth2 Type const ( @@ -9,12 +9,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,16 +30,19 @@ 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 { return } if !exists { - err = fmt.Errorf("not exists oauth2: %s", identity) - return + return nil, ErrOauth2RecordNotExists + } + if oa.Uid == 0 { + return oa, ErrOauth2NotAssociatedWithUser } - return GetUserById(oa.Uid) + oa.User, err = GetUserById(oa.Uid) + return } |