Pārlūkot izejas kodu

Merge pull request #174 from qor5/fix-login-typo

fix login typo
xuxinx 1 gadu atpakaļ
vecāks
revīzija
99614f5210
2 mainītis faili ar 13 papildinājumiem un 13 dzēšanām
  1. 4 4
      login/builder.go
  2. 9 9
      login/oauth_user.go

+ 4 - 4
login/builder.go

@@ -520,9 +520,9 @@ func (b *Builder) completeUserAuthCallbackComplete(w http.ResponseWriter, r *htt
 				http.Redirect(w, r, b.LogoutURL, http.StatusFound)
 				return
 			}
-			// TODO: maybe the indentifier of some providers is not email
-			indentifier := ouser.Email
-			user, err = b.userModel.(OAuthUser).FindUserByOAuthIndentifier(b.db, b.newUserObject(), ouser.Provider, indentifier)
+			// TODO: maybe the identifier of some providers is not email
+			identifier := ouser.Email
+			user, err = b.userModel.(OAuthUser).FindUserByOAuthIdentifier(b.db, b.newUserObject(), ouser.Provider, identifier)
 			if err != nil {
 				if err == gorm.ErrRecordNotFound {
 					setFailCodeFlash(w, FailCodeUserNotFound)
@@ -532,7 +532,7 @@ func (b *Builder) completeUserAuthCallbackComplete(w http.ResponseWriter, r *htt
 				http.Redirect(w, r, b.LogoutURL, http.StatusFound)
 				return
 			}
-			err = user.(OAuthUser).InitOAuthUserID(b.db, b.newUserObject(), ouser.Provider, indentifier, ouser.UserID)
+			err = user.(OAuthUser).InitOAuthUserID(b.db, b.newUserObject(), ouser.Provider, identifier, ouser.UserID)
 			if err != nil {
 				setFailCodeFlash(w, FailCodeSystemError)
 				http.Redirect(w, r, b.LogoutURL, http.StatusFound)

+ 9 - 9
login/oauth_user.go

@@ -4,20 +4,20 @@ import "gorm.io/gorm"
 
 type OAuthUser interface {
 	FindUserByOAuthUserID(db *gorm.DB, model interface{}, provider string, oid string) (user interface{}, err error)
-	FindUserByOAuthIndentifier(db *gorm.DB, model interface{}, provider string, indentifier string) (user interface{}, err error)
-	InitOAuthUserID(db *gorm.DB, model interface{}, provider string, indentifier string, oid string) error
+	FindUserByOAuthIdentifier(db *gorm.DB, model interface{}, provider string, identifier string) (user interface{}, err error)
+	InitOAuthUserID(db *gorm.DB, model interface{}, provider string, identifier string, oid string) error
 	SetAvatar(v string)
 	GetAvatar() string
 }
 
 type OAuthInfo struct {
-	OAuthProvider string `gorm:"index:uidx_users_oauth_provider_user_id,unique,where:o_auth_provider!='' and o_auth_user_id!='' and deleted_at is null;index:uidx_users_oauth_provider_indentifier,unique,where:o_auth_provider!='' and o_auth_indentifier!='' and deleted_at is null"`
+	OAuthProvider string `gorm:"index:uidx_users_oauth_provider_user_id,unique,where:o_auth_provider!='' and o_auth_user_id!='' and deleted_at is null;index:uidx_users_oauth_provider_identifier,unique,where:o_auth_provider!='' and o_auth_identifier!='' and deleted_at is null"`
 	OAuthUserID   string `gorm:"index:uidx_users_oauth_provider_user_id,unique,where:o_auth_provider!='' and o_auth_user_id!='' and deleted_at is null"`
 	// users use this value to log into their account
 	// in most cases is email or account name
 	// it is used to find the user record on the first login
-	OAuthIndentifier string `gorm:"index:uidx_users_oauth_provider_indentifier,unique,where:o_auth_provider!='' and o_auth_indentifier!='' and deleted_at is null"`
-	OAuthAvatar      string `gorm:"-"`
+	OAuthIdentifier string `gorm:"index:uidx_users_oauth_provider_identifier,unique,where:o_auth_provider!='' and o_auth_identifier!='' and deleted_at is null"`
+	OAuthAvatar     string `gorm:"-"`
 }
 
 var _ OAuthUser = (*OAuthInfo)(nil)
@@ -32,8 +32,8 @@ func (oa *OAuthInfo) FindUserByOAuthUserID(db *gorm.DB, model interface{}, provi
 	return model, nil
 }
 
-func (oa *OAuthInfo) FindUserByOAuthIndentifier(db *gorm.DB, model interface{}, provider string, indentifier string) (user interface{}, err error) {
-	err = db.Where("o_auth_provider = ? and o_auth_indentifier = ?", provider, indentifier).
+func (oa *OAuthInfo) FindUserByOAuthIdentifier(db *gorm.DB, model interface{}, provider string, identifier string) (user interface{}, err error) {
+	err = db.Where("o_auth_provider = ? and o_auth_identifier = ?", provider, identifier).
 		First(model).
 		Error
 	if err != nil {
@@ -41,9 +41,9 @@ func (oa *OAuthInfo) FindUserByOAuthIndentifier(db *gorm.DB, model interface{},
 	}
 	return model, nil
 }
-func (oa *OAuthInfo) InitOAuthUserID(db *gorm.DB, model interface{}, provider string, indentifier string, oid string) error {
+func (oa *OAuthInfo) InitOAuthUserID(db *gorm.DB, model interface{}, provider string, identifier string, oid string) error {
 	err := db.Model(model).
-		Where("o_auth_provider = ? and o_auth_indentifier = ?", provider, indentifier).
+		Where("o_auth_provider = ? and o_auth_identifier = ?", provider, identifier).
 		Updates(map[string]interface{}{
 			"o_auth_user_id": oid,
 		}).