aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/oauth2.go34
-rw-r--r--models/repo.go13
-rw-r--r--models/user.go11
3 files changed, 41 insertions, 17 deletions
diff --git a/models/oauth2.go b/models/oauth2.go
index a17d4e30..45728b0d 100644
--- a/models/oauth2.go
+++ b/models/oauth2.go
@@ -1,6 +1,10 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
package models
-import "fmt"
+import "errors"
// OT: Oauth2 Type
const (
@@ -9,12 +13,18 @@ const (
OT_TWITTER
)
+var (
+ ErrOauth2RecordNotExists = errors.New("not exists oauth2 record")
+ ErrOauth2NotAssociatedWithUser = errors.New("not associated with user")
+)
+
type Oauth2 struct {
- Uid int64 `xorm:"pk"` // userId
+ Id int64
+ Uid int64 // userId
+ User *User `xorm:"-"`
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) {
@@ -24,16 +34,16 @@ func AddOauth2(oa *Oauth2) (err error) {
return nil
}
-func GetOauth2User(identity string) (u *User, err error) {
- oa := &Oauth2{}
- oa.Identity = identity
- exists, err := orm.Get(oa)
+func GetOauth2(identity string) (oa *Oauth2, err error) {
+ oa = &Oauth2{Identity: identity}
+ isExist, err := orm.Get(oa)
if err != nil {
return
+ } else if !isExist {
+ return nil, ErrOauth2RecordNotExists
+ } else if oa.Uid == 0 {
+ return oa, ErrOauth2NotAssociatedWithUser
}
- if !exists {
- err = fmt.Errorf("not exists oauth2: %s", identity)
- return
- }
- return GetUserById(oa.Uid)
+ oa.User, err = GetUserById(oa.Uid)
+ return oa, err
}
diff --git a/models/repo.go b/models/repo.go
index bb5c3637..573e0f4e 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -79,6 +79,7 @@ type Repository struct {
NumOpenIssues int `xorm:"-"`
IsPrivate bool
IsBare bool
+ IsGoget bool
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
@@ -261,6 +262,13 @@ func createHookUpdate(hookPath, content string) error {
return err
}
+// SetRepoEnvs sets environment variables for command update.
+func SetRepoEnvs(userId int64, userName, repoName string) {
+ os.Setenv("userId", base.ToStr(userId))
+ os.Setenv("userName", userName)
+ os.Setenv("repoName", repoName)
+}
+
// InitRepository initializes README and .gitignore if needed.
func initRepository(f string, user *User, repo *Repository, initReadme bool, repoLang, license string) error {
repoPath := RepoPath(user.Name, repo.Name)
@@ -333,10 +341,7 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
return nil
}
- // for update use
- os.Setenv("userName", user.Name)
- os.Setenv("userId", base.ToStr(user.Id))
- os.Setenv("repoName", repo.Name)
+ SetRepoEnvs(user.Id, user.Name, repo.Name)
// Apply changes and commit.
return initRepoCommit(tmpDir, user.NewGitSig())
diff --git a/models/user.go b/models/user.go
index 0fcf7243..b2fddd0a 100644
--- a/models/user.go
+++ b/models/user.go
@@ -289,11 +289,21 @@ func DeleteUser(user *User) error {
// TODO: check issues, other repos' commits
+ // Delete all followers.
+ if _, err = orm.Delete(&Follow{FollowId: user.Id}); err != nil {
+ return err
+ }
+
// Delete all feeds.
if _, err = orm.Delete(&Action{UserId: user.Id}); err != nil {
return err
}
+ // Delete all watches.
+ if _, err = orm.Delete(&Watch{UserId: user.Id}); err != nil {
+ return err
+ }
+
// Delete all accesses.
if _, err = orm.Delete(&Access{UserName: user.LowerName}); err != nil {
return err
@@ -316,7 +326,6 @@ func DeleteUser(user *User) error {
}
_, err = orm.Delete(user)
- // TODO: delete and update follower information.
return err
}