fix new users could not be automatically created when signing in via oauth 2.0
This commit is contained in:
@@ -242,7 +242,6 @@ func (a *OAuth2AuthenticationApi) CallbackHandler(c *core.WebContext) (string, *
|
|||||||
Username: userName,
|
Username: userName,
|
||||||
Email: email,
|
Email: email,
|
||||||
Nickname: nickName,
|
Nickname: nickName,
|
||||||
Password: "",
|
|
||||||
Language: languageCode,
|
Language: languageCode,
|
||||||
DefaultCurrency: currencyCode,
|
DefaultCurrency: currencyCode,
|
||||||
FirstDayOfWeek: oauth2UserInfo.FirstDayOfWeek,
|
FirstDayOfWeek: oauth2UserInfo.FirstDayOfWeek,
|
||||||
@@ -251,7 +250,7 @@ func (a *OAuth2AuthenticationApi) CallbackHandler(c *core.WebContext) (string, *
|
|||||||
FeatureRestriction: a.CurrentConfig().DefaultFeatureRestrictions,
|
FeatureRestriction: a.CurrentConfig().DefaultFeatureRestrictions,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.users.CreateUser(c, user)
|
err = a.users.CreateUser(c, user, true)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[oauth2_authentications.CallbackHandler] failed to create user \"%s\", because %s", user.Username, err.Error())
|
log.Errorf(c, "[oauth2_authentications.CallbackHandler] failed to create user \"%s\", because %s", user.Username, err.Error())
|
||||||
@@ -260,7 +259,7 @@ func (a *OAuth2AuthenticationApi) CallbackHandler(c *core.WebContext) (string, *
|
|||||||
|
|
||||||
log.Infof(c, "[oauth2_authentications.CallbackHandler] user \"%s\" has registered successfully, uid is %d", user.Username, user.Uid)
|
log.Infof(c, "[oauth2_authentications.CallbackHandler] user \"%s\" has registered successfully, uid is %d", user.Username, user.Uid)
|
||||||
|
|
||||||
userExternalAuth := &models.UserExternalAuth{
|
userExternalAuth = &models.UserExternalAuth{
|
||||||
Uid: user.Uid,
|
Uid: user.Uid,
|
||||||
ExternalAuthType: userExternalAuthType,
|
ExternalAuthType: userExternalAuthType,
|
||||||
ExternalUsername: oauth2UserInfo.UserName,
|
ExternalUsername: oauth2UserInfo.UserName,
|
||||||
|
|||||||
+1
-1
@@ -83,7 +83,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.WebContext) (any, *errs.Error) {
|
|||||||
FeatureRestriction: a.CurrentConfig().DefaultFeatureRestrictions,
|
FeatureRestriction: a.CurrentConfig().DefaultFeatureRestrictions,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.users.CreateUser(c, user)
|
err = a.users.CreateUser(c, user, false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[users.UserRegisterHandler] failed to create user \"%s\", because %s", user.Username, err.Error())
|
log.Errorf(c, "[users.UserRegisterHandler] failed to create user \"%s\", because %s", user.Username, err.Error())
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func (l *UserDataCli) AddNewUser(c *core.CliContext, username string, email stri
|
|||||||
FeatureRestriction: l.CurrentConfig().DefaultFeatureRestrictions,
|
FeatureRestriction: l.CurrentConfig().DefaultFeatureRestrictions,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := l.users.CreateUser(c, user)
|
err := l.users.CreateUser(c, user, false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.CliErrorf(c, "[user_data.AddNewUser] failed to create user \"%s\", because %s", user.Username, err.Error())
|
log.CliErrorf(c, "[user_data.AddNewUser] failed to create user \"%s\", because %s", user.Username, err.Error())
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ func (s *UserService) GetUserAvatar(c core.Context, uid int64, fileExtension str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateUser saves a new user model to database
|
// CreateUser saves a new user model to database
|
||||||
func (s *UserService) CreateUser(c core.Context, user *models.User) error {
|
func (s *UserService) CreateUser(c core.Context, user *models.User, noPassword bool) error {
|
||||||
exists, err := s.ExistsUsername(c, user.Username)
|
exists, err := s.ExistsUsername(c, user.Username)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -201,7 +201,7 @@ func (s *UserService) CreateUser(c core.Context, user *models.User) error {
|
|||||||
return errs.ErrUserEmailAlreadyExists
|
return errs.ErrUserEmailAlreadyExists
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.Password == "" {
|
if !noPassword && user.Password == "" {
|
||||||
return errs.ErrPasswordIsEmpty
|
return errs.ErrPasswordIsEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +215,11 @@ func (s *UserService) CreateUser(c core.Context, user *models.User) error {
|
|||||||
return errs.ErrSystemIsBusy
|
return errs.ErrSystemIsBusy
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Password = utils.EncodePassword(user.Password, user.Salt)
|
if !noPassword {
|
||||||
|
user.Password = utils.EncodePassword(user.Password, user.Salt)
|
||||||
|
} else {
|
||||||
|
user.Password = ""
|
||||||
|
}
|
||||||
|
|
||||||
user.Deleted = false
|
user.Deleted = false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user