finish new add auth UI

This commit is contained in:
Unknwon 2015-09-10 17:11:41 -04:00
parent fa728d8dff
commit 0617448282
8 changed files with 238 additions and 167 deletions

View file

@ -39,11 +39,28 @@ func Authentications(ctx *middleware.Context) {
ctx.HTML(200, AUTHS)
}
type AuthSource struct {
Name string
Type models.LoginType
}
var authSources = []AuthSource{
{models.LoginNames[models.LDAP], models.LDAP},
{models.LoginNames[models.DLDAP], models.DLDAP},
{models.LoginNames[models.SMTP], models.SMTP},
{models.LoginNames[models.PAM], models.PAM},
}
func NewAuthSource(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
ctx.Data["LoginTypes"] = models.LoginTypes
ctx.Data["type"] = models.LDAP
ctx.Data["CurTypeName"] = models.LoginNames[models.LDAP]
ctx.Data["smtp_auth"] = "PLAIN"
ctx.Data["is_active"] = true
ctx.Data["AuthSources"] = authSources
ctx.Data["SMTPAuths"] = models.SMTPAuths
ctx.HTML(200, AUTH_NEW)
}
@ -52,7 +69,9 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
ctx.Data["LoginTypes"] = models.LoginTypes
ctx.Data["CurTypeName"] = models.LoginNames[models.LoginType(form.Type)]
ctx.Data["AuthSources"] = authSources
ctx.Data["SMTPAuths"] = models.SMTPAuths
if ctx.HasError() {
@ -62,9 +81,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
var u core.Conversion
switch models.LoginType(form.Type) {
case models.LDAP:
fallthrough
case models.DLDAP:
case models.LDAP, models.DLDAP:
u = &models.LDAPConfig{
Ldapsource: ldap.Ldapsource{
Name: form.Name,
@ -103,7 +120,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
var source = &models.LoginSource{
Type: models.LoginType(form.Type),
Name: form.Name,
IsActived: true,
IsActived: form.IsActive,
AllowAutoRegister: form.AllowAutoRegister,
Cfg: u,
}
@ -121,7 +138,7 @@ func EditAuthSource(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
ctx.Data["LoginTypes"] = models.LoginTypes
// ctx.Data["LoginTypes"] = models.LoginTypes
ctx.Data["SMTPAuths"] = models.SMTPAuths
id := com.StrTo(ctx.Params(":authid")).MustInt64()
@ -143,7 +160,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
ctx.Data["PageIsAuths"] = true
ctx.Data["LoginTypes"] = models.LoginTypes
// ctx.Data["LoginTypes"] = models.LoginTypes
ctx.Data["SMTPAuths"] = models.SMTPAuths
if ctx.HasError() {
@ -194,7 +211,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
u := models.LoginSource{
ID: form.ID,
Name: form.Name,
IsActived: form.IsActived,
IsActived: form.IsActive,
Type: models.LoginType(form.Type),
AllowAutoRegister: form.AllowAutoRegister,
Cfg: config,