Skip to content

Commit 29e47ef

Browse files
committed
Show error if admin tries to add a second authentication source of type SSPI
1 parent e6dca6b commit 29e47ef

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

models/login_source.go

+9
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ func LoginSources() ([]*LoginSource, error) {
334334
return auths, x.Find(&auths)
335335
}
336336

337+
// LoginSourcesByType returns all sources of the specified type
338+
func LoginSourcesByType(loginType LoginType) ([]*LoginSource, error) {
339+
sources := make([]*LoginSource, 0, 1)
340+
if err := x.Where("type = ?", loginType).Find(&sources); err != nil {
341+
return nil, err
342+
}
343+
return sources, nil
344+
}
345+
337346
// ActiveLoginSources returns all active sources of the specified type
338347
func ActiveLoginSources(loginType LoginType) ([]*LoginSource, error) {
339348
sources := make([]*LoginSource, 0, 1)

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,7 @@ auths.delete_auth_desc = Deleting an authentication source prevents users from u
18491849
auths.still_in_used = The authentication source is still in use. Convert or delete any users using this authentication source first.
18501850
auths.deletion_success = The authentication source has been deleted.
18511851
auths.login_source_exist = The authentication source '%s' already exists.
1852+
auths.login_source_of_type_exist = An authentication source of this type already exists.
18521853

18531854
config.server_config = Server Configuration
18541855
config.app_name = Site Title

routers/admin/auths.go

+6
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
233233
ctx.RenderWithErr(err.Error(), tplAuthNew, form)
234234
return
235235
}
236+
existing, err := models.LoginSourcesByType(models.LoginSSPI)
237+
if err != nil || len(existing) > 0 {
238+
ctx.Data["Err_Type"] = true
239+
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_of_type_exist"), tplAuthNew, form)
240+
return
241+
}
236242
default:
237243
ctx.Error(400)
238244
return

0 commit comments

Comments
 (0)