|
|
@ -5,10 +5,11 @@ |
|
|
|
package admin |
|
|
|
package admin |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-martini/martini" |
|
|
|
"github.com/go-martini/martini" |
|
|
|
|
|
|
|
"github.com/go-xorm/core" |
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/modules/auth" |
|
|
|
"github.com/gogits/gogs/modules/auth" |
|
|
|
"github.com/gogits/gogs/modules/auth/ldap" |
|
|
|
"github.com/gogits/gogs/modules/auth/ldap" |
|
|
@ -21,19 +22,24 @@ func NewAuthSource(ctx *middleware.Context) { |
|
|
|
ctx.Data["Title"] = "New Authentication" |
|
|
|
ctx.Data["Title"] = "New Authentication" |
|
|
|
ctx.Data["PageIsAuths"] = true |
|
|
|
ctx.Data["PageIsAuths"] = true |
|
|
|
ctx.Data["LoginTypes"] = models.LoginTypes |
|
|
|
ctx.Data["LoginTypes"] = models.LoginTypes |
|
|
|
|
|
|
|
ctx.Data["SMTPAuths"] = models.SMTPAuths |
|
|
|
ctx.HTML(200, "admin/auths/new") |
|
|
|
ctx.HTML(200, "admin/auths/new") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { |
|
|
|
func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { |
|
|
|
ctx.Data["Title"] = "New Authentication" |
|
|
|
ctx.Data["Title"] = "New Authentication" |
|
|
|
ctx.Data["PageIsAuths"] = true |
|
|
|
ctx.Data["PageIsAuths"] = true |
|
|
|
|
|
|
|
ctx.Data["LoginTypes"] = models.LoginTypes |
|
|
|
|
|
|
|
ctx.Data["SMTPAuths"] = models.SMTPAuths |
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
ctx.HTML(200, "admin/auths/new") |
|
|
|
ctx.HTML(200, "admin/auths/new") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
u := &models.LDAPConfig{ |
|
|
|
var u core.Conversion |
|
|
|
|
|
|
|
if form.Type == models.LT_LDAP { |
|
|
|
|
|
|
|
u = &models.LDAPConfig{ |
|
|
|
Ldapsource: ldap.Ldapsource{ |
|
|
|
Ldapsource: ldap.Ldapsource{ |
|
|
|
Host: form.Host, |
|
|
|
Host: form.Host, |
|
|
|
Port: form.Port, |
|
|
|
Port: form.Port, |
|
|
@ -45,8 +51,26 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { |
|
|
|
Name: form.AuthName, |
|
|
|
Name: form.AuthName, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if form.Type == models.LT_SMTP { |
|
|
|
|
|
|
|
u = &models.SMTPConfig{ |
|
|
|
|
|
|
|
Auth: form.SmtpAuth, |
|
|
|
|
|
|
|
Host: form.SmtpHost, |
|
|
|
|
|
|
|
Port: form.SmtpPort, |
|
|
|
|
|
|
|
TLS: form.SmtpTls, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
panic(errors.New("not allow type")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := models.AddLDAPSource(form.AuthName, u); err != nil { |
|
|
|
var source = &models.LoginSource{ |
|
|
|
|
|
|
|
Type: form.Type, |
|
|
|
|
|
|
|
Name: form.AuthName, |
|
|
|
|
|
|
|
IsActived: true, |
|
|
|
|
|
|
|
AllowAutoRegisted: form.AllowAutoRegister, |
|
|
|
|
|
|
|
Cfg: u, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := models.AddSource(source); err != nil { |
|
|
|
switch err { |
|
|
|
switch err { |
|
|
|
default: |
|
|
|
default: |
|
|
|
ctx.Handle(500, "admin.auths.NewAuth", err) |
|
|
|
ctx.Handle(500, "admin.auths.NewAuth", err) |
|
|
@ -63,6 +87,9 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { |
|
|
|
func EditAuthSource(ctx *middleware.Context, params martini.Params) { |
|
|
|
func EditAuthSource(ctx *middleware.Context, params martini.Params) { |
|
|
|
ctx.Data["Title"] = "Edit Authentication" |
|
|
|
ctx.Data["Title"] = "Edit Authentication" |
|
|
|
ctx.Data["PageIsAuths"] = true |
|
|
|
ctx.Data["PageIsAuths"] = true |
|
|
|
|
|
|
|
ctx.Data["LoginTypes"] = models.LoginTypes |
|
|
|
|
|
|
|
ctx.Data["SMTPAuths"] = models.SMTPAuths |
|
|
|
|
|
|
|
|
|
|
|
id, err := base.StrTo(params["authid"]).Int64() |
|
|
|
id, err := base.StrTo(params["authid"]).Int64() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(404, "admin.auths.EditAuthSource", err) |
|
|
|
ctx.Handle(404, "admin.auths.EditAuthSource", err) |
|
|
@ -74,24 +101,23 @@ func EditAuthSource(ctx *middleware.Context, params martini.Params) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["Source"] = u |
|
|
|
ctx.Data["Source"] = u |
|
|
|
ctx.Data["LoginTypes"] = models.LoginTypes |
|
|
|
|
|
|
|
ctx.HTML(200, "admin/auths/edit") |
|
|
|
ctx.HTML(200, "admin/auths/edit") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { |
|
|
|
func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { |
|
|
|
ctx.Data["Title"] = "Edit Authentication" |
|
|
|
ctx.Data["Title"] = "Edit Authentication" |
|
|
|
ctx.Data["PageIsAuths"] = true |
|
|
|
ctx.Data["PageIsAuths"] = true |
|
|
|
|
|
|
|
ctx.Data["LoginTypes"] = models.LoginTypes |
|
|
|
|
|
|
|
ctx.Data["SMTPAuths"] = models.SMTPAuths |
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
ctx.HTML(200, "admin/auths/edit") |
|
|
|
ctx.HTML(200, "admin/auths/edit") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
u := models.LoginSource{ |
|
|
|
var config core.Conversion |
|
|
|
Name: form.AuthName, |
|
|
|
if form.Type == models.LT_LDAP { |
|
|
|
IsActived: form.IsActived, |
|
|
|
config = &models.LDAPConfig{ |
|
|
|
Type: models.LT_LDAP, |
|
|
|
|
|
|
|
Cfg: &models.LDAPConfig{ |
|
|
|
|
|
|
|
Ldapsource: ldap.Ldapsource{ |
|
|
|
Ldapsource: ldap.Ldapsource{ |
|
|
|
Host: form.Host, |
|
|
|
Host: form.Host, |
|
|
|
Port: form.Port, |
|
|
|
Port: form.Port, |
|
|
@ -102,10 +128,25 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) { |
|
|
|
Enabled: true, |
|
|
|
Enabled: true, |
|
|
|
Name: form.AuthName, |
|
|
|
Name: form.AuthName, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
} else if form.Type == models.LT_SMTP { |
|
|
|
|
|
|
|
config = &models.SMTPConfig{ |
|
|
|
|
|
|
|
Auth: form.SmtpAuth, |
|
|
|
|
|
|
|
Host: form.SmtpHost, |
|
|
|
|
|
|
|
Port: form.SmtpPort, |
|
|
|
|
|
|
|
TLS: form.SmtpTls, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u := models.LoginSource{ |
|
|
|
|
|
|
|
Name: form.AuthName, |
|
|
|
|
|
|
|
IsActived: form.IsActived, |
|
|
|
|
|
|
|
Type: form.Type, |
|
|
|
|
|
|
|
AllowAutoRegisted: form.AllowAutoRegister, |
|
|
|
|
|
|
|
Cfg: config, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := models.UpdateLDAPSource(&u); err != nil { |
|
|
|
if err := models.UpdateSource(&u); err != nil { |
|
|
|
switch err { |
|
|
|
switch err { |
|
|
|
default: |
|
|
|
default: |
|
|
|
ctx.Handle(500, "admin.auths.EditAuth", err) |
|
|
|
ctx.Handle(500, "admin.auths.EditAuth", err) |
|
|
|