diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-08-09 17:25:02 -0700 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-08-09 17:25:02 -0700 |
commit | 78defd238c939ff577041f2e7b95b2ae48a9fb27 (patch) | |
tree | 5dd168d880ece655796558874f352b2c2263e965 /models/oauth2.go | |
parent | 08c6d07aad65f45efd5bf9f50d9cda68f59c0e69 (diff) | |
download | gitea-78defd238c939ff577041f2e7b95b2ae48a9fb27.tar.gz gitea-78defd238c939ff577041f2e7b95b2ae48a9fb27.zip |
Page: Manage social accounts
Diffstat (limited to 'models/oauth2.go')
-rw-r--r-- | models/oauth2.go | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/models/oauth2.go b/models/oauth2.go index 4b024a26e4..46e8e492a3 100644 --- a/models/oauth2.go +++ b/models/oauth2.go @@ -6,6 +6,7 @@ package models import ( "errors" + "time" ) type OauthType int @@ -26,12 +27,15 @@ var ( ) type Oauth2 struct { - Id int64 - Uid int64 `xorm:"unique(s)"` // userId - User *User `xorm:"-"` - Type int `xorm:"unique(s) unique(oauth)"` // twitter,github,google... - Identity string `xorm:"unique(s) unique(oauth)"` // id.. - Token string `xorm:"TEXT not null"` + Id int64 + Uid int64 `xorm:"unique(s)"` // userId + User *User `xorm:"-"` + Type int `xorm:"unique(s) unique(oauth)"` // twitter,github,google... + Identity string `xorm:"unique(s) unique(oauth)"` // id.. + Token string `xorm:"TEXT not null"` + Created time.Time `xorm:"CREATED"` + Updated time.Time + HasRecentActivity bool `xorm:"-"` } func BindUserOauth2(userId, oauthId int64) error { @@ -69,10 +73,24 @@ func GetOauth2ById(id int64) (oa *Oauth2, err error) { return oa, nil } +// UpdateOauth2 updates given OAuth2. +func UpdateOauth2(oa *Oauth2) error { + _, err := x.Id(oa.Id).AllCols().Update(oa) + return err +} + // GetOauthByUserId returns list of oauthes that are releated to given user. -func GetOauthByUserId(uid int64) (oas []*Oauth2, err error) { - err = x.Find(&oas, Oauth2{Uid: uid}) - return oas, err +func GetOauthByUserId(uid int64) ([]*Oauth2, error) { + socials := make([]*Oauth2, 0, 5) + err := x.Find(&socials, Oauth2{Uid: uid}) + if err != nil { + return nil, err + } + + for _, social := range socials { + social.HasRecentActivity = social.Updated.Add(7 * 24 * time.Hour).After(time.Now()) + } + return socials, err } // DeleteOauth2ById deletes a oauth2 by ID. |