diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-04-10 22:21:12 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-04-10 22:21:12 +0800 |
commit | 94c7278194694fec728b518d4390b03ba6c237a4 (patch) | |
tree | 2aebf5fe63423b7b2eb14d58697bab1c95ffb3bb /models/oauth2.go | |
parent | 16b6e5d50b665c5376b61ca7d02e3716a1c05ead (diff) | |
parent | 2577940c30f6a6d15390974ab36f8c3d1e00f9f4 (diff) |
Merge branch 'master' of github.com:gogits/gogs into dev
Conflicts:
web.go
Diffstat (limited to 'models/oauth2.go')
-rw-r--r-- | models/oauth2.go | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/models/oauth2.go b/models/oauth2.go index 70dcd510..a17d4e30 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -1,6 +1,6 @@ package models -import "time" +import "fmt" // OT: Oauth2 Type const ( @@ -10,9 +10,30 @@ const ( ) type Oauth2 struct { - Uid int64 `xorm:"pk"` // userId - 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"` + Uid int64 `xorm:"pk"` // userId + 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) { + if _, err = orm.Insert(oa); err != nil { + return err + } + return nil +} + +func GetOauth2User(identity string) (u *User, 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 GetUserById(oa.Uid) } |