auths.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package admin
  2. import (
  3. "strings"
  4. "github.com/gogits/gogs/models"
  5. "github.com/gogits/gogs/modules/auth"
  6. "github.com/gogits/gogs/modules/auth/ldap"
  7. "github.com/gogits/gogs/modules/middleware"
  8. "github.com/gpmgo/gopm/log"
  9. )
  10. func NewAuthSource(ctx *middleware.Context) {
  11. ctx.Data["Title"] = "New Authentication"
  12. ctx.Data["PageIsAuths"] = true
  13. ctx.HTML(200, "admin/auths/new")
  14. }
  15. func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
  16. ctx.Data["Title"] = "New Authentication"
  17. ctx.Data["PageIsAuths"] = true
  18. if ctx.HasError() {
  19. ctx.HTML(200, "admin/auths/new")
  20. return
  21. }
  22. u := &models.LDAPConfig{
  23. Ldapsource: ldap.Ldapsource{
  24. Host: form.Host,
  25. Port: form.Port,
  26. BaseDN: form.BaseDN,
  27. Attributes: form.Attributes,
  28. Filter: form.Filter,
  29. MsAdSAFormat: form.MsAdSA,
  30. Enabled: true,
  31. Name: form.Name,
  32. },
  33. }
  34. if err := models.AddLDAPSource(form.Name, u); err != nil {
  35. switch err {
  36. default:
  37. ctx.Handle(500, "admin.auths.NewAuth", err)
  38. }
  39. return
  40. }
  41. log.Trace("%s Authentication created by admin(%s): %s", ctx.Req.RequestURI,
  42. ctx.User.LowerName, strings.ToLower(form.Name))
  43. ctx.Redirect("/admin/auths")
  44. }
  45. func EditAuthSource(ctx *middleware.Context) {
  46. }
  47. func EditAuthSourcePost(ctx *middleware.Context) {
  48. }
  49. func DeleteAuthSource(ctx *middleware.Context) {
  50. }