Merge pull request #202 from lunny/lunny/golint_fixed_routers_admin
go lint fixed for routers/admin
This commit is contained in:
commit
1d9576d5ea
6 changed files with 73 additions and 51 deletions
|
@ -22,9 +22,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DASHBOARD base.TplName = "admin/dashboard"
|
tplDashboard base.TplName = "admin/dashboard"
|
||||||
CONFIG base.TplName = "admin/config"
|
tplConfig base.TplName = "admin/config"
|
||||||
MONITOR base.TplName = "admin/monitor"
|
tplMonitor base.TplName = "admin/monitor"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -110,19 +110,20 @@ func updateSystemStatus() {
|
||||||
sysStatus.NumGC = m.NumGC
|
sysStatus.NumGC = m.NumGC
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operation types.
|
// Operation Operation types.
|
||||||
type AdminOperation int
|
type Operation int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CLEAN_INACTIVATE_USER AdminOperation = iota + 1
|
cleanInactivateUser Operation = iota + 1
|
||||||
CLEAN_REPO_ARCHIVES
|
cleanRepoArchives
|
||||||
CLEAN_MISSING_REPOS
|
cleanMissingRepos
|
||||||
GIT_GC_REPOS
|
gitGCRepos
|
||||||
SYNC_SSH_AUTHORIZED_KEY
|
syncSSHAuthorizedKey
|
||||||
SYNC_REPOSITORY_UPDATE_HOOK
|
syncRepositoryUpdateHook
|
||||||
REINIT_MISSING_REPOSITORY
|
reinitMissingRepository
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Dashboard show admin panel dashboard
|
||||||
func Dashboard(ctx *context.Context) {
|
func Dashboard(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
|
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -134,26 +135,26 @@ func Dashboard(ctx *context.Context) {
|
||||||
var err error
|
var err error
|
||||||
var success string
|
var success string
|
||||||
|
|
||||||
switch AdminOperation(op) {
|
switch Operation(op) {
|
||||||
case CLEAN_INACTIVATE_USER:
|
case cleanInactivateUser:
|
||||||
success = ctx.Tr("admin.dashboard.delete_inactivate_accounts_success")
|
success = ctx.Tr("admin.dashboard.delete_inactivate_accounts_success")
|
||||||
err = models.DeleteInactivateUsers()
|
err = models.DeleteInactivateUsers()
|
||||||
case CLEAN_REPO_ARCHIVES:
|
case cleanRepoArchives:
|
||||||
success = ctx.Tr("admin.dashboard.delete_repo_archives_success")
|
success = ctx.Tr("admin.dashboard.delete_repo_archives_success")
|
||||||
err = models.DeleteRepositoryArchives()
|
err = models.DeleteRepositoryArchives()
|
||||||
case CLEAN_MISSING_REPOS:
|
case cleanMissingRepos:
|
||||||
success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
|
success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
|
||||||
err = models.DeleteMissingRepositories()
|
err = models.DeleteMissingRepositories()
|
||||||
case GIT_GC_REPOS:
|
case gitGCRepos:
|
||||||
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
|
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
|
||||||
err = models.GitGcRepos()
|
err = models.GitGcRepos()
|
||||||
case SYNC_SSH_AUTHORIZED_KEY:
|
case syncSSHAuthorizedKey:
|
||||||
success = ctx.Tr("admin.dashboard.resync_all_sshkeys_success")
|
success = ctx.Tr("admin.dashboard.resync_all_sshkeys_success")
|
||||||
err = models.RewriteAllPublicKeys()
|
err = models.RewriteAllPublicKeys()
|
||||||
case SYNC_REPOSITORY_UPDATE_HOOK:
|
case syncRepositoryUpdateHook:
|
||||||
success = ctx.Tr("admin.dashboard.resync_all_update_hooks_success")
|
success = ctx.Tr("admin.dashboard.resync_all_update_hooks_success")
|
||||||
err = models.RewriteRepositoryUpdateHook()
|
err = models.RewriteRepositoryUpdateHook()
|
||||||
case REINIT_MISSING_REPOSITORY:
|
case reinitMissingRepository:
|
||||||
success = ctx.Tr("admin.dashboard.reinit_missing_repos_success")
|
success = ctx.Tr("admin.dashboard.reinit_missing_repos_success")
|
||||||
err = models.ReinitMissingRepositories()
|
err = models.ReinitMissingRepositories()
|
||||||
}
|
}
|
||||||
|
@ -171,9 +172,10 @@ func Dashboard(ctx *context.Context) {
|
||||||
// FIXME: update periodically
|
// FIXME: update periodically
|
||||||
updateSystemStatus()
|
updateSystemStatus()
|
||||||
ctx.Data["SysStatus"] = sysStatus
|
ctx.Data["SysStatus"] = sysStatus
|
||||||
ctx.HTML(200, DASHBOARD)
|
ctx.HTML(200, tplDashboard)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendTestMail send test mail to confirm mail service is OK
|
||||||
func SendTestMail(ctx *context.Context) {
|
func SendTestMail(ctx *context.Context) {
|
||||||
email := ctx.Query("email")
|
email := ctx.Query("email")
|
||||||
// Send a test email to the user's email address and redirect back to Config
|
// Send a test email to the user's email address and redirect back to Config
|
||||||
|
@ -186,6 +188,7 @@ func SendTestMail(ctx *context.Context) {
|
||||||
ctx.Redirect(setting.AppSubUrl + "/admin/config")
|
ctx.Redirect(setting.AppSubUrl + "/admin/config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config show admin config page
|
||||||
func Config(ctx *context.Context) {
|
func Config(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.config")
|
ctx.Data["Title"] = ctx.Tr("admin.config")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -235,14 +238,15 @@ func Config(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
ctx.Data["Loggers"] = loggers
|
ctx.Data["Loggers"] = loggers
|
||||||
|
|
||||||
ctx.HTML(200, CONFIG)
|
ctx.HTML(200, tplConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Monitor show admin monitor page
|
||||||
func Monitor(ctx *context.Context) {
|
func Monitor(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.monitor")
|
ctx.Data["Title"] = ctx.Tr("admin.monitor")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
ctx.Data["PageIsAdminMonitor"] = true
|
ctx.Data["PageIsAdminMonitor"] = true
|
||||||
ctx.Data["Processes"] = process.Processes
|
ctx.Data["Processes"] = process.Processes
|
||||||
ctx.Data["Entries"] = cron.ListTasks()
|
ctx.Data["Entries"] = cron.ListTasks()
|
||||||
ctx.HTML(200, MONITOR)
|
ctx.HTML(200, tplMonitor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AUTHS base.TplName = "admin/auth/list"
|
tplAuths base.TplName = "admin/auth/list"
|
||||||
AUTH_NEW base.TplName = "admin/auth/new"
|
tplAuthNew base.TplName = "admin/auth/new"
|
||||||
AUTH_EDIT base.TplName = "admin/auth/edit"
|
tplAuthEdit base.TplName = "admin/auth/edit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Authentications show authentication config page
|
||||||
func Authentications(ctx *context.Context) {
|
func Authentications(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.authentication")
|
ctx.Data["Title"] = ctx.Tr("admin.authentication")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -38,7 +39,7 @@ func Authentications(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["Total"] = models.CountLoginSources()
|
ctx.Data["Total"] = models.CountLoginSources()
|
||||||
ctx.HTML(200, AUTHS)
|
ctx.HTML(200, tplAuths)
|
||||||
}
|
}
|
||||||
|
|
||||||
type dropdownItem struct {
|
type dropdownItem struct {
|
||||||
|
@ -60,6 +61,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewAuthSource render adding a new auth source page
|
||||||
func NewAuthSource(ctx *context.Context) {
|
func NewAuthSource(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -73,7 +75,7 @@ func NewAuthSource(ctx *context.Context) {
|
||||||
ctx.Data["AuthSources"] = authSources
|
ctx.Data["AuthSources"] = authSources
|
||||||
ctx.Data["SecurityProtocols"] = securityProtocols
|
ctx.Data["SecurityProtocols"] = securityProtocols
|
||||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||||
ctx.HTML(200, AUTH_NEW)
|
ctx.HTML(200, tplAuthNew)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseLDAPConfig(form auth.AuthenticationForm) *models.LDAPConfig {
|
func parseLDAPConfig(form auth.AuthenticationForm) *models.LDAPConfig {
|
||||||
|
@ -111,6 +113,7 @@ func parseSMTPConfig(form auth.AuthenticationForm) *models.SMTPConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAuthSourcePost response for adding an auth source
|
||||||
func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -142,7 +145,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||||
ctx.Data["HasTLS"] = hasTLS
|
ctx.Data["HasTLS"] = hasTLS
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, AUTH_NEW)
|
ctx.HTML(200, tplAuthNew)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +157,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
if models.IsErrLoginSourceAlreadyExist(err) {
|
if models.IsErrLoginSourceAlreadyExist(err) {
|
||||||
ctx.Data["Err_Name"] = true
|
ctx.Data["Err_Name"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), AUTH_NEW, form)
|
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "CreateSource", err)
|
ctx.Handle(500, "CreateSource", err)
|
||||||
}
|
}
|
||||||
|
@ -167,6 +170,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||||
ctx.Redirect(setting.AppSubUrl + "/admin/auths")
|
ctx.Redirect(setting.AppSubUrl + "/admin/auths")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditAuthSource render editing auth source page
|
||||||
func EditAuthSource(ctx *context.Context) {
|
func EditAuthSource(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -183,9 +187,10 @@ func EditAuthSource(ctx *context.Context) {
|
||||||
ctx.Data["Source"] = source
|
ctx.Data["Source"] = source
|
||||||
ctx.Data["HasTLS"] = source.HasTLS()
|
ctx.Data["HasTLS"] = source.HasTLS()
|
||||||
|
|
||||||
ctx.HTML(200, AUTH_EDIT)
|
ctx.HTML(200, tplAuthEdit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditAuthSourcePost resposne for editing auth source
|
||||||
func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -202,7 +207,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||||
ctx.Data["HasTLS"] = source.HasTLS()
|
ctx.Data["HasTLS"] = source.HasTLS()
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, AUTH_EDIT)
|
ctx.HTML(200, tplAuthEdit)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,6 +239,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||||
ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + com.ToStr(form.ID))
|
ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + com.ToStr(form.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteAuthSource response for deleting an auth source
|
||||||
func DeleteAuthSource(ctx *context.Context) {
|
func DeleteAuthSource(ctx *context.Context) {
|
||||||
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
|
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,9 +16,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NOTICES base.TplName = "admin/notice"
|
tplNotices base.TplName = "admin/notice"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Notices show notices for admin
|
||||||
func Notices(ctx *context.Context) {
|
func Notices(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.notices")
|
ctx.Data["Title"] = ctx.Tr("admin.notices")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -39,9 +40,10 @@ func Notices(ctx *context.Context) {
|
||||||
ctx.Data["Notices"] = notices
|
ctx.Data["Notices"] = notices
|
||||||
|
|
||||||
ctx.Data["Total"] = total
|
ctx.Data["Total"] = total
|
||||||
ctx.HTML(200, NOTICES)
|
ctx.HTML(200, tplNotices)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteNotices delete the specific notices
|
||||||
func DeleteNotices(ctx *context.Context) {
|
func DeleteNotices(ctx *context.Context) {
|
||||||
strs := ctx.QueryStrings("ids[]")
|
strs := ctx.QueryStrings("ids[]")
|
||||||
ids := make([]int64, 0, len(strs))
|
ids := make([]int64, 0, len(strs))
|
||||||
|
@ -61,6 +63,7 @@ func DeleteNotices(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EmptyNotices delete all the notices
|
||||||
func EmptyNotices(ctx *context.Context) {
|
func EmptyNotices(ctx *context.Context) {
|
||||||
if err := models.DeleteNotices(0, 0); err != nil {
|
if err := models.DeleteNotices(0, 0); err != nil {
|
||||||
ctx.Handle(500, "DeleteNotices", err)
|
ctx.Handle(500, "DeleteNotices", err)
|
||||||
|
|
|
@ -13,9 +13,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ORGS base.TplName = "admin/org/list"
|
tplOrgs base.TplName = "admin/org/list"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Organizations show all the organizations
|
||||||
func Organizations(ctx *context.Context) {
|
func Organizations(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.organizations")
|
ctx.Data["Title"] = ctx.Tr("admin.organizations")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -27,6 +28,6 @@ func Organizations(ctx *context.Context) {
|
||||||
Ranger: models.Organizations,
|
Ranger: models.Organizations,
|
||||||
PageSize: setting.UI.Admin.OrgPagingNum,
|
PageSize: setting.UI.Admin.OrgPagingNum,
|
||||||
OrderBy: "id ASC",
|
OrderBy: "id ASC",
|
||||||
TplName: ORGS,
|
TplName: tplOrgs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
REPOS base.TplName = "admin/repo/list"
|
tplRepos base.TplName = "admin/repo/list"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Repos show all the repositories
|
||||||
func Repos(ctx *context.Context) {
|
func Repos(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.repositories")
|
ctx.Data["Title"] = ctx.Tr("admin.repositories")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -28,10 +29,11 @@ func Repos(ctx *context.Context) {
|
||||||
Private: true,
|
Private: true,
|
||||||
PageSize: setting.UI.Admin.RepoPagingNum,
|
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||||
OrderBy: "owner_id ASC, name ASC, id ASC",
|
OrderBy: "owner_id ASC, name ASC, id ASC",
|
||||||
TplName: REPOS,
|
TplName: tplRepos,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteRepo delete one repository
|
||||||
func DeleteRepo(ctx *context.Context) {
|
func DeleteRepo(ctx *context.Context) {
|
||||||
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
|
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -19,11 +19,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
USERS base.TplName = "admin/user/list"
|
tplUsers base.TplName = "admin/user/list"
|
||||||
USER_NEW base.TplName = "admin/user/new"
|
tplUserNew base.TplName = "admin/user/new"
|
||||||
USER_EDIT base.TplName = "admin/user/edit"
|
tplUserEdit base.TplName = "admin/user/edit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Users show all the users
|
||||||
func Users(ctx *context.Context) {
|
func Users(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.users")
|
ctx.Data["Title"] = ctx.Tr("admin.users")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -35,10 +36,11 @@ func Users(ctx *context.Context) {
|
||||||
Ranger: models.Users,
|
Ranger: models.Users,
|
||||||
PageSize: setting.UI.Admin.UserPagingNum,
|
PageSize: setting.UI.Admin.UserPagingNum,
|
||||||
OrderBy: "id ASC",
|
OrderBy: "id ASC",
|
||||||
TplName: USERS,
|
TplName: tplUsers,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewUser render adding a new user page
|
||||||
func NewUser(ctx *context.Context) {
|
func NewUser(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
|
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -54,9 +56,10 @@ func NewUser(ctx *context.Context) {
|
||||||
ctx.Data["Sources"] = sources
|
ctx.Data["Sources"] = sources
|
||||||
|
|
||||||
ctx.Data["CanSendEmail"] = setting.MailService != nil
|
ctx.Data["CanSendEmail"] = setting.MailService != nil
|
||||||
ctx.HTML(200, USER_NEW)
|
ctx.HTML(200, tplUserNew)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewUserPost response for adding a new user
|
||||||
func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
|
func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
|
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -72,7 +75,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
|
||||||
ctx.Data["CanSendEmail"] = setting.MailService != nil
|
ctx.Data["CanSendEmail"] = setting.MailService != nil
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, USER_NEW)
|
ctx.HTML(200, tplUserNew)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,16 +100,16 @@ func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
|
||||||
switch {
|
switch {
|
||||||
case models.IsErrUserAlreadyExist(err):
|
case models.IsErrUserAlreadyExist(err):
|
||||||
ctx.Data["Err_UserName"] = true
|
ctx.Data["Err_UserName"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), USER_NEW, &form)
|
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplUserNew, &form)
|
||||||
case models.IsErrEmailAlreadyUsed(err):
|
case models.IsErrEmailAlreadyUsed(err):
|
||||||
ctx.Data["Err_Email"] = true
|
ctx.Data["Err_Email"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), USER_NEW, &form)
|
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserNew, &form)
|
||||||
case models.IsErrNameReserved(err):
|
case models.IsErrNameReserved(err):
|
||||||
ctx.Data["Err_UserName"] = true
|
ctx.Data["Err_UserName"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), USER_NEW, &form)
|
ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplUserNew, &form)
|
||||||
case models.IsErrNamePatternNotAllowed(err):
|
case models.IsErrNamePatternNotAllowed(err):
|
||||||
ctx.Data["Err_UserName"] = true
|
ctx.Data["Err_UserName"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), USER_NEW, &form)
|
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form)
|
||||||
default:
|
default:
|
||||||
ctx.Handle(500, "CreateUser", err)
|
ctx.Handle(500, "CreateUser", err)
|
||||||
}
|
}
|
||||||
|
@ -151,6 +154,7 @@ func prepareUserInfo(ctx *context.Context) *models.User {
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditUser show editting user page
|
||||||
func EditUser(ctx *context.Context) {
|
func EditUser(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
|
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -161,9 +165,10 @@ func EditUser(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.HTML(200, USER_EDIT)
|
ctx.HTML(200, tplUserEdit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditUserPost response for editting user
|
||||||
func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
|
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
|
||||||
ctx.Data["PageIsAdmin"] = true
|
ctx.Data["PageIsAdmin"] = true
|
||||||
|
@ -175,7 +180,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, USER_EDIT)
|
ctx.HTML(200, tplUserEdit)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +216,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||||
if err := models.UpdateUser(u); err != nil {
|
if err := models.UpdateUser(u); err != nil {
|
||||||
if models.IsErrEmailAlreadyUsed(err) {
|
if models.IsErrEmailAlreadyUsed(err) {
|
||||||
ctx.Data["Err_Email"] = true
|
ctx.Data["Err_Email"] = true
|
||||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), USER_EDIT, &form)
|
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "UpdateUser", err)
|
ctx.Handle(500, "UpdateUser", err)
|
||||||
}
|
}
|
||||||
|
@ -223,6 +228,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||||
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"))
|
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteUser response for deleting a user
|
||||||
func DeleteUser(ctx *context.Context) {
|
func DeleteUser(ctx *context.Context) {
|
||||||
u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
|
u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue