MCPcopy Create free account
hub / github.com/gogs/gogs / EditAuthSourcePost

Function EditAuthSourcePost

internal/route/admin/auths.go:210–273  ·  view source on GitHub ↗
(c *context.Context, f form.Authentication)

Source from the content-addressed store, hash-verified

208}
209
210func EditAuthSourcePost(c *context.Context, f form.Authentication) {
211 c.Title("admin.auths.edit")
212 c.PageIs("Admin")
213 c.PageIs("AdminAuthentications")
214
215 c.Data["SMTPAuths"] = smtp.AuthTypes
216
217 source, err := database.Handle.LoginSources().GetByID(c.Req.Context(), c.ParamsInt64(":authid"))
218 if err != nil {
219 c.Error(err, "get login source by ID")
220 return
221 }
222 c.Data["Source"] = source
223 c.Data["HasTLS"] = source.Provider.HasTLS()
224
225 if c.HasError() {
226 c.HTML(http.StatusBadRequest, tmplAdminAuthEdit)
227 return
228 }
229
230 var provider auth.Provider
231 switch auth.Type(f.Type) {
232 case auth.LDAP:
233 provider = ldap.NewProvider(false, parseLDAPConfig(f))
234 case auth.DLDAP:
235 provider = ldap.NewProvider(true, parseLDAPConfig(f))
236 case auth.SMTP:
237 provider = smtp.NewProvider(parseSMTPConfig(f))
238 case auth.PAM:
239 provider = pam.NewProvider(&pam.Config{
240 ServiceName: f.PAMServiceName,
241 })
242 case auth.GitHub:
243 provider = github.NewProvider(&github.Config{
244 APIEndpoint: strings.TrimSuffix(f.GitHubAPIEndpoint, "/") + "/",
245 SkipVerify: f.SkipVerify,
246 })
247 default:
248 c.Status(http.StatusBadRequest)
249 return
250 }
251
252 source.Name = f.Name
253 source.IsActived = f.IsActive
254 source.IsDefault = f.IsDefault
255 source.Provider = provider
256 if err := database.Handle.LoginSources().Save(c.Req.Context(), source); err != nil {
257 c.Error(err, "update login source")
258 return
259 }
260
261 if source.IsDefault {
262 err = database.Handle.LoginSources().ResetNonDefault(c.Req.Context(), source)
263 if err != nil {
264 c.Error(err, "reset non-default login sources")
265 return
266 }
267 }

Callers

nothing calls this directly

Calls 15

TypeTypeAlias · 0.92
NewProviderFunction · 0.92
NewProviderFunction · 0.92
NewProviderFunction · 0.92
NewProviderFunction · 0.92
parseLDAPConfigFunction · 0.85
parseSMTPConfigFunction · 0.85
TitleMethod · 0.80
PageIsMethod · 0.80
LoginSourcesMethod · 0.80
HasErrorMethod · 0.80
HTMLMethod · 0.80

Tested by

no test coverage detected