aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorskyblue <ssx205@gmail.com>2014-04-07 18:01:25 +0800
committerskyblue <ssx205@gmail.com>2014-04-07 18:01:25 +0800
commit05fb34eacdbec59fb8bcdf96c82c0855e6ec78d2 (patch)
treee12623184d69d5a674c77aa8a98aba4955301581 /models
parenta92d67fa01983644ccdb3d7bc54993a60d185da5 (diff)
first works oauth2(github). need to login with /user/login/github
Diffstat (limited to 'models')
-rw-r--r--models/oauth2.go33
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)
}