summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-05 11:14:17 +0800
committerUnknwon <u@gogs.io>2015-08-05 11:14:17 +0800
commite50982f5ec78c3cfa4a1cf322f7fa1a4dea44b84 (patch)
treef6dffcf1c5a273a077a8b33c75334b9994ca02ff /models
parent487fc8ca39a3de565fc6c67aea72c4658bbf64c8 (diff)
downloadgitea-e50982f5ec78c3cfa4a1cf322f7fa1a4dea44b84.tar.gz
gitea-e50982f5ec78c3cfa4a1cf322f7fa1a4dea44b84.zip
allow anonymous SSH clone
Diffstat (limited to 'models')
-rw-r--r--models/error.go14
-rw-r--r--models/issue.go4
-rw-r--r--models/login.go12
-rw-r--r--models/repo.go2
-rw-r--r--models/user.go13
5 files changed, 29 insertions, 16 deletions
diff --git a/models/error.go b/models/error.go
index 04f850def9..067eace239 100644
--- a/models/error.go
+++ b/models/error.go
@@ -54,6 +54,20 @@ func (err ErrUserAlreadyExist) Error() string {
return fmt.Sprintf("user already exists: [name: %s]", err.Name)
}
+type ErrUserNotExist struct {
+ UID int64
+ Name string
+}
+
+func IsErrUserNotExist(err error) bool {
+ _, ok := err.(ErrUserNotExist)
+ return ok
+}
+
+func (err ErrUserNotExist) Error() string {
+ return fmt.Sprintf("user does not exist: [uid: %d, name: %s]", err.UID, err.Name)
+}
+
type ErrEmailAlreadyUsed struct {
Email string
}
diff --git a/models/issue.go b/models/issue.go
index f9930aa677..77b38cbc0a 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -57,7 +57,7 @@ type Issue struct {
func (i *Issue) GetPoster() (err error) {
i.Poster, err = GetUserById(i.PosterId)
- if err == ErrUserNotExist {
+ if IsErrUserNotExist(err) {
i.Poster = &User{Name: "FakeUser"}
return nil
}
@@ -92,7 +92,7 @@ func (i *Issue) GetAssignee() (err error) {
return nil
}
i.Assignee, err = GetUserById(i.AssigneeId)
- if err == ErrUserNotExist {
+ if IsErrUserNotExist(err) {
return nil
}
return err
diff --git a/models/login.go b/models/login.go
index 10f782beec..82cea35f4c 100644
--- a/models/login.go
+++ b/models/login.go
@@ -41,7 +41,7 @@ var (
var LoginTypes = map[LoginType]string{
LDAP: "LDAP",
SMTP: "SMTP",
- PAM: "PAM",
+ PAM: "PAM",
}
// Ensure structs implemented interface.
@@ -192,7 +192,7 @@ func UserSignIn(uname, passwd string) (*User, error) {
// Now verify password.
if u.LoginType == PLAIN {
if !u.ValidatePassword(passwd) {
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{u.Id, u.Name}
}
return u, nil
}
@@ -229,7 +229,7 @@ func UserSignIn(uname, passwd string) (*User, error) {
}
}
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{u.Id, u.Name}
}
var source LoginSource
@@ -261,7 +261,7 @@ func LoginUserLdapSource(u *User, name, passwd string, sourceId int64, cfg *LDAP
name, fn, sn, mail, logged := cfg.Ldapsource.SearchEntry(name, passwd)
if !logged {
// User not in LDAP, do nothing
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{u.Id, u.Name}
}
if !autoRegister {
return u, nil
@@ -362,7 +362,7 @@ func LoginUserSMTPSource(u *User, name, passwd string, sourceId int64, cfg *SMTP
if err := SmtpAuth(cfg.Host, cfg.Port, auth, cfg.TLS); err != nil {
if strings.Contains(err.Error(), "Username and Password not accepted") {
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{u.Id, u.Name}
}
return nil, err
}
@@ -397,7 +397,7 @@ func LoginUserSMTPSource(u *User, name, passwd string, sourceId int64, cfg *SMTP
func LoginUserPAMSource(u *User, name, passwd string, sourceId int64, cfg *PAMConfig, autoRegister bool) (*User, error) {
if err := pam.PAMAuth(cfg.ServiceName, name, passwd); err != nil {
if strings.Contains(err.Error(), "Authentication failure") {
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{u.Id, u.Name}
}
return nil, err
}
diff --git a/models/repo.go b/models/repo.go
index a2b29ff31b..117837fc56 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -624,7 +624,7 @@ func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{repo.OwnerId, ""}
}
}
diff --git a/models/user.go b/models/user.go
index e239ea174d..c5d4b9d914 100644
--- a/models/user.go
+++ b/models/user.go
@@ -36,7 +36,6 @@ const (
)
var (
- ErrUserNotExist = errors.New("User does not exist")
ErrUserNotKeyOwner = errors.New("User does not the owner of public key")
ErrEmailNotExist = errors.New("E-mail does not exist")
ErrEmailNotActivated = errors.New("E-mail address has not been activated")
@@ -555,7 +554,7 @@ func getUserById(e Engine, id int64) (*User, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{id, ""}
}
return u, nil
}
@@ -568,14 +567,14 @@ func GetUserById(id int64) (*User, error) {
// GetUserByName returns user by given name.
func GetUserByName(name string) (*User, error) {
if len(name) == 0 {
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{0, name}
}
u := &User{LowerName: strings.ToLower(name)}
has, err := x.Get(u)
if err != nil {
return nil, err
} else if !has {
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{0, name}
}
return u, nil
}
@@ -700,7 +699,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
if err != nil {
return err
} else if !has {
- return ErrUserNotExist
+ return ErrUserNotExist{email.Uid, ""}
}
// Make sure the former primary email doesn't disappear
@@ -763,7 +762,7 @@ func ValidateCommitsWithEmails(oldCommits *list.List) *list.List {
// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(email string) (*User, error) {
if len(email) == 0 {
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{0, "email"}
}
// First try to find the user by primary email
user := &User{Email: strings.ToLower(email)}
@@ -785,7 +784,7 @@ func GetUserByEmail(email string) (*User, error) {
return GetUserById(emailAddress.Uid)
}
- return nil, ErrUserNotExist
+ return nil, ErrUserNotExist{0, "email"}
}
// SearchUserByName returns given number of users whose name contains keyword.