Bladeren bron

db: remove `db.User.LoginType` field (#6122)

Kousik Mitra 4 jaren geleden
bovenliggende
commit
5a52ee75e3
5 gewijzigde bestanden met toevoegingen van 14 en 25 verwijderingen
  1. 0 4
      internal/db/login_source.go
  2. 4 5
      internal/db/user.go
  3. 1 1
      internal/db/users.go
  4. 4 8
      internal/route/admin/users.go
  5. 5 7
      internal/route/api/v1/admin/user.go

+ 0 - 4
internal/db/login_source.go

@@ -105,7 +105,6 @@ func LoginViaLDAP(login, password string, source *LoginSource, autoRegister bool
 		Name:        username,
 		FullName:    composeFullName(fn, sn, username),
 		Email:       mail,
-		LoginType:   source.Type,
 		LoginSource: source.ID,
 		LoginName:   login,
 		IsActive:    true,
@@ -245,7 +244,6 @@ func LoginViaSMTP(login, password string, sourceID int64, cfg *SMTPConfig, autoR
 		Name:        strings.ToLower(username),
 		Email:       login,
 		Passwd:      password,
-		LoginType:   LoginSMTP,
 		LoginSource: sourceID,
 		LoginName:   login,
 		IsActive:    true,
@@ -281,7 +279,6 @@ func LoginViaPAM(login, password string, sourceID int64, cfg *PAMConfig, autoReg
 		Name:        login,
 		Email:       login,
 		Passwd:      password,
-		LoginType:   LoginPAM,
 		LoginSource: sourceID,
 		LoginName:   login,
 		IsActive:    true,
@@ -317,7 +314,6 @@ func LoginViaGitHub(login, password string, sourceID int64, cfg *GitHubConfig, a
 		Email:       email,
 		Website:     url,
 		Passwd:      password,
-		LoginType:   LoginGitHub,
 		LoginSource: sourceID,
 		LoginName:   login,
 		IsActive:    true,

+ 4 - 5
internal/db/user.go

@@ -53,10 +53,9 @@ type User struct {
 	Name      string `xorm:"UNIQUE NOT NULL" gorm:"NOT NULL"`
 	FullName  string
 	// Email is the primary email address (to be used for communication)
-	Email       string    `xorm:"NOT NULL" gorm:"NOT NULL"`
-	Passwd      string    `xorm:"NOT NULL" gorm:"NOT NULL"`
-	LoginType   LoginType // TODO: Remove me https://github.com/gogs/gogs/issues/6117.
-	LoginSource int64     `xorm:"NOT NULL DEFAULT 0" gorm:"NOT NULL;DEFAULT:0"`
+	Email       string `xorm:"NOT NULL" gorm:"NOT NULL"`
+	Passwd      string `xorm:"NOT NULL" gorm:"NOT NULL"`
+	LoginSource int64  `xorm:"NOT NULL DEFAULT 0" gorm:"NOT NULL;DEFAULT:0"`
 	LoginName   string
 	Type        UserType
 	OwnedOrgs   []*User       `xorm:"-" gorm:"-" json:"-"`
@@ -142,7 +141,7 @@ func (u *User) APIFormat() *api.User {
 
 // returns true if user login type is LoginPlain.
 func (u *User) IsLocal() bool {
-	return u.LoginType <= LoginPlain
+	return u.LoginSource <= 0
 }
 
 // HasForkedRepo checks if user has already forked a repository with given ID.

+ 1 - 1
internal/db/users.go

@@ -98,7 +98,7 @@ func (db *users) Authenticate(login, password string, loginSourceID int64) (*Use
 		}
 
 		// Validate password hash fetched from database for local accounts.
-		if user.LoginType == LoginNotype || user.LoginType == LoginPlain {
+		if user.IsLocal() {
 			if user.ValidatePassword(password) {
 				return user, nil
 			}

+ 4 - 8
internal/route/admin/users.go

@@ -77,17 +77,15 @@ func NewUserPost(c *context.Context, f form.AdminCrateUser) {
 	}
 
 	u := &db.User{
-		Name:      f.UserName,
-		Email:     f.Email,
-		Passwd:    f.Password,
-		IsActive:  true,
-		LoginType: db.LoginPlain,
+		Name:     f.UserName,
+		Email:    f.Email,
+		Passwd:   f.Password,
+		IsActive: true,
 	}
 
 	if len(f.LoginType) > 0 {
 		fields := strings.Split(f.LoginType, "-")
 		if len(fields) == 2 {
-			u.LoginType = db.LoginType(com.StrTo(fields[0]).MustInt())
 			u.LoginSource = com.StrTo(fields[1]).MustInt64()
 			u.LoginName = f.LoginName
 		}
@@ -180,12 +178,10 @@ func EditUserPost(c *context.Context, f form.AdminEditUser) {
 
 	fields := strings.Split(f.LoginType, "-")
 	if len(fields) == 2 {
-		loginType := db.LoginType(com.StrTo(fields[0]).MustInt())
 		loginSource := com.StrTo(fields[1]).MustInt64()
 
 		if u.LoginSource != loginSource {
 			u.LoginSource = loginSource
-			u.LoginType = loginType
 		}
 	}
 

+ 5 - 7
internal/route/api/v1/admin/user.go

@@ -32,19 +32,17 @@ func parseLoginSource(c *context.APIContext, u *db.User, sourceID int64, loginNa
 		return
 	}
 
-	u.LoginType = source.Type
 	u.LoginSource = source.ID
 	u.LoginName = loginName
 }
 
 func CreateUser(c *context.APIContext, form api.CreateUserOption) {
 	u := &db.User{
-		Name:      form.Username,
-		FullName:  form.FullName,
-		Email:     form.Email,
-		Passwd:    form.Password,
-		IsActive:  true,
-		LoginType: db.LoginPlain,
+		Name:     form.Username,
+		FullName: form.FullName,
+		Email:    form.Email,
+		Passwd:   form.Password,
+		IsActive: true,
 	}
 
 	parseLoginSource(c, u, form.SourceID, form.LoginName)