aboutsummaryrefslogtreecommitdiff
path: root/routes/admin/auths.go
diff options
context:
space:
mode:
Diffstat (limited to 'routes/admin/auths.go')
-rw-r--r--routes/admin/auths.go62
1 files changed, 30 insertions, 32 deletions
diff --git a/routes/admin/auths.go b/routes/admin/auths.go
index 56a0aad6..6356d112 100644
--- a/routes/admin/auths.go
+++ b/routes/admin/auths.go
@@ -25,19 +25,19 @@ const (
)
func Authentications(c *context.Context) {
- c.Data["Title"] = c.Tr("admin.authentication")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.authentication")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
var err error
c.Data["Sources"], err = models.LoginSources()
if err != nil {
- c.Handle(500, "LoginSources", err)
+ c.ServerError("LoginSources", err)
return
}
c.Data["Total"] = models.CountLoginSources()
- c.HTML(200, AUTHS)
+ c.Success(AUTHS)
}
type dropdownItem struct {
@@ -60,9 +60,9 @@ var (
)
func NewAuthSource(c *context.Context) {
- c.Data["Title"] = c.Tr("admin.auths.new")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.auths.new")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
c.Data["type"] = models.LOGIN_LDAP
c.Data["CurrentTypeName"] = models.LoginNames[models.LOGIN_LDAP]
@@ -72,13 +72,12 @@ func NewAuthSource(c *context.Context) {
c.Data["AuthSources"] = authSources
c.Data["SecurityProtocols"] = securityProtocols
c.Data["SMTPAuths"] = models.SMTPAuths
- c.HTML(200, AUTH_NEW)
+ c.Success(AUTH_NEW)
}
func parseLDAPConfig(f form.Authentication) *models.LDAPConfig {
return &models.LDAPConfig{
Source: &ldap.Source{
- Name: f.Name,
Host: f.Host,
Port: f.Port,
SecurityProtocol: ldap.SecurityProtocol(f.SecurityProtocol),
@@ -99,7 +98,6 @@ func parseLDAPConfig(f form.Authentication) *models.LDAPConfig {
GroupMemberUID: f.GroupMemberUID,
UserUID: f.UserUID,
AdminFilter: f.AdminFilter,
- Enabled: true,
},
}
}
@@ -116,9 +114,9 @@ func parseSMTPConfig(f form.Authentication) *models.SMTPConfig {
}
func NewAuthSourcePost(c *context.Context, f form.Authentication) {
- c.Data["Title"] = c.Tr("admin.auths.new")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.auths.new")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
c.Data["CurrentTypeName"] = models.LoginNames[models.LoginType(f.Type)]
c.Data["CurrentSecurityProtocol"] = models.SecurityProtocolNames[ldap.SecurityProtocol(f.SecurityProtocol)]
@@ -146,7 +144,7 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) {
c.Data["HasTLS"] = hasTLS
if c.HasError() {
- c.HTML(200, AUTH_NEW)
+ c.Success(AUTH_NEW)
return
}
@@ -160,7 +158,7 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) {
c.Data["Err_Name"] = true
c.RenderWithErr(c.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), AUTH_NEW, f)
} else {
- c.Handle(500, "CreateSource", err)
+ c.ServerError("CreateSource", err)
}
return
}
@@ -172,41 +170,41 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) {
}
func EditAuthSource(c *context.Context) {
- c.Data["Title"] = c.Tr("admin.auths.edit")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.auths.edit")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
c.Data["SecurityProtocols"] = securityProtocols
c.Data["SMTPAuths"] = models.SMTPAuths
source, err := models.GetLoginSourceByID(c.ParamsInt64(":authid"))
if err != nil {
- c.Handle(500, "GetLoginSourceByID", err)
+ c.ServerError("GetLoginSourceByID", err)
return
}
c.Data["Source"] = source
c.Data["HasTLS"] = source.HasTLS()
- c.HTML(200, AUTH_EDIT)
+ c.Success(AUTH_EDIT)
}
func EditAuthSourcePost(c *context.Context, f form.Authentication) {
- c.Data["Title"] = c.Tr("admin.auths.edit")
- c.Data["PageIsAdmin"] = true
- c.Data["PageIsAdminAuthentications"] = true
+ c.Title("admin.auths.edit")
+ c.PageIs("Admin")
+ c.PageIs("AdminAuthentications")
c.Data["SMTPAuths"] = models.SMTPAuths
source, err := models.GetLoginSourceByID(c.ParamsInt64(":authid"))
if err != nil {
- c.Handle(500, "GetLoginSourceByID", err)
+ c.ServerError("GetLoginSourceByID", err)
return
}
c.Data["Source"] = source
c.Data["HasTLS"] = source.HasTLS()
if c.HasError() {
- c.HTML(200, AUTH_EDIT)
+ c.Success(AUTH_EDIT)
return
}
@@ -228,11 +226,11 @@ func EditAuthSourcePost(c *context.Context, f form.Authentication) {
source.Name = f.Name
source.IsActived = f.IsActive
source.Cfg = config
- if err := models.UpdateSource(source); err != nil {
- c.Handle(500, "UpdateSource", err)
+ if err := models.UpdateLoginSource(source); err != nil {
+ c.ServerError("UpdateLoginSource", err)
return
}
- log.Trace("Authentication changed by admin(%s): %d", c.User.Name, source.ID)
+ log.Trace("Authentication changed by admin '%s': %d", c.User.Name, source.ID)
c.Flash.Success(c.Tr("admin.auths.update_success"))
c.Redirect(setting.AppSubURL + "/admin/auths/" + com.ToStr(f.ID))
@@ -241,7 +239,7 @@ func EditAuthSourcePost(c *context.Context, f form.Authentication) {
func DeleteAuthSource(c *context.Context) {
source, err := models.GetLoginSourceByID(c.ParamsInt64(":authid"))
if err != nil {
- c.Handle(500, "GetLoginSourceByID", err)
+ c.ServerError("GetLoginSourceByID", err)
return
}
@@ -251,7 +249,7 @@ func DeleteAuthSource(c *context.Context) {
} else {
c.Flash.Error(fmt.Sprintf("DeleteSource: %v", err))
}
- c.JSON(200, map[string]interface{}{
+ c.JSONSuccess(map[string]interface{}{
"redirect": setting.AppSubURL + "/admin/auths/" + c.Params(":authid"),
})
return
@@ -259,7 +257,7 @@ func DeleteAuthSource(c *context.Context) {
log.Trace("Authentication deleted by admin(%s): %d", c.User.Name, source.ID)
c.Flash.Success(c.Tr("admin.auths.deletion_success"))
- c.JSON(200, map[string]interface{}{
+ c.JSONSuccess(map[string]interface{}{
"redirect": setting.AppSubURL + "/admin/auths",
})
}