summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-04-13 18:12:07 -0400
committerUnknown <joe2010xtmf@163.com>2014-04-13 18:12:07 -0400
commit4b9b8024ba59b5b84d92dca650761b35ebf6408a (patch)
treef40ed3d56e5df158168cb38a5f3b479c17903362 /models
parent8c266f2df5848b230c6fbb0bc4578a8907edc725 (diff)
downloadgitea-4b9b8024ba59b5b84d92dca650761b35ebf6408a.tar.gz
gitea-4b9b8024ba59b5b84d92dca650761b35ebf6408a.zip
Clean oauth code
Diffstat (limited to 'models')
-rw-r--r--models/oauth2.go25
-rw-r--r--models/repo.go9
-rw-r--r--models/user.go2
3 files changed, 21 insertions, 15 deletions
diff --git a/models/oauth2.go b/models/oauth2.go
index f8780fe682..38d21fda1c 100644
--- a/models/oauth2.go
+++ b/models/oauth2.go
@@ -14,11 +14,15 @@ const (
OT_GOOGLE
OT_TWITTER
OT_QQ
+ OT_WEIBO
+ OT_BITBUCKET
+ OT_OSCHINA
+ OT_FACEBOOK
)
var (
- ErrOauth2RecordNotExists = errors.New("not exists oauth2 record")
- ErrOauth2NotAssociatedWithUser = errors.New("not associated with user")
+ ErrOauth2RecordNotExist = errors.New("OAuth2 record does not exist")
+ ErrOauth2NotAssociated = errors.New("OAuth2 is not associated with user")
)
type Oauth2 struct {
@@ -35,11 +39,9 @@ func BindUserOauth2(userId, oauthId int64) error {
return err
}
-func AddOauth2(oa *Oauth2) (err error) {
- if _, err = orm.Insert(oa); err != nil {
- return err
- }
- return nil
+func AddOauth2(oa *Oauth2) error {
+ _, err := orm.Insert(oa)
+ return err
}
func GetOauth2(identity string) (oa *Oauth2, err error) {
@@ -48,9 +50,9 @@ func GetOauth2(identity string) (oa *Oauth2, err error) {
if err != nil {
return
} else if !isExist {
- return nil, ErrOauth2RecordNotExists
+ return nil, ErrOauth2RecordNotExist
} else if oa.Uid == -1 {
- return oa, ErrOauth2NotAssociatedWithUser
+ return oa, ErrOauth2NotAssociated
}
oa.User, err = GetUserById(oa.Uid)
return oa, err
@@ -61,9 +63,8 @@ func GetOauth2ById(id int64) (oa *Oauth2, err error) {
has, err := orm.Id(id).Get(oa)
if err != nil {
return nil, err
- }
- if !has {
- return nil, ErrOauth2RecordNotExists
+ } else if !has {
+ return nil, ErrOauth2RecordNotExist
}
return oa, nil
}
diff --git a/models/repo.go b/models/repo.go
index 01736b631d..1a5a95f047 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -714,9 +714,14 @@ func GetRepositoryById(id int64) (*Repository, error) {
}
// GetRepositories returns the list of repositories of given user.
-func GetRepositories(user *User) ([]Repository, error) {
+func GetRepositories(user *User, private bool) ([]Repository, error) {
repos := make([]Repository, 0, 10)
- err := orm.Desc("updated").Find(&repos, &Repository{OwnerId: user.Id})
+ sess := orm.Desc("updated")
+ if !private {
+ sess.Where("is_private=?", false)
+ }
+
+ err := sess.Find(&repos, &Repository{OwnerId: user.Id})
return repos, err
}
diff --git a/models/user.go b/models/user.go
index ea2c79b771..ffee2dd9e5 100644
--- a/models/user.go
+++ b/models/user.go
@@ -234,7 +234,7 @@ func ChangeUserName(user *User, newUserName string) (err error) {
}
}
- repos, err := GetRepositories(user)
+ repos, err := GetRepositories(user, true)
if err != nil {
return err
}