]> source.dussan.org Git - gitea.git/commitdiff
fix #644
authorUnknwon <joe2010xtmf@163.com>
Fri, 21 Nov 2014 18:10:00 +0000 (13:10 -0500)
committerUnknwon <joe2010xtmf@163.com>
Fri, 21 Nov 2014 18:10:00 +0000 (13:10 -0500)
models/org.go
models/user.go

index 3232bf2ac13ca2d7d5f9d72a4984359ac3f0246a..90e5a1f3a09087537f05d1b0c9ce4ebf70bf32d6 100644 (file)
@@ -77,6 +77,17 @@ func (org *User) RemoveMember(uid int64) error {
        return RemoveOrgUser(org.Id, uid)
 }
 
+// IsOrgEmailUsed returns true if the e-mail has been used in organization account.
+func IsOrgEmailUsed(email string) (bool, error) {
+       if len(email) == 0 {
+               return false, nil
+       }
+       return x.Get(&User{
+               Email: email,
+               Type:  ORGANIZATION,
+       })
+}
+
 // CreateOrganization creates record of a new organization.
 func CreateOrganization(org, owner *User) (*User, error) {
        if !IsLegalName(org.Name) {
@@ -90,7 +101,7 @@ func CreateOrganization(org, owner *User) (*User, error) {
                return nil, ErrUserAlreadyExist
        }
 
-       isExist, err = IsEmailUsed(org.Email)
+       isExist, err = IsOrgEmailUsed(org.Email)
        if err != nil {
                return nil, err
        } else if isExist {
index c68ae31067fc531047fac4687dad913f69c3389b..b0cc2ae15639b05d744b57c7fb634354da9c70c9 100644 (file)
@@ -53,12 +53,12 @@ type User struct {
        LowerName   string `xorm:"UNIQUE NOT NULL"`
        Name        string `xorm:"UNIQUE NOT NULL"`
        FullName    string
-       Email       string `xorm:"UNIQUE NOT NULL"`
+       Email       string `xorm:"UNIQUE(s) NOT NULL"`
        Passwd      string `xorm:"NOT NULL"`
        LoginType   LoginType
        LoginSource int64 `xorm:"NOT NULL DEFAULT 0"`
        LoginName   string
-       Type        UserType
+       Type        UserType      `xorm:"UNIQUE(s)"`
        Orgs        []*User       `xorm:"-"`
        Repos       []*Repository `xorm:"-"`
        Location    string