1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-09 11:08:19 +00:00

Fix 500 error if there is a name conflict when edit authentication source (#23832) (#23852)

Backport #23832 by @yp05327

Co-authored-by: yp05327 <576951401@qq.com>
This commit is contained in:
Giteabot
2023-03-31 12:53:25 -04:00
committed by GitHub
parent 503af4b807
commit 16bfe983c2
2 changed files with 12 additions and 3 deletions

View File

@@ -426,9 +426,11 @@ func EditAuthSourcePost(ctx *context.Context) {
source.IsActive = form.IsActive
source.IsSyncEnabled = form.IsSyncEnabled
source.Cfg = config
// FIXME: if the name conflicts, it will result in 500: Error 1062: Duplicate entry 'aa' for key 'login_source.UQE_login_source_name'
if err := auth.UpdateSource(source); err != nil {
if oauth2.IsErrOpenIDConnectInitialize(err) {
if auth.IsErrSourceAlreadyExist(err) {
ctx.Data["Err_Name"] = true
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(auth.ErrSourceAlreadyExist).Name), tplAuthEdit, form)
} else if oauth2.IsErrOpenIDConnectInitialize(err) {
ctx.Flash.Error(err.Error(), true)
ctx.Data["Err_DiscoveryURL"] = true
ctx.HTML(http.StatusOK, tplAuthEdit)