#3515 use alert instead 500 for duplicated login source name

This commit is contained in:
Unknwon 2016-08-31 00:56:10 -07:00
parent cd9b926af7
commit 99c2ae7b35
7 changed files with 47 additions and 23 deletions

View file

@ -146,13 +146,18 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
return
}
if err := models.CreateSource(&models.LoginSource{
if err := models.CreateLoginSource(&models.LoginSource{
Type: models.LoginType(form.Type),
Name: form.Name,
IsActived: form.IsActive,
Cfg: config,
}); err != nil {
ctx.Handle(500, "CreateSource", err)
if models.IsErrLoginSourceAlreadyExist(err) {
ctx.Data["Err_Name"] = true
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), AUTH_NEW, form)
} else {
ctx.Handle(500, "CreateSource", err)
}
return
}

View file

@ -21,7 +21,7 @@ func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, l
source, err := models.GetLoginSourceByID(sourceID)
if err != nil {
if models.IsErrAuthenticationNotExist(err) {
if models.IsErrLoginSourceNotExist(err) {
ctx.Error(422, "", err)
} else {
ctx.Error(500, "GetLoginSourceByID", err)