func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { ctx.Data["Title"] = ctx.Tr("admin.auths.edit") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["PageIsAuths"] = true ctx.Data["LoginTypes"] = models.LoginTypes ctx.Data["SMTPAuths"] = models.SMTPAuths if ctx.HasError() { ctx.HTML(200, AUTH_EDIT) return } var config core.Conversion switch models.LoginType(form.Type) { case models.LDAP: config = &models.LDAPConfig{ Ldapsource: ldap.Ldapsource{ Host: form.Host, Port: form.Port, UseSSL: form.UseSSL, BaseDN: form.BaseDN, Attributes: form.Attributes, Filter: form.Filter, MsAdSAFormat: form.MsAdSA, Enabled: true, Name: form.AuthName, }, } case models.SMTP: config = &models.SMTPConfig{ Auth: form.SmtpAuth, Host: form.SmtpHost, Port: form.SmtpPort, TLS: form.Tls, } default: ctx.Error(400) return } u := models.LoginSource{ Id: form.Id, Name: form.AuthName, IsActived: form.IsActived, Type: models.LoginType(form.Type), AllowAutoRegister: form.AllowAutoRegister, Cfg: config, } if err := models.UpdateSource(&u); err != nil { ctx.Handle(500, "UpdateSource", err) return } log.Trace("Authentication changed by admin(%s): %s", ctx.User.Name, form.AuthName) ctx.Flash.Success(ctx.Tr("admin.auths.update_success")) ctx.Redirect("/admin/auths/" + ctx.Params(":authid")) }
func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { ctx.Data["Title"] = "Edit Authentication" ctx.Data["PageIsAuths"] = true ctx.Data["LoginTypes"] = models.LoginTypes ctx.Data["SMTPAuths"] = models.SMTPAuths if ctx.HasError() { ctx.HTML(200, "admin/auths/edit") return } var config core.Conversion switch form.Type { case models.LT_LDAP: config = &models.LDAPConfig{ Ldapsource: ldap.Ldapsource{ Host: form.Host, Port: form.Port, UseSSL: form.UseSSL, BaseDN: form.BaseDN, Attributes: form.Attributes, Filter: form.Filter, MsAdSAFormat: form.MsAdSA, Enabled: true, Name: form.AuthName, }, } case models.LT_SMTP: config = &models.SMTPConfig{ Auth: form.SmtpAuth, Host: form.SmtpHost, Port: form.SmtpPort, TLS: form.Tls, } default: ctx.Error(400) return } u := models.LoginSource{ Id: form.Id, Name: form.AuthName, IsActived: form.IsActived, Type: form.Type, AllowAutoRegister: form.AllowAutoRegister, Cfg: config, } if err := models.UpdateSource(&u); err != nil { ctx.Handle(500, "admin.auths.EditAuth", err) return } log.Trace("%s Authentication changed by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, form.AuthName) ctx.Redirect("/admin/auths") }
func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) { ctx.Data["Title"] = ctx.Tr("admin.auths.edit") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["SMTPAuths"] = models.SMTPAuths source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) if err != nil { ctx.Handle(500, "GetLoginSourceByID", err) return } ctx.Data["Source"] = source ctx.Data["HasTLS"] = source.HasTLS() if ctx.HasError() { ctx.HTML(200, AUTH_EDIT) return } var config core.Conversion switch models.LoginType(form.Type) { case models.LOGIN_LDAP, models.LOGIN_DLDAP: config = parseLDAPConfig(form) case models.LOGIN_SMTP: config = parseSMTPConfig(form) case models.LOGIN_PAM: config = &models.PAMConfig{ ServiceName: form.PAMServiceName, } default: ctx.Error(400) return } source.Name = form.Name source.IsActived = form.IsActive source.Cfg = config if err := models.UpdateSource(source); err != nil { ctx.Handle(500, "UpdateSource", err) return } log.Trace("Authentication changed by admin(%s): %s", ctx.User.Name, source.ID) ctx.Flash.Success(ctx.Tr("admin.auths.update_success")) ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + com.ToStr(form.ID)) }
func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { ctx.Data["Title"] = ctx.Tr("admin.auths.edit") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["PageIsAuths"] = true // ctx.Data["LoginTypes"] = models.LoginTypes ctx.Data["SMTPAuths"] = models.SMTPAuths if ctx.HasError() { ctx.HTML(200, AUTH_EDIT) return } var config core.Conversion switch models.LoginType(form.Type) { case models.LDAP: fallthrough case models.DLDAP: config = &models.LDAPConfig{ Ldapsource: ldap.Ldapsource{ Name: form.Name, Host: form.Host, Port: form.Port, UseSSL: form.UseSSL, BindDN: form.BindDN, UserDN: form.UserDN, BindPassword: form.BindPassword, UserBase: form.UserBase, AttributeName: form.AttributeName, AttributeSurname: form.AttributeSurname, AttributeMail: form.AttributeMail, Filter: form.Filter, AdminFilter: form.AdminFilter, Enabled: true, }, } case models.SMTP: config = &models.SMTPConfig{ Auth: form.SMTPAuth, Host: form.SMTPHost, Port: form.SMTPPort, TLS: form.TLS, SkipVerify: form.SkipVerify, } case models.PAM: config = &models.PAMConfig{ ServiceName: form.PAMServiceName, } default: ctx.Error(400) return } u := models.LoginSource{ ID: form.ID, Name: form.Name, IsActived: form.IsActive, Type: models.LoginType(form.Type), AllowAutoRegister: form.AllowAutoRegister, Cfg: config, } if err := models.UpdateSource(&u); err != nil { ctx.Handle(500, "UpdateSource", err) return } log.Trace("Authentication changed by admin(%s): %s", ctx.User.Name, form.Name) ctx.Flash.Success(ctx.Tr("admin.auths.update_success")) ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + ctx.Params(":authid")) }