Skip to content

Commit 44554d5

Browse files
committed
Fix add authentication page
There is a regression in go-gitea#16199 whereby the add authentication page fails to react to the change in selected type. This is due to the String() method on the LoginSourceType which is ameliorated with an Int() function being added. Following on from this there are a few other related bugs. Fix go-gitea#16541 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent d717c69 commit 44554d5

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

models/login_source.go

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func (typ LoginType) String() string {
3636
return LoginNames[typ]
3737
}
3838

39+
// String returns the string name of the LoginType
40+
func (typ LoginType) Int() int {
41+
return int(typ)
42+
}
43+
3944
// LoginNames contains the name of LoginType values.
4045
var LoginNames = map[LoginType]string{
4146
LoginLDAP: "LDAP (via BindDN)",
@@ -218,6 +223,10 @@ func CreateLoginSource(source *LoginSource) error {
218223
return nil
219224
}
220225

226+
if settable, ok := source.Cfg.(LoginSourceSettable); ok {
227+
settable.SetLoginSource(source)
228+
}
229+
221230
registerableSource, ok := source.Cfg.(RegisterableSource)
222231
if !ok {
223232
return nil

services/auth/source/ldap/security_protocol.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func (s SecurityProtocol) String() string {
1919
return SecurityProtocolNames[s]
2020
}
2121

22+
// String returns the name of the SecurityProtocol
23+
func (s SecurityProtocol) Int() int {
24+
return int(s)
25+
}
26+
2227
// SecurityProtocolNames contains the name of SecurityProtocol values.
2328
var SecurityProtocolNames = map[SecurityProtocol]string{
2429
SecurityProtocolUnencrypted: "Unencrypted",

templates/admin/auth/edit.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<input type="hidden" name="id" value="{{.Source.ID}}">
1313
<div class="inline field">
1414
<label>{{$.i18n.Tr "admin.auths.auth_type"}}</label>
15-
<input type="hidden" id="auth_type" name="type" value="{{.Source.Type}}">
15+
<input type="hidden" id="auth_type" name="type" value="{{.Source.Type.Int}}">
1616
<span>{{.Source.TypeName}}</span>
1717
</div>
1818
<div class="required inline field {{if .Err_Name}}error{{end}}">
@@ -31,7 +31,7 @@
3131
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
3232
<div class="menu">
3333
{{range .SecurityProtocols}}
34-
<div class="item" data-value="{{.Type}}">{{.Name}}</div>
34+
<div class="item" data-value="{{.Type.Int}}">{{.Name}}</div>
3535
{{end}}
3636
</div>
3737
</div>

templates/admin/auth/new.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
<div class="inline required field {{if .Err_Type}}error{{end}}">
1414
<label>{{.i18n.Tr "admin.auths.auth_type"}}</label>
1515
<div class="ui selection type dropdown">
16-
<input type="hidden" id="auth_type" name="type" value="{{.type}}">
16+
<input type="hidden" id="auth_type" name="type" value="{{.type.Int}}">
1717
<div class="text">{{.CurrentTypeName}}</div>
1818
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
1919
<div class="menu">
2020
{{range .AuthSources}}
21-
<div class="item" data-value="{{.Type}}">{{.Name}}</div>
21+
<div class="item" data-value="{{.Type.Int}}">{{.Name}}</div>
2222
{{end}}
2323
</div>
2424
</div>

templates/admin/auth/source/ldap.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
88
<div class="menu">
99
{{range .SecurityProtocols}}
10-
<div class="item" data-value="{{.Type}}">{{.Name}}</div>
10+
<div class="item" data-value="{{.Type.Int}}">{{.Name}}</div>
1111
{{end}}
1212
</div>
1313
</div>

0 commit comments

Comments
 (0)