summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorskyblue <ssx205@gmail.com>2014-04-12 01:01:30 +0800
committerskyblue <ssx205@gmail.com>2014-04-12 01:01:30 +0800
commitdd815ae7b532ceba1f96e6751e231dc351eb19b9 (patch)
tree3e8383106585e5a990ab5074ff3a2fd87d4239d7 /models
parentdf000245d19ffa3e4f88d252763269bbdd04f8eb (diff)
downloadgitea-dd815ae7b532ceba1f96e6751e231dc351eb19b9.tar.gz
gitea-dd815ae7b532ceba1f96e6751e231dc351eb19b9.zip
finish github oauth2 support
Diffstat (limited to 'models')
-rw-r--r--models/oauth2.go31
1 files changed, 27 insertions, 4 deletions
diff --git a/models/oauth2.go b/models/oauth2.go
index 45728b0d51..e50d4039fd 100644
--- a/models/oauth2.go
+++ b/models/oauth2.go
@@ -4,7 +4,11 @@
package models
-import "errors"
+import (
+ "errors"
+
+ "github.com/gogits/gogs/modules/log"
+)
// OT: Oauth2 Type
const (
@@ -16,17 +20,23 @@ const (
var (
ErrOauth2RecordNotExists = errors.New("not exists oauth2 record")
ErrOauth2NotAssociatedWithUser = errors.New("not associated with user")
+ ErrOauth2NotExist = errors.New("not exist oauth2")
)
type Oauth2 struct {
Id int64
- Uid int64 // userId
+ Uid int64 `xorm:"unique(s)"` // userId
User *User `xorm:"-"`
- Type int `xorm:"pk unique(oauth)"` // twitter,github,google...
- Identity string `xorm:"pk unique(oauth)"` // id..
+ Type int `xorm:"unique(s) unique(oauth)"` // twitter,github,google...
+ Identity string `xorm:"unique(s) unique(oauth)"` // id..
Token string `xorm:"VARCHAR(200) not null"`
}
+func BindUserOauth2(userId, oauthId int64) error {
+ _, err := orm.Id(oauthId).Update(&Oauth2{Uid: userId})
+ return err
+}
+
func AddOauth2(oa *Oauth2) (err error) {
if _, err = orm.Insert(oa); err != nil {
return err
@@ -47,3 +57,16 @@ func GetOauth2(identity string) (oa *Oauth2, err error) {
oa.User, err = GetUserById(oa.Uid)
return oa, err
}
+
+func GetOauth2ById(id int64) (oa *Oauth2, err error) {
+ oa = new(Oauth2)
+ has, err := orm.Id(id).Get(oa)
+ log.Info("oa: %v", oa)
+ if err != nil {
+ return nil, err
+ }
+ if !has {
+ return nil, ErrOauth2NotExist
+ }
+ return oa, nil
+}