forked from Shiloh/githaven
In progress of name template name constant
This commit is contained in:
parent
c280415e0b
commit
9924e65ca1
@ -7,6 +7,7 @@ package base
|
|||||||
type (
|
type (
|
||||||
// Type TmplData represents data in the templates.
|
// Type TmplData represents data in the templates.
|
||||||
TmplData map[string]interface{}
|
TmplData map[string]interface{}
|
||||||
|
TplName string
|
||||||
|
|
||||||
ApiJsonErr struct {
|
ApiJsonErr struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
@ -17,6 +17,15 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AUTH_ACTIVE base.TplName = "mail/auth/active"
|
||||||
|
AUTH_REGISTER_SUCCESS base.TplName = "mail/auth/register_success"
|
||||||
|
AUTH_RESET_PASSWORD base.TplName = "mail/auth/reset_passwd"
|
||||||
|
|
||||||
|
NOTIFY_COLLABORATOR base.TplName = "mail/notify/collaborator"
|
||||||
|
NOTIFY_MENTION base.TplName = "mail/notify/mention"
|
||||||
|
)
|
||||||
|
|
||||||
// Create New mail message use MailFrom and MailUser
|
// Create New mail message use MailFrom and MailUser
|
||||||
func NewMailMessageFrom(To []string, from, subject, body string) Message {
|
func NewMailMessageFrom(To []string, from, subject, body string) Message {
|
||||||
msg := NewHtmlMessage(To, from, subject, body)
|
msg := NewHtmlMessage(To, from, subject, body)
|
||||||
@ -61,7 +70,7 @@ func SendRegisterMail(r *middleware.Render, u *models.User) {
|
|||||||
|
|
||||||
data := GetMailTmplData(u)
|
data := GetMailTmplData(u)
|
||||||
data["Code"] = code
|
data["Code"] = code
|
||||||
body, err := r.HTMLString("mail/auth/register_success", data)
|
body, err := r.HTMLString(string(AUTH_REGISTER_SUCCESS), data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("mail.SendRegisterMail(fail to render): %v", err)
|
log.Error("mail.SendRegisterMail(fail to render): %v", err)
|
||||||
return
|
return
|
||||||
@ -81,7 +90,7 @@ func SendActiveMail(r *middleware.Render, u *models.User) {
|
|||||||
|
|
||||||
data := GetMailTmplData(u)
|
data := GetMailTmplData(u)
|
||||||
data["Code"] = code
|
data["Code"] = code
|
||||||
body, err := r.HTMLString("mail/auth/active_email", data)
|
body, err := r.HTMLString(string(AUTH_ACTIVE), data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("mail.SendActiveMail(fail to render): %v", err)
|
log.Error("mail.SendActiveMail(fail to render): %v", err)
|
||||||
return
|
return
|
||||||
@ -101,7 +110,7 @@ func SendResetPasswdMail(r *middleware.Render, u *models.User) {
|
|||||||
|
|
||||||
data := GetMailTmplData(u)
|
data := GetMailTmplData(u)
|
||||||
data["Code"] = code
|
data["Code"] = code
|
||||||
body, err := r.HTMLString("mail/auth/reset_passwd", data)
|
body, err := r.HTMLString(string(AUTH_RESET_PASSWORD), data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("mail.SendResetPasswdMail(fail to render): %v", err)
|
log.Error("mail.SendResetPasswdMail(fail to render): %v", err)
|
||||||
return
|
return
|
||||||
@ -161,7 +170,7 @@ func SendIssueMentionMail(r *middleware.Render, u, owner *models.User,
|
|||||||
data["IssueLink"] = fmt.Sprintf("%s/%s/issues/%d", owner.Name, repo.Name, issue.Index)
|
data["IssueLink"] = fmt.Sprintf("%s/%s/issues/%d", owner.Name, repo.Name, issue.Index)
|
||||||
data["Subject"] = subject
|
data["Subject"] = subject
|
||||||
|
|
||||||
body, err := r.HTMLString("mail/notify/mention", data)
|
body, err := r.HTMLString(string(NOTIFY_MENTION), data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("mail.SendIssueMentionMail(fail to render): %v", err)
|
return fmt.Errorf("mail.SendIssueMentionMail(fail to render): %v", err)
|
||||||
}
|
}
|
||||||
@ -182,7 +191,7 @@ func SendCollaboratorMail(r *middleware.Render, u, owner *models.User,
|
|||||||
data["RepoLink"] = path.Join(owner.Name, repo.Name)
|
data["RepoLink"] = path.Join(owner.Name, repo.Name)
|
||||||
data["Subject"] = subject
|
data["Subject"] = subject
|
||||||
|
|
||||||
body, err := r.HTMLString("mail/notify/collaborator", data)
|
body, err := r.HTMLString(string(NOTIFY_COLLABORATOR), data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("mail.SendCollaboratorMail(fail to render): %v", err)
|
return fmt.Errorf("mail.SendCollaboratorMail(fail to render): %v", err)
|
||||||
}
|
}
|
||||||
|
@ -104,12 +104,12 @@ func (ctx *Context) HasError() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HTML calls render.HTML underlying but reduce one argument.
|
// HTML calls render.HTML underlying but reduce one argument.
|
||||||
func (ctx *Context) HTML(status int, name string, htmlOpt ...HTMLOptions) {
|
func (ctx *Context) HTML(status int, name base.TplName, htmlOpt ...HTMLOptions) {
|
||||||
ctx.Render.HTML(status, name, ctx.Data, htmlOpt...)
|
ctx.Render.HTML(status, string(name), ctx.Data, htmlOpt...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderWithErr used for page has form validation but need to prompt error to users.
|
// RenderWithErr used for page has form validation but need to prompt error to users.
|
||||||
func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form) {
|
func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form auth.Form) {
|
||||||
if form != nil {
|
if form != nil {
|
||||||
auth.AssignForm(form, ctx.Data)
|
auth.AssignForm(form, ctx.Data)
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ func (ctx *Context) Handle(status int, title string, err error) {
|
|||||||
case 500:
|
case 500:
|
||||||
ctx.Data["Title"] = "Internal Server Error"
|
ctx.Data["Title"] = "Internal Server Error"
|
||||||
}
|
}
|
||||||
ctx.HTML(status, fmt.Sprintf("status/%d", status))
|
ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *Context) Debug(msg string, args ...interface{}) {
|
func (ctx *Context) Debug(msg string, args ...interface{}) {
|
||||||
|
@ -20,6 +20,16 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DASHBOARD base.TplName = "admin/dashboard"
|
||||||
|
USERS base.TplName = "admin/users"
|
||||||
|
REPOS base.TplName = "admin/repos"
|
||||||
|
AUTHS base.TplName = "admin/auths"
|
||||||
|
CONFIG base.TplName = "admin/config"
|
||||||
|
MONITOR_PROCESS base.TplName = "admin/monitor/process"
|
||||||
|
MONITOR_CRON base.TplName = "admin/monitor/cron"
|
||||||
|
)
|
||||||
|
|
||||||
var startTime = time.Now()
|
var startTime = time.Now()
|
||||||
|
|
||||||
var sysStatus struct {
|
var sysStatus struct {
|
||||||
@ -140,7 +150,7 @@ func Dashboard(ctx *middleware.Context) {
|
|||||||
ctx.Data["Stats"] = models.GetStatistic()
|
ctx.Data["Stats"] = models.GetStatistic()
|
||||||
updateSystemStatus()
|
updateSystemStatus()
|
||||||
ctx.Data["SysStatus"] = sysStatus
|
ctx.Data["SysStatus"] = sysStatus
|
||||||
ctx.HTML(200, "admin/dashboard")
|
ctx.HTML(200, DASHBOARD)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Users(ctx *middleware.Context) {
|
func Users(ctx *middleware.Context) {
|
||||||
@ -150,10 +160,10 @@ func Users(ctx *middleware.Context) {
|
|||||||
var err error
|
var err error
|
||||||
ctx.Data["Users"], err = models.GetUsers(200, 0)
|
ctx.Data["Users"], err = models.GetUsers(200, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "admin.Users", err)
|
ctx.Handle(500, "admin.Users(GetUsers)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.HTML(200, "admin/users")
|
ctx.HTML(200, USERS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Repositories(ctx *middleware.Context) {
|
func Repositories(ctx *middleware.Context) {
|
||||||
@ -166,7 +176,7 @@ func Repositories(ctx *middleware.Context) {
|
|||||||
ctx.Handle(500, "admin.Repositories", err)
|
ctx.Handle(500, "admin.Repositories", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.HTML(200, "admin/repos")
|
ctx.HTML(200, REPOS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Auths(ctx *middleware.Context) {
|
func Auths(ctx *middleware.Context) {
|
||||||
@ -179,7 +189,7 @@ func Auths(ctx *middleware.Context) {
|
|||||||
ctx.Handle(500, "admin.Auths", err)
|
ctx.Handle(500, "admin.Auths", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.HTML(200, "admin/auths")
|
ctx.HTML(200, AUTHS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Config(ctx *middleware.Context) {
|
func Config(ctx *middleware.Context) {
|
||||||
@ -235,7 +245,7 @@ func Config(ctx *middleware.Context) {
|
|||||||
}
|
}
|
||||||
ctx.Data["Loggers"] = loggers
|
ctx.Data["Loggers"] = loggers
|
||||||
|
|
||||||
ctx.HTML(200, "admin/config")
|
ctx.HTML(200, CONFIG)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Monitor(ctx *middleware.Context) {
|
func Monitor(ctx *middleware.Context) {
|
||||||
@ -247,11 +257,10 @@ func Monitor(ctx *middleware.Context) {
|
|||||||
case "process":
|
case "process":
|
||||||
ctx.Data["PageIsMonitorProcess"] = true
|
ctx.Data["PageIsMonitorProcess"] = true
|
||||||
ctx.Data["Processes"] = process.Processes
|
ctx.Data["Processes"] = process.Processes
|
||||||
ctx.HTML(200, "admin/monitor/process")
|
ctx.HTML(200, MONITOR_PROCESS)
|
||||||
default:
|
default:
|
||||||
ctx.Data["PageIsMonitorCron"] = true
|
ctx.Data["PageIsMonitorCron"] = true
|
||||||
ctx.Data["Entries"] = cron.ListEntries()
|
ctx.Data["Entries"] = cron.ListEntries()
|
||||||
ctx.HTML(200, "admin/monitor/cron")
|
ctx.HTML(200, MONITOR_CRON)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,17 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AUTH_NEW base.TplName = "admin/auth/new"
|
||||||
|
AUTH_EDIT base.TplName = "admin/auth/edit"
|
||||||
|
)
|
||||||
|
|
||||||
func NewAuthSource(ctx *middleware.Context) {
|
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.Data["SMTPAuths"] = models.SMTPAuths
|
||||||
ctx.HTML(200, "admin/auths/new")
|
ctx.HTML(200, AUTH_NEW)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
||||||
@ -33,7 +38,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, "admin/auths/new")
|
ctx.HTML(200, AUTH_NEW)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +79,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CreateSource(source); err != nil {
|
if err := models.CreateSource(source); err != nil {
|
||||||
ctx.Handle(500, "admin.auths.NewAuth", err)
|
ctx.Handle(500, "admin.auths.NewAuth(CreateSource)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,11 +102,11 @@ func EditAuthSource(ctx *middleware.Context, params martini.Params) {
|
|||||||
}
|
}
|
||||||
u, err := models.GetLoginSourceById(id)
|
u, err := models.GetLoginSourceById(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "admin.user.EditUser", err)
|
ctx.Handle(500, "admin.user.EditUser(GetLoginSourceById)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["Source"] = u
|
ctx.Data["Source"] = u
|
||||||
ctx.HTML(200, "admin/auths/edit")
|
ctx.HTML(200, AUTH_EDIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
||||||
@ -111,7 +116,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, "admin/auths/edit")
|
ctx.HTML(200, AUTH_EDIT)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +158,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := models.UpdateSource(&u); err != nil {
|
if err := models.UpdateSource(&u); err != nil {
|
||||||
ctx.Handle(500, "admin.auths.EditAuth", err)
|
ctx.Handle(500, "admin.auths.EditAuth(UpdateSource)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +180,7 @@ func DeleteAuthSource(ctx *middleware.Context, params martini.Params) {
|
|||||||
|
|
||||||
a, err := models.GetLoginSourceById(id)
|
a, err := models.GetLoginSourceById(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "admin.auths.DeleteAuth", err)
|
ctx.Handle(500, "admin.auths.DeleteAuth(GetLoginSourceById)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +190,7 @@ func DeleteAuthSource(ctx *middleware.Context, params martini.Params) {
|
|||||||
ctx.Flash.Error("This authentication still has used by some users, you should move them and then delete again.")
|
ctx.Flash.Error("This authentication still has used by some users, you should move them and then delete again.")
|
||||||
ctx.Redirect("/admin/auths/" + params["authid"])
|
ctx.Redirect("/admin/auths/" + params["authid"])
|
||||||
default:
|
default:
|
||||||
ctx.Handle(500, "admin.auths.DeleteAuth", err)
|
ctx.Handle(500, "admin.auths.DeleteAuth(DelLoginSource)", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
@ -5,8 +5,6 @@
|
|||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-martini/martini"
|
"github.com/go-martini/martini"
|
||||||
@ -18,16 +16,21 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
USER_NEW base.TplName = "admin/user/new"
|
||||||
|
USER_EDIT base.TplName = "admin/user/edit"
|
||||||
|
)
|
||||||
|
|
||||||
func NewUser(ctx *middleware.Context) {
|
func NewUser(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = "New Account"
|
ctx.Data["Title"] = "New Account"
|
||||||
ctx.Data["PageIsUsers"] = true
|
ctx.Data["PageIsUsers"] = true
|
||||||
auths, err := models.GetAuths()
|
auths, err := models.GetAuths()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "admin.user.NewUser", err)
|
ctx.Handle(500, "admin.user.NewUser(GetAuths)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["LoginSources"] = auths
|
ctx.Data["LoginSources"] = auths
|
||||||
ctx.HTML(200, "admin/users/new")
|
ctx.HTML(200, USER_NEW)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
|
func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
|
||||||
@ -35,7 +38,7 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
|
|||||||
ctx.Data["PageIsUsers"] = true
|
ctx.Data["PageIsUsers"] = true
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, "admin/users/new")
|
ctx.HTML(200, USER_NEW)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,25 +58,25 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(form.LoginType) > 0 {
|
if len(form.LoginType) > 0 {
|
||||||
|
// NOTE: need rewrite.
|
||||||
fields := strings.Split(form.LoginType, "-")
|
fields := strings.Split(form.LoginType, "-")
|
||||||
tp, _ := strconv.Atoi(fields[0])
|
tp, _ := base.StrTo(fields[0]).Int()
|
||||||
u.LoginType = models.LoginType(tp)
|
u.LoginType = models.LoginType(tp)
|
||||||
u.LoginSource, _ = strconv.ParseInt(fields[1], 10, 64)
|
u.LoginSource, _ = base.StrTo(fields[1]).Int64()
|
||||||
u.LoginName = form.LoginName
|
u.LoginName = form.LoginName
|
||||||
fmt.Println(u.LoginType, u.LoginSource, u.LoginName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if u, err = models.RegisterUser(u); err != nil {
|
if u, err = models.RegisterUser(u); err != nil {
|
||||||
switch err {
|
switch err {
|
||||||
case models.ErrUserAlreadyExist:
|
case models.ErrUserAlreadyExist:
|
||||||
ctx.RenderWithErr("Username has been already taken", "admin/users/new", &form)
|
ctx.RenderWithErr("Username has been already taken", USER_NEW, &form)
|
||||||
case models.ErrEmailAlreadyUsed:
|
case models.ErrEmailAlreadyUsed:
|
||||||
ctx.RenderWithErr("E-mail address has been already used", "admin/users/new", &form)
|
ctx.RenderWithErr("E-mail address has been already used", USER_NEW, &form)
|
||||||
case models.ErrUserNameIllegal:
|
case models.ErrUserNameIllegal:
|
||||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "admin/users/new", &form)
|
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), USER_NEW, &form)
|
||||||
default:
|
default:
|
||||||
ctx.Handle(500, "admin.user.NewUser", err)
|
ctx.Handle(500, "admin.user.NewUser(RegisterUser)", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -96,18 +99,18 @@ func EditUser(ctx *middleware.Context, params martini.Params) {
|
|||||||
|
|
||||||
u, err := models.GetUserById(int64(uid))
|
u, err := models.GetUserById(int64(uid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "admin.user.EditUser", err)
|
ctx.Handle(500, "admin.user.EditUser(GetUserById)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["User"] = u
|
ctx.Data["User"] = u
|
||||||
auths, err := models.GetAuths()
|
auths, err := models.GetAuths()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "admin.user.NewUser", err)
|
ctx.Handle(500, "admin.user.NewUser(GetAuths)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["LoginSources"] = auths
|
ctx.Data["LoginSources"] = auths
|
||||||
ctx.HTML(200, "admin/users/edit")
|
ctx.HTML(200, USER_EDIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) {
|
func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) {
|
||||||
@ -116,13 +119,18 @@ func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.Admi
|
|||||||
|
|
||||||
uid, err := base.StrTo(params["userid"]).Int()
|
uid, err := base.StrTo(params["userid"]).Int()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(404, "admin.user.EditUser", err)
|
ctx.Handle(404, "admin.user.EditUserPost", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := models.GetUserById(int64(uid))
|
u, err := models.GetUserById(int64(uid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "admin.user.EditUser", err)
|
ctx.Handle(500, "admin.user.EditUserPost(GetUserById)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.HasError() {
|
||||||
|
ctx.HTML(200, USER_EDIT)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +142,7 @@ func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.Admi
|
|||||||
u.IsActive = form.Active
|
u.IsActive = form.Active
|
||||||
u.IsAdmin = form.Admin
|
u.IsAdmin = form.Admin
|
||||||
if err := models.UpdateUser(u); err != nil {
|
if err := models.UpdateUser(u); err != nil {
|
||||||
ctx.Handle(500, "admin.user.EditUser", err)
|
ctx.Handle(500, "admin.user.EditUserPost(UpdateUser)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI,
|
log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI,
|
||||||
@ -152,13 +160,13 @@ func DeleteUser(ctx *middleware.Context, params martini.Params) {
|
|||||||
//log.Info("delete")
|
//log.Info("delete")
|
||||||
uid, err := base.StrTo(params["userid"]).Int()
|
uid, err := base.StrTo(params["userid"]).Int()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(404, "admin.user.EditUser", err)
|
ctx.Handle(404, "admin.user.DeleteUser", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := models.GetUserById(int64(uid))
|
u, err := models.GetUserById(int64(uid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "admin.user.EditUser", err)
|
ctx.Handle(500, "admin.user.DeleteUser(GetUserById)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,16 @@ package routers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
|
"github.com/gogits/gogs/modules/base"
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
"github.com/gogits/gogs/routers/user"
|
"github.com/gogits/gogs/routers/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
HOME base.TplName = "home"
|
||||||
|
)
|
||||||
|
|
||||||
func Home(ctx *middleware.Context) {
|
func Home(ctx *middleware.Context) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
user.Dashboard(ctx)
|
user.Dashboard(ctx)
|
||||||
@ -40,7 +45,7 @@ func Home(ctx *middleware.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Data["Repos"] = repos
|
ctx.Data["Repos"] = repos
|
||||||
ctx.HTML(200, "home")
|
ctx.HTML(200, HOME)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NotFound(ctx *middleware.Context) {
|
func NotFound(ctx *middleware.Context) {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/go-martini/martini"
|
"github.com/go-martini/martini"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
|
"github.com/gogits/gogs/modules/base"
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
@ -22,5 +23,5 @@ func TemplatePreview(ctx *middleware.Context, params martini.Params) {
|
|||||||
ctx.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60
|
ctx.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60
|
||||||
ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60
|
ctx.Data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60
|
||||||
ctx.Data["CurDbValue"] = ""
|
ctx.Data["CurDbValue"] = ""
|
||||||
ctx.HTML(200, params["_1"])
|
ctx.HTML(200, base.TplName(params["_1"]))
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,10 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/social"
|
"github.com/gogits/gogs/modules/social"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
INSTALL base.TplName = "install"
|
||||||
|
)
|
||||||
|
|
||||||
func checkRunMode() {
|
func checkRunMode() {
|
||||||
switch setting.Cfg.MustValue("", "RUN_MODE") {
|
switch setting.Cfg.MustValue("", "RUN_MODE") {
|
||||||
case "prod":
|
case "prod":
|
||||||
@ -72,6 +76,7 @@ func renderDbOption(ctx *middleware.Context) {
|
|||||||
ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"}
|
ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @router /install [get]
|
||||||
func Install(ctx *middleware.Context, form auth.InstallForm) {
|
func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||||
if setting.InstallLock {
|
if setting.InstallLock {
|
||||||
ctx.Handle(404, "install.Install", errors.New("Installation is prohibited"))
|
ctx.Handle(404, "install.Install", errors.New("Installation is prohibited"))
|
||||||
@ -119,12 +124,12 @@ func Install(ctx *middleware.Context, form auth.InstallForm) {
|
|||||||
ctx.Data["CurDbOption"] = curDbOp
|
ctx.Data["CurDbOption"] = curDbOp
|
||||||
|
|
||||||
auth.AssignForm(form, ctx.Data)
|
auth.AssignForm(form, ctx.Data)
|
||||||
ctx.HTML(200, "install")
|
ctx.HTML(200, INSTALL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
||||||
if setting.InstallLock {
|
if setting.InstallLock {
|
||||||
ctx.Handle(404, "install.Install", errors.New("Installation is prohibited"))
|
ctx.Handle(404, "install.InstallPost", errors.New("Installation is prohibited"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,12 +140,12 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||||||
ctx.Data["CurDbOption"] = form.Database
|
ctx.Data["CurDbOption"] = form.Database
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, "install")
|
ctx.HTML(200, INSTALL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := exec.LookPath("git"); err != nil {
|
if _, err := exec.LookPath("git"); err != nil {
|
||||||
ctx.RenderWithErr("Fail to test 'git' command: "+err.Error(), "install", &form)
|
ctx.RenderWithErr("Fail to test 'git' command: "+err.Error(), INSTALL, &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,18 +163,19 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||||||
// Set test engine.
|
// Set test engine.
|
||||||
var x *xorm.Engine
|
var x *xorm.Engine
|
||||||
if err := models.NewTestEngine(x); err != nil {
|
if err := models.NewTestEngine(x); err != nil {
|
||||||
|
// NOTE: should use core.QueryDriver (github.com/go-xorm/core)
|
||||||
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
|
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
|
||||||
ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+
|
ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+
|
||||||
"from http://gogs.io/docs/installation/install_from_binary.md, NOT the gobuild version.", "install", &form)
|
"from http://gogs.io/docs/installation/install_from_binary.md, NOT the gobuild version.", INSTALL, &form)
|
||||||
} else {
|
} else {
|
||||||
ctx.RenderWithErr("Database setting is not correct: "+err.Error(), "install", &form)
|
ctx.RenderWithErr("Database setting is not correct: "+err.Error(), INSTALL, &form)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test repository root path.
|
// Test repository root path.
|
||||||
if err := os.MkdirAll(form.RepoRootPath, os.ModePerm); err != nil {
|
if err := os.MkdirAll(form.RepoRootPath, os.ModePerm); err != nil {
|
||||||
ctx.RenderWithErr("Repository root path is invalid: "+err.Error(), "install", &form)
|
ctx.RenderWithErr("Repository root path is invalid: "+err.Error(), INSTALL, &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +186,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||||||
}
|
}
|
||||||
// Does not check run user when the install lock is off.
|
// Does not check run user when the install lock is off.
|
||||||
if form.RunUser != curUser {
|
if form.RunUser != curUser {
|
||||||
ctx.RenderWithErr("Run user isn't the current user: "+form.RunUser+" -> "+curUser, "install", &form)
|
ctx.RenderWithErr("Run user isn't the current user: "+form.RunUser+" -> "+curUser, INSTALL, &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +220,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||||||
|
|
||||||
os.MkdirAll("custom/conf", os.ModePerm)
|
os.MkdirAll("custom/conf", os.ModePerm)
|
||||||
if err := goconfig.SaveConfigFile(setting.Cfg, path.Join(setting.CustomPath, "conf/app.ini")); err != nil {
|
if err := goconfig.SaveConfigFile(setting.Cfg, path.Join(setting.CustomPath, "conf/app.ini")); err != nil {
|
||||||
ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form)
|
ctx.RenderWithErr("Fail to save configuration: "+err.Error(), INSTALL, &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +231,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||||||
IsAdmin: true, IsActive: true}); err != nil {
|
IsAdmin: true, IsActive: true}); err != nil {
|
||||||
if err != models.ErrUserAlreadyExist {
|
if err != models.ErrUserAlreadyExist {
|
||||||
setting.InstallLock = false
|
setting.InstallLock = false
|
||||||
ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form)
|
ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), INSTALL, &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("Admin account already exist")
|
log.Info("Admin account already exist")
|
||||||
|
@ -318,7 +318,7 @@ func basicDecode(encoded string) (user string, name string, err error) {
|
|||||||
func authRequired(ctx *middleware.Context) {
|
func authRequired(ctx *middleware.Context) {
|
||||||
ctx.ResponseWriter.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
|
ctx.ResponseWriter.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
|
||||||
ctx.Data["ErrorMsg"] = "no basic auth and digit auth"
|
ctx.Data["ErrorMsg"] = "no basic auth and digit auth"
|
||||||
ctx.HTML(401, fmt.Sprintf("status/401"))
|
ctx.HTML(401, base.TplName("status/401"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Action(ctx *middleware.Context, params martini.Params) {
|
func Action(ctx *middleware.Context, params martini.Params) {
|
||||||
|
Loading…
Reference in New Issue
Block a user