Merge branch 'master' of github.com:gogits/gogs
Conflicts: models/update.go routers/repo/http.go
This commit is contained in:
commit
86e2627175
75 changed files with 2034 additions and 661 deletions
|
@ -20,6 +20,16 @@ import (
|
|||
"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 sysStatus struct {
|
||||
|
@ -140,7 +150,7 @@ func Dashboard(ctx *middleware.Context) {
|
|||
ctx.Data["Stats"] = models.GetStatistic()
|
||||
updateSystemStatus()
|
||||
ctx.Data["SysStatus"] = sysStatus
|
||||
ctx.HTML(200, "admin/dashboard")
|
||||
ctx.HTML(200, DASHBOARD)
|
||||
}
|
||||
|
||||
func Users(ctx *middleware.Context) {
|
||||
|
@ -150,10 +160,10 @@ func Users(ctx *middleware.Context) {
|
|||
var err error
|
||||
ctx.Data["Users"], err = models.GetUsers(200, 0)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.Users", err)
|
||||
ctx.Handle(500, "admin.Users(GetUsers)", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, "admin/users")
|
||||
ctx.HTML(200, USERS)
|
||||
}
|
||||
|
||||
func Repositories(ctx *middleware.Context) {
|
||||
|
@ -166,7 +176,7 @@ func Repositories(ctx *middleware.Context) {
|
|||
ctx.Handle(500, "admin.Repositories", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, "admin/repos")
|
||||
ctx.HTML(200, REPOS)
|
||||
}
|
||||
|
||||
func Auths(ctx *middleware.Context) {
|
||||
|
@ -179,7 +189,7 @@ func Auths(ctx *middleware.Context) {
|
|||
ctx.Handle(500, "admin.Auths", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, "admin/auths")
|
||||
ctx.HTML(200, AUTHS)
|
||||
}
|
||||
|
||||
func Config(ctx *middleware.Context) {
|
||||
|
@ -196,7 +206,7 @@ func Config(ctx *middleware.Context) {
|
|||
ctx.Data["StaticRootPath"] = setting.StaticRootPath
|
||||
ctx.Data["LogRootPath"] = setting.LogRootPath
|
||||
ctx.Data["ScriptType"] = setting.ScriptType
|
||||
ctx.Data["ReverseProxyAuthUid"] = setting.ReverseProxyAuthUid
|
||||
ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser
|
||||
|
||||
ctx.Data["Service"] = setting.Service
|
||||
|
||||
|
@ -235,7 +245,7 @@ func Config(ctx *middleware.Context) {
|
|||
}
|
||||
ctx.Data["Loggers"] = loggers
|
||||
|
||||
ctx.HTML(200, "admin/config")
|
||||
ctx.HTML(200, CONFIG)
|
||||
}
|
||||
|
||||
func Monitor(ctx *middleware.Context) {
|
||||
|
@ -247,11 +257,10 @@ func Monitor(ctx *middleware.Context) {
|
|||
case "process":
|
||||
ctx.Data["PageIsMonitorProcess"] = true
|
||||
ctx.Data["Processes"] = process.Processes
|
||||
ctx.HTML(200, "admin/monitor/process")
|
||||
ctx.HTML(200, MONITOR_PROCESS)
|
||||
default:
|
||||
ctx.Data["PageIsMonitorCron"] = true
|
||||
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"
|
||||
)
|
||||
|
||||
const (
|
||||
AUTH_NEW base.TplName = "admin/auth/new"
|
||||
AUTH_EDIT base.TplName = "admin/auth/edit"
|
||||
)
|
||||
|
||||
func NewAuthSource(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "New Authentication"
|
||||
ctx.Data["PageIsAuths"] = true
|
||||
ctx.Data["LoginTypes"] = models.LoginTypes
|
||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||
ctx.HTML(200, "admin/auths/new")
|
||||
ctx.HTML(200, AUTH_NEW)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "admin/auths/new")
|
||||
ctx.HTML(200, AUTH_NEW)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -74,7 +79,7 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||
}
|
||||
|
||||
if err := models.CreateSource(source); err != nil {
|
||||
ctx.Handle(500, "admin.auths.NewAuth", err)
|
||||
ctx.Handle(500, "admin.auths.NewAuth(CreateSource)", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -97,11 +102,11 @@ func EditAuthSource(ctx *middleware.Context, params martini.Params) {
|
|||
}
|
||||
u, err := models.GetLoginSourceById(id)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.user.EditUser", err)
|
||||
ctx.Handle(500, "admin.user.EditUser(GetLoginSourceById)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Source"] = u
|
||||
ctx.HTML(200, "admin/auths/edit")
|
||||
ctx.HTML(200, AUTH_EDIT)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "admin/auths/edit")
|
||||
ctx.HTML(200, AUTH_EDIT)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -153,7 +158,7 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
|||
}
|
||||
|
||||
if err := models.UpdateSource(&u); err != nil {
|
||||
ctx.Handle(500, "admin.auths.EditAuth", err)
|
||||
ctx.Handle(500, "admin.auths.EditAuth(UpdateSource)", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -175,7 +180,7 @@ func DeleteAuthSource(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
a, err := models.GetLoginSourceById(id)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.auths.DeleteAuth", err)
|
||||
ctx.Handle(500, "admin.auths.DeleteAuth(GetLoginSourceById)", err)
|
||||
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.Redirect("/admin/auths/" + params["authid"])
|
||||
default:
|
||||
ctx.Handle(500, "admin.auths.DeleteAuth", err)
|
||||
ctx.Handle(500, "admin.auths.DeleteAuth(DelLoginSource)", err)
|
||||
}
|
||||
return
|
||||
}
|
|
@ -5,8 +5,6 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-martini/martini"
|
||||
|
@ -18,16 +16,21 @@ import (
|
|||
"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) {
|
||||
ctx.Data["Title"] = "New Account"
|
||||
ctx.Data["PageIsUsers"] = true
|
||||
auths, err := models.GetAuths()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.user.NewUser", err)
|
||||
ctx.Handle(500, "admin.user.NewUser(GetAuths)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["LoginSources"] = auths
|
||||
ctx.HTML(200, "admin/users/new")
|
||||
ctx.HTML(200, USER_NEW)
|
||||
}
|
||||
|
||||
func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
|
||||
|
@ -35,7 +38,7 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
|
|||
ctx.Data["PageIsUsers"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "admin/users/new")
|
||||
ctx.HTML(200, USER_NEW)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -55,25 +58,25 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
|
|||
}
|
||||
|
||||
if len(form.LoginType) > 0 {
|
||||
// NOTE: need rewrite.
|
||||
fields := strings.Split(form.LoginType, "-")
|
||||
tp, _ := strconv.Atoi(fields[0])
|
||||
tp, _ := base.StrTo(fields[0]).Int()
|
||||
u.LoginType = models.LoginType(tp)
|
||||
u.LoginSource, _ = strconv.ParseInt(fields[1], 10, 64)
|
||||
u.LoginSource, _ = base.StrTo(fields[1]).Int64()
|
||||
u.LoginName = form.LoginName
|
||||
fmt.Println(u.LoginType, u.LoginSource, u.LoginName)
|
||||
}
|
||||
|
||||
var err error
|
||||
if u, err = models.RegisterUser(u); err != nil {
|
||||
if u, err = models.CreateUser(u); err != nil {
|
||||
switch err {
|
||||
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:
|
||||
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:
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "admin/users/new", &form)
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), USER_NEW, &form)
|
||||
default:
|
||||
ctx.Handle(500, "admin.user.NewUser", err)
|
||||
ctx.Handle(500, "admin.user.NewUser(CreateUser)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -96,18 +99,18 @@ func EditUser(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
u, err := models.GetUserById(int64(uid))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.user.EditUser", err)
|
||||
ctx.Handle(500, "admin.user.EditUser(GetUserById)", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["User"] = u
|
||||
auths, err := models.GetAuths()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.user.NewUser", err)
|
||||
ctx.Handle(500, "admin.user.NewUser(GetAuths)", err)
|
||||
return
|
||||
}
|
||||
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) {
|
||||
|
@ -116,13 +119,18 @@ func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.Admi
|
|||
|
||||
uid, err := base.StrTo(params["userid"]).Int()
|
||||
if err != nil {
|
||||
ctx.Handle(404, "admin.user.EditUser", err)
|
||||
ctx.Handle(404, "admin.user.EditUserPost", err)
|
||||
return
|
||||
}
|
||||
|
||||
u, err := models.GetUserById(int64(uid))
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -134,7 +142,7 @@ func EditUserPost(ctx *middleware.Context, params martini.Params, form auth.Admi
|
|||
u.IsActive = form.Active
|
||||
u.IsAdmin = form.Admin
|
||||
if err := models.UpdateUser(u); err != nil {
|
||||
ctx.Handle(500, "admin.user.EditUser", err)
|
||||
ctx.Handle(500, "admin.user.EditUserPost(UpdateUser)", err)
|
||||
return
|
||||
}
|
||||
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")
|
||||
uid, err := base.StrTo(params["userid"]).Int()
|
||||
if err != nil {
|
||||
ctx.Handle(404, "admin.user.EditUser", err)
|
||||
ctx.Handle(404, "admin.user.DeleteUser", err)
|
||||
return
|
||||
}
|
||||
|
||||
u, err := models.GetUserById(int64(uid))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.user.EditUser", err)
|
||||
ctx.Handle(500, "admin.user.DeleteUser(GetUserById)", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,16 @@ package routers
|
|||
|
||||
import (
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
"github.com/gogits/gogs/routers/user"
|
||||
)
|
||||
|
||||
const (
|
||||
HOME base.TplName = "home"
|
||||
)
|
||||
|
||||
func Home(ctx *middleware.Context) {
|
||||
if ctx.IsSigned {
|
||||
user.Dashboard(ctx)
|
||||
|
@ -40,7 +45,7 @@ func Home(ctx *middleware.Context) {
|
|||
}
|
||||
}
|
||||
ctx.Data["Repos"] = repos
|
||||
ctx.HTML(200, "home")
|
||||
ctx.HTML(200, HOME)
|
||||
}
|
||||
|
||||
func NotFound(ctx *middleware.Context) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"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["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60
|
||||
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"
|
||||
)
|
||||
|
||||
const (
|
||||
INSTALL base.TplName = "install"
|
||||
)
|
||||
|
||||
func checkRunMode() {
|
||||
switch setting.Cfg.MustValue("", "RUN_MODE") {
|
||||
case "prod":
|
||||
|
@ -72,6 +76,7 @@ func renderDbOption(ctx *middleware.Context) {
|
|||
ctx.Data["DbOptions"] = []string{"MySQL", "PostgreSQL", "SQLite3"}
|
||||
}
|
||||
|
||||
// @router /install [get]
|
||||
func Install(ctx *middleware.Context, form auth.InstallForm) {
|
||||
if setting.InstallLock {
|
||||
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
|
||||
|
||||
auth.AssignForm(form, ctx.Data)
|
||||
ctx.HTML(200, "install")
|
||||
ctx.HTML(200, INSTALL)
|
||||
}
|
||||
|
||||
func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
||||
if setting.InstallLock {
|
||||
ctx.Handle(404, "install.Install", errors.New("Installation is prohibited"))
|
||||
ctx.Handle(404, "install.InstallPost", errors.New("Installation is prohibited"))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -135,12 +140,12 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
ctx.Data["CurDbOption"] = form.Database
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "install")
|
||||
ctx.HTML(200, INSTALL)
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -158,18 +163,19 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
// Set test engine.
|
||||
var x *xorm.Engine
|
||||
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`) {
|
||||
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 {
|
||||
ctx.RenderWithErr("Database setting is not correct: "+err.Error(), "install", &form)
|
||||
ctx.RenderWithErr("Database setting is not correct: "+err.Error(), INSTALL, &form)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Test repository root path.
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -180,7 +186,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
}
|
||||
// Does not check run user when the install lock is off.
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -214,18 +220,18 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
|
|||
|
||||
os.MkdirAll("custom/conf", os.ModePerm)
|
||||
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
|
||||
}
|
||||
|
||||
GlobalInit()
|
||||
|
||||
// Create admin account.
|
||||
if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd,
|
||||
if _, err := models.CreateUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd,
|
||||
IsAdmin: true, IsActive: true}); err != nil {
|
||||
if err != models.ErrUserAlreadyExist {
|
||||
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
|
||||
}
|
||||
log.Info("Admin account already exist")
|
||||
|
|
|
@ -1,11 +1,162 @@
|
|||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package org
|
||||
|
||||
import (
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/routers/user"
|
||||
)
|
||||
|
||||
const (
|
||||
NEW base.TplName = "org/new"
|
||||
SETTINGS base.TplName = "org/settings"
|
||||
)
|
||||
|
||||
func Organization(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Organization Name" + params["org"]
|
||||
ctx.Data["Title"] = "Organization " + params["org"]
|
||||
ctx.HTML(200, "org/org")
|
||||
}
|
||||
|
||||
func Members(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Organization " + params["org"] + " Members"
|
||||
ctx.HTML(200, "org/members")
|
||||
}
|
||||
|
||||
|
||||
func New(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Create An Organization"
|
||||
ctx.HTML(200, NEW)
|
||||
}
|
||||
|
||||
func NewPost(ctx *middleware.Context, form auth.CreateOrgForm) {
|
||||
ctx.Data["Title"] = "Create An Organization"
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, NEW)
|
||||
return
|
||||
}
|
||||
|
||||
org := &models.User{
|
||||
Name: form.OrgName,
|
||||
Email: form.Email,
|
||||
IsActive: true, // NOTE: may need to set false when require e-mail confirmation.
|
||||
Type: models.ORGANIZATION,
|
||||
}
|
||||
|
||||
var err error
|
||||
if org, err = models.CreateOrganization(org, ctx.User); err != nil {
|
||||
switch err {
|
||||
case models.ErrUserAlreadyExist:
|
||||
ctx.Data["Err_OrgName"] = true
|
||||
ctx.RenderWithErr("Organization name has been already taken", NEW, &form)
|
||||
case models.ErrEmailAlreadyUsed:
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErr("E-mail address has been already used", NEW, &form)
|
||||
case models.ErrUserNameIllegal:
|
||||
ctx.Data["Err_OrgName"] = true
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), NEW, &form)
|
||||
default:
|
||||
ctx.Handle(500, "user.NewPost(CreateUser)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Trace("%s Organization created: %s", ctx.Req.RequestURI, org.Name)
|
||||
|
||||
ctx.Redirect("/org/" + form.OrgName + "/dashboard")
|
||||
}
|
||||
|
||||
func Dashboard(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Dashboard"
|
||||
ctx.Data["PageIsUserDashboard"] = true
|
||||
ctx.Data["PageIsOrgDashboard"] = true
|
||||
|
||||
org, err := models.GetUserByName(params["org"])
|
||||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Handle(404, "org.Dashboard(GetUserByName)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "org.Dashboard(GetUserByName)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err := ctx.User.GetOrganizations(); err != nil {
|
||||
ctx.Handle(500, "home.Dashboard(GetOrganizations)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Orgs"] = ctx.User.Orgs
|
||||
ctx.Data["ContextUser"] = org
|
||||
|
||||
ctx.Data["MyRepos"], err = models.GetRepositories(org.Id, true)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "org.Dashboard(GetRepositories)", err)
|
||||
return
|
||||
}
|
||||
|
||||
actions, err := models.GetFeeds(org.Id, 0, false)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "org.Dashboard(GetFeeds)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Feeds"] = actions
|
||||
|
||||
ctx.HTML(200, user.DASHBOARD)
|
||||
}
|
||||
|
||||
func Settings(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Settings"
|
||||
|
||||
org, err := models.GetUserByName(params["org"])
|
||||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Handle(404, "org.Settings(GetUserByName)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "org.Settings(GetUserByName)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.Data["Org"] = org
|
||||
|
||||
ctx.HTML(200, SETTINGS)
|
||||
}
|
||||
|
||||
func SettingsPost(ctx *middleware.Context, params martini.Params, form auth.OrgSettingForm) {
|
||||
ctx.Data["Title"] = "Settings"
|
||||
|
||||
org, err := models.GetUserByName(params["org"])
|
||||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Handle(404, "org.SettingsPost(GetUserByName)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "org.SettingsPost(GetUserByName)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.Data["Org"] = org
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, SETTINGS)
|
||||
return
|
||||
}
|
||||
|
||||
org.FullName = form.DisplayName
|
||||
org.Email = form.Email
|
||||
org.Description = form.Description
|
||||
org.Website = form.Website
|
||||
org.Location = form.Location
|
||||
if err = models.UpdateUser(org); err != nil {
|
||||
ctx.Handle(500, "org.SettingsPost(UpdateUser)", err)
|
||||
return
|
||||
}
|
||||
log.Trace("%s Organization setting updated: %s", ctx.Req.RequestURI, org.LowerName)
|
||||
ctx.Flash.Success("Organization profile has been successfully updated.")
|
||||
ctx.Redirect("/org/" + org.Name + "/settings")
|
||||
}
|
||||
|
|
21
routers/org/teams.go
Normal file
21
routers/org/teams.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package org
|
||||
|
||||
import (
|
||||
"github.com/go-martini/martini"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
func Teams(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Organization "+params["org"]+" Teams"
|
||||
ctx.HTML(200, "org/teams")
|
||||
}
|
||||
|
||||
func NewTeam(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Organization "+params["org"]+" New Team"
|
||||
ctx.HTML(200, "org/new_team")
|
||||
}
|
||||
|
||||
func EditTeam(ctx *middleware.Context, params martini.Params){
|
||||
ctx.Data["Title"] = "Organization "+params["org"]+" Edit Team"
|
||||
ctx.HTML(200,"org/edit_team")
|
||||
}
|
|
@ -7,22 +7,27 @@ package repo
|
|||
import (
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
BRANCH base.TplName = "repo/branch"
|
||||
)
|
||||
|
||||
func Branches(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Branches"
|
||||
ctx.Data["IsRepoToolbarBranches"] = true
|
||||
|
||||
brs, err := ctx.Repo.GitRepo.GetBranches()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "repo.Branches", err)
|
||||
ctx.Handle(500, "repo.Branches(GetBranches)", err)
|
||||
return
|
||||
} else if len(brs) == 0 {
|
||||
ctx.Handle(404, "repo.Branches", nil)
|
||||
ctx.Handle(404, "repo.Branches(GetBranches)", nil)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Branches"] = brs
|
||||
ctx.HTML(200, "repo/branches")
|
||||
ctx.HTML(200, BRANCH)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,11 @@ import (
|
|||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
COMMITS base.TplName = "repo/commits"
|
||||
DIFF base.TplName = "repo/diff"
|
||||
)
|
||||
|
||||
func Commits(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["IsRepoToolbarCommits"] = true
|
||||
|
||||
|
@ -22,10 +27,10 @@ func Commits(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
brs, err := ctx.Repo.GitRepo.GetBranches()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "repo.Commits", err)
|
||||
ctx.Handle(500, "repo.Commits(GetBranches)", err)
|
||||
return
|
||||
} else if len(brs) == 0 {
|
||||
ctx.Handle(404, "repo.Commits", nil)
|
||||
ctx.Handle(404, "repo.Commits(GetBranches)", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -61,7 +66,43 @@ func Commits(ctx *middleware.Context, params martini.Params) {
|
|||
ctx.Data["CommitCount"] = commitsCount
|
||||
ctx.Data["LastPageNum"] = lastPage
|
||||
ctx.Data["NextPageNum"] = nextPage
|
||||
ctx.HTML(200, "repo/commits")
|
||||
ctx.HTML(200, COMMITS)
|
||||
}
|
||||
|
||||
func SearchCommits(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["IsSearchPage"] = true
|
||||
ctx.Data["IsRepoToolbarCommits"] = true
|
||||
|
||||
keyword := ctx.Query("q")
|
||||
if len(keyword) == 0 {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName)
|
||||
return
|
||||
}
|
||||
|
||||
userName := params["username"]
|
||||
repoName := params["reponame"]
|
||||
|
||||
brs, err := ctx.Repo.GitRepo.GetBranches()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "repo.SearchCommits(GetBranches)", err)
|
||||
return
|
||||
} else if len(brs) == 0 {
|
||||
ctx.Handle(404, "repo.SearchCommits(GetBranches)", nil)
|
||||
return
|
||||
}
|
||||
|
||||
commits, err := ctx.Repo.Commit.SearchCommits(keyword)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "repo.SearchCommits(SearchCommits)", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Username"] = userName
|
||||
ctx.Data["Reponame"] = repoName
|
||||
ctx.Data["CommitCount"] = commits.Len()
|
||||
ctx.Data["Commits"] = commits
|
||||
ctx.HTML(200, COMMITS)
|
||||
}
|
||||
|
||||
func Diff(ctx *middleware.Context, params martini.Params) {
|
||||
|
@ -75,7 +116,7 @@ func Diff(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId)
|
||||
if err != nil {
|
||||
ctx.Handle(404, "repo.Diff", err)
|
||||
ctx.Handle(404, "repo.Diff(GetDiff)", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -119,43 +160,7 @@ func Diff(ctx *middleware.Context, params martini.Params) {
|
|||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
||||
ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId)
|
||||
ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId)
|
||||
ctx.HTML(200, "repo/diff")
|
||||
}
|
||||
|
||||
func SearchCommits(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["IsSearchPage"] = true
|
||||
ctx.Data["IsRepoToolbarCommits"] = true
|
||||
|
||||
keyword := ctx.Query("q")
|
||||
if len(keyword) == 0 {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName)
|
||||
return
|
||||
}
|
||||
|
||||
userName := params["username"]
|
||||
repoName := params["reponame"]
|
||||
|
||||
brs, err := ctx.Repo.GitRepo.GetBranches()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "repo.SearchCommits(GetBranches)", err)
|
||||
return
|
||||
} else if len(brs) == 0 {
|
||||
ctx.Handle(404, "repo.SearchCommits(GetBranches)", nil)
|
||||
return
|
||||
}
|
||||
|
||||
commits, err := ctx.Repo.Commit.SearchCommits(keyword)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "repo.SearchCommits(SearchCommits)", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Username"] = userName
|
||||
ctx.Data["Reponame"] = repoName
|
||||
ctx.Data["CommitCount"] = commits.Len()
|
||||
ctx.Data["Commits"] = commits
|
||||
ctx.HTML(200, "repo/commits")
|
||||
ctx.HTML(200, DIFF)
|
||||
}
|
||||
|
||||
func FileHistory(ctx *middleware.Context, params martini.Params) {
|
||||
|
@ -184,8 +189,7 @@ func FileHistory(ctx *middleware.Context, params martini.Params) {
|
|||
if err != nil {
|
||||
ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err)
|
||||
return
|
||||
}
|
||||
if commitsCount == 0 {
|
||||
} else if commitsCount == 0 {
|
||||
ctx.Handle(404, "repo.FileHistory", nil)
|
||||
return
|
||||
}
|
||||
|
@ -217,5 +221,5 @@ func FileHistory(ctx *middleware.Context, params martini.Params) {
|
|||
ctx.Data["CommitCount"] = commitsCount
|
||||
ctx.Data["LastPageNum"] = lastPage
|
||||
ctx.Data["NextPageNum"] = nextPage
|
||||
ctx.HTML(200, "repo/commits")
|
||||
ctx.HTML(200, COMMITS)
|
||||
}
|
||||
|
|
|
@ -107,9 +107,9 @@ func Http(ctx *middleware.Context, params martini.Params) {
|
|||
}
|
||||
|
||||
if !isPublicPull {
|
||||
var tp = models.AU_WRITABLE
|
||||
var tp = models.WRITABLE
|
||||
if isPull {
|
||||
tp = models.AU_READABLE
|
||||
tp = models.READABLE
|
||||
}
|
||||
|
||||
has, err := models.HasAccess(authUsername, username+"/"+reponame, tp)
|
||||
|
@ -117,8 +117,8 @@ func Http(ctx *middleware.Context, params martini.Params) {
|
|||
ctx.Handle(401, "no basic auth and digit auth", nil)
|
||||
return
|
||||
} else if !has {
|
||||
if tp == models.AU_READABLE {
|
||||
has, err = models.HasAccess(authUsername, username+"/"+reponame, models.AU_WRITABLE)
|
||||
if tp == models.READABLE {
|
||||
has, err = models.HasAccess(authUsername, username+"/"+reponame, models.WRITABLE)
|
||||
if err != nil || !has {
|
||||
ctx.Handle(401, "no basic auth and digit auth", nil)
|
||||
return
|
||||
|
|
|
@ -22,6 +22,16 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const (
|
||||
ISSUES base.TplName = "repo/issue/list"
|
||||
ISSUE_CREATE base.TplName = "repo/issue/create"
|
||||
ISSUE_VIEW base.TplName = "repo/issue/view"
|
||||
|
||||
MILESTONE base.TplName = "repo/issue/milestone"
|
||||
MILESTONE_NEW base.TplName = "repo/issue/milestone_new"
|
||||
MILESTONE_EDIT base.TplName = "repo/issue/milestone_edit"
|
||||
)
|
||||
|
||||
func Issues(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Issues"
|
||||
ctx.Data["IsRepoToolbarIssues"] = true
|
||||
|
@ -134,7 +144,7 @@ func Issues(ctx *middleware.Context) {
|
|||
} else {
|
||||
ctx.Data["ShowCount"] = issueStats.OpenCount
|
||||
}
|
||||
ctx.HTML(200, "issue/list")
|
||||
ctx.HTML(200, ISSUES)
|
||||
}
|
||||
|
||||
func CreateIssue(ctx *middleware.Context, params martini.Params) {
|
||||
|
@ -161,7 +171,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) {
|
|||
return
|
||||
}
|
||||
ctx.Data["Collaborators"] = us
|
||||
ctx.HTML(200, "issue/create")
|
||||
ctx.HTML(200, ISSUE_CREATE)
|
||||
}
|
||||
|
||||
func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
|
||||
|
@ -190,7 +200,7 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
|
|||
ctx.Data["Collaborators"] = us
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "issue/create")
|
||||
ctx.HTML(200, ISSUE_CREATE)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -392,7 +402,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
|
|||
ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner || (ctx.IsSigned && issue.PosterId == ctx.User.Id)
|
||||
ctx.Data["IsRepoToolbarIssues"] = true
|
||||
ctx.Data["IsRepoToolbarIssuesList"] = false
|
||||
ctx.HTML(200, "issue/view")
|
||||
ctx.HTML(200, ISSUE_VIEW)
|
||||
}
|
||||
|
||||
func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
|
||||
|
@ -794,14 +804,14 @@ func Milestones(ctx *middleware.Context) {
|
|||
} else {
|
||||
ctx.Data["State"] = "open"
|
||||
}
|
||||
ctx.HTML(200, "issue/milestone")
|
||||
ctx.HTML(200, MILESTONE)
|
||||
}
|
||||
|
||||
func NewMilestone(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "New Milestone"
|
||||
ctx.Data["IsRepoToolbarIssues"] = true
|
||||
ctx.Data["IsRepoToolbarIssuesList"] = true
|
||||
ctx.HTML(200, "issue/milestone_new")
|
||||
ctx.HTML(200, MILESTONE_NEW)
|
||||
}
|
||||
|
||||
func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
|
||||
|
@ -809,6 +819,11 @@ func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) {
|
|||
ctx.Data["IsRepoToolbarIssues"] = true
|
||||
ctx.Data["IsRepoToolbarIssuesList"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, MILESTONE_NEW)
|
||||
return
|
||||
}
|
||||
|
||||
var deadline time.Time
|
||||
var err error
|
||||
if len(form.Deadline) == 0 {
|
||||
|
@ -890,7 +905,7 @@ func UpdateMilestone(ctx *middleware.Context, params martini.Params) {
|
|||
}
|
||||
ctx.Data["Milestone"] = mile
|
||||
|
||||
ctx.HTML(200, "issue/milestone_edit")
|
||||
ctx.HTML(200, MILESTONE_EDIT)
|
||||
}
|
||||
|
||||
func UpdateMilestonePost(ctx *middleware.Context, params martini.Params, form auth.CreateMilestoneForm) {
|
||||
|
@ -914,6 +929,11 @@ func UpdateMilestonePost(ctx *middleware.Context, params martini.Params, form au
|
|||
return
|
||||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, MILESTONE_EDIT)
|
||||
return
|
||||
}
|
||||
|
||||
var deadline time.Time
|
||||
if len(form.Deadline) == 0 {
|
||||
form.Deadline = "12/31/9999"
|
||||
|
|
|
@ -7,10 +7,15 @@ package repo
|
|||
import (
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
PULLS base.TplName = "repo/pulls"
|
||||
)
|
||||
|
||||
func Pulls(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["IsRepoToolbarPulls"] = true
|
||||
ctx.HTML(200, "repo/pulls")
|
||||
ctx.HTML(200, PULLS)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,12 @@ import (
|
|||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
RELEASES base.TplName = "repo/release/list"
|
||||
RELEASE_NEW base.TplName = "repo/release/new"
|
||||
RELEASE_EDIT base.TplName = "repo/release/edit"
|
||||
)
|
||||
|
||||
func Releases(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Releases"
|
||||
ctx.Data["IsRepoToolbarReleases"] = true
|
||||
|
@ -100,7 +106,7 @@ func Releases(ctx *middleware.Context) {
|
|||
}
|
||||
models.SortReleases(tags)
|
||||
ctx.Data["Releases"] = tags
|
||||
ctx.HTML(200, "release/list")
|
||||
ctx.HTML(200, RELEASES)
|
||||
}
|
||||
|
||||
func NewRelease(ctx *middleware.Context) {
|
||||
|
@ -112,7 +118,7 @@ func NewRelease(ctx *middleware.Context) {
|
|||
ctx.Data["Title"] = "New Release"
|
||||
ctx.Data["IsRepoToolbarReleases"] = true
|
||||
ctx.Data["IsRepoReleaseNew"] = true
|
||||
ctx.HTML(200, "release/new")
|
||||
ctx.HTML(200, RELEASE_NEW)
|
||||
}
|
||||
|
||||
func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
|
||||
|
@ -126,7 +132,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
|
|||
ctx.Data["IsRepoReleaseNew"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "release/new")
|
||||
ctx.HTML(200, RELEASE_NEW)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -187,7 +193,7 @@ func EditRelease(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
ctx.Data["Title"] = "Edit Release"
|
||||
ctx.Data["IsRepoToolbarReleases"] = true
|
||||
ctx.HTML(200, "release/edit")
|
||||
ctx.HTML(200, RELEASE_EDIT)
|
||||
}
|
||||
|
||||
func EditReleasePost(ctx *middleware.Context, params martini.Params, form auth.EditReleaseForm) {
|
||||
|
@ -208,6 +214,11 @@ func EditReleasePost(ctx *middleware.Context, params martini.Params, form auth.E
|
|||
}
|
||||
ctx.Data["Release"] = rel
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, RELEASE_EDIT)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Title"] = "Edit Release"
|
||||
ctx.Data["IsRepoToolbarReleases"] = true
|
||||
|
||||
|
|
|
@ -25,12 +25,25 @@ import (
|
|||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
CREATE base.TplName = "repo/create"
|
||||
MIGRATE base.TplName = "repo/migrate"
|
||||
SINGLE base.TplName = "repo/single"
|
||||
)
|
||||
|
||||
func Create(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Create repository"
|
||||
ctx.Data["PageIsNewRepo"] = true
|
||||
ctx.Data["LanguageIgns"] = models.LanguageIgns
|
||||
ctx.Data["Licenses"] = models.Licenses
|
||||
ctx.HTML(200, "repo/create")
|
||||
|
||||
if err := ctx.User.GetOrganizations(); err != nil {
|
||||
ctx.Handle(500, "home.Dashboard(GetOrganizations)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Orgs"] = ctx.User.Orgs
|
||||
|
||||
ctx.HTML(200, CREATE)
|
||||
}
|
||||
|
||||
func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
|
||||
|
@ -39,76 +52,125 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
|
|||
ctx.Data["LanguageIgns"] = models.LanguageIgns
|
||||
ctx.Data["Licenses"] = models.Licenses
|
||||
|
||||
if err := ctx.User.GetOrganizations(); err != nil {
|
||||
ctx.Handle(500, "home.CreatePost(GetOrganizations)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Orgs"] = ctx.User.Orgs
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "repo/create")
|
||||
ctx.HTML(200, CREATE)
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := models.CreateRepository(ctx.User, form.RepoName, form.Description,
|
||||
u := ctx.User
|
||||
// Not equal means current user is an organization.
|
||||
if u.Id != form.Uid {
|
||||
var err error
|
||||
u, err = models.GetUserById(form.Uid)
|
||||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Handle(404, "home.CreatePost(GetUserById)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "home.CreatePost(GetUserById)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
repo, err := models.CreateRepository(u, form.RepoName, form.Description,
|
||||
form.Language, form.License, form.Private, false, form.InitReadme)
|
||||
if err == nil {
|
||||
log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName)
|
||||
ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName)
|
||||
log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, u.LowerName, form.RepoName)
|
||||
ctx.Redirect("/" + u.Name + "/" + form.RepoName)
|
||||
return
|
||||
} else if err == models.ErrRepoAlreadyExist {
|
||||
ctx.RenderWithErr("Repository name has already been used", "repo/create", &form)
|
||||
ctx.RenderWithErr("Repository name has already been used", CREATE, &form)
|
||||
return
|
||||
} else if err == models.ErrRepoNameIllegal {
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/create", &form)
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), CREATE, &form)
|
||||
return
|
||||
}
|
||||
|
||||
if repo != nil {
|
||||
if errDelete := models.DeleteRepository(ctx.User.Id, repo.Id, ctx.User.Name); errDelete != nil {
|
||||
log.Error("repo.MigratePost(CreatePost): %v", errDelete)
|
||||
if errDelete := models.DeleteRepository(u.Id, repo.Id, u.Name); errDelete != nil {
|
||||
log.Error("repo.CreatePost(DeleteRepository): %v", errDelete)
|
||||
}
|
||||
}
|
||||
ctx.Handle(500, "repo.Create", err)
|
||||
ctx.Handle(500, "repo.CreatePost(CreateRepository)", err)
|
||||
}
|
||||
|
||||
func Migrate(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Migrate repository"
|
||||
ctx.Data["PageIsNewRepo"] = true
|
||||
ctx.HTML(200, "repo/migrate")
|
||||
|
||||
if err := ctx.User.GetOrganizations(); err != nil {
|
||||
ctx.Handle(500, "home.Migrate(GetOrganizations)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Orgs"] = ctx.User.Orgs
|
||||
|
||||
ctx.HTML(200, MIGRATE)
|
||||
}
|
||||
|
||||
func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
|
||||
ctx.Data["Title"] = "Migrate repository"
|
||||
ctx.Data["PageIsNewRepo"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "repo/migrate")
|
||||
if err := ctx.User.GetOrganizations(); err != nil {
|
||||
ctx.Handle(500, "home.MigratePost(GetOrganizations)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Orgs"] = ctx.User.Orgs
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, MIGRATE)
|
||||
return
|
||||
}
|
||||
|
||||
u := ctx.User
|
||||
// Not equal means current user is an organization.
|
||||
if u.Id != form.Uid {
|
||||
var err error
|
||||
u, err = models.GetUserById(form.Uid)
|
||||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Handle(404, "home.MigratePost(GetUserById)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "home.MigratePost(GetUserById)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
authStr := strings.Replace(fmt.Sprintf("://%s:%s",
|
||||
form.AuthUserName, form.AuthPasswd), "@", "%40", -1)
|
||||
url := strings.Replace(form.Url, "://", authStr+"@", 1)
|
||||
repo, err := models.MigrateRepository(ctx.User, form.RepoName, form.Description, form.Private,
|
||||
repo, err := models.MigrateRepository(u, form.RepoName, form.Description, form.Private,
|
||||
form.Mirror, url)
|
||||
if err == nil {
|
||||
log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName)
|
||||
ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName)
|
||||
log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, u.LowerName, form.RepoName)
|
||||
ctx.Redirect("/" + u.Name + "/" + form.RepoName)
|
||||
return
|
||||
} else if err == models.ErrRepoAlreadyExist {
|
||||
ctx.RenderWithErr("Repository name has already been used", "repo/migrate", &form)
|
||||
ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form)
|
||||
return
|
||||
} else if err == models.ErrRepoNameIllegal {
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/migrate", &form)
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), MIGRATE, &form)
|
||||
return
|
||||
}
|
||||
|
||||
if repo != nil {
|
||||
if errDelete := models.DeleteRepository(ctx.User.Id, repo.Id, ctx.User.Name); errDelete != nil {
|
||||
if errDelete := models.DeleteRepository(u.Id, repo.Id, u.Name); errDelete != nil {
|
||||
log.Error("repo.MigratePost(DeleteRepository): %v", errDelete)
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(err.Error(), "Authentication failed") {
|
||||
ctx.RenderWithErr(err.Error(), "repo/migrate", &form)
|
||||
ctx.RenderWithErr(err.Error(), MIGRATE, &form)
|
||||
return
|
||||
}
|
||||
ctx.Handle(500, "repo.Migrate", err)
|
||||
ctx.Handle(500, "repo.Migrate(MigrateRepository)", err)
|
||||
}
|
||||
|
||||
func Single(ctx *middleware.Context, params martini.Params) {
|
||||
|
@ -291,7 +353,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
|||
ctx.Data["Treenames"] = treenames
|
||||
ctx.Data["TreePath"] = treePath
|
||||
ctx.Data["BranchLink"] = branchLink
|
||||
ctx.HTML(200, "repo/single")
|
||||
ctx.HTML(200, SINGLE)
|
||||
}
|
||||
|
||||
func basicEncode(username, password string) string {
|
||||
|
@ -318,7 +380,7 @@ func basicDecode(encoded string) (user string, name string, err error) {
|
|||
func authRequired(ctx *middleware.Context) {
|
||||
ctx.ResponseWriter.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
|
||||
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) {
|
||||
|
|
|
@ -20,10 +20,19 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const (
|
||||
SETTING base.TplName = "repo/setting"
|
||||
COLLABORATION base.TplName = "repo/collaboration"
|
||||
|
||||
HOOKS base.TplName = "repo/hooks"
|
||||
HOOK_ADD base.TplName = "repo/hook_add"
|
||||
HOOK_EDIT base.TplName = "repo/hook_edit"
|
||||
)
|
||||
|
||||
func Setting(ctx *middleware.Context) {
|
||||
ctx.Data["IsRepoToolbarSetting"] = true
|
||||
ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - settings"
|
||||
ctx.HTML(200, "repo/setting")
|
||||
ctx.HTML(200, SETTING)
|
||||
}
|
||||
|
||||
func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
||||
|
@ -32,7 +41,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
|||
switch ctx.Query("action") {
|
||||
case "update":
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "repo/setting")
|
||||
ctx.HTML(200, SETTING)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -44,7 +53,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
|||
ctx.Handle(500, "setting.SettingPost(update: check existence)", err)
|
||||
return
|
||||
} else if isExist {
|
||||
ctx.RenderWithErr("Repository name has been taken in your repositories.", "repo/setting", nil)
|
||||
ctx.RenderWithErr("Repository name has been taken in your repositories.", SETTING, nil)
|
||||
return
|
||||
} else if err = models.ChangeRepositoryName(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newRepoName); err != nil {
|
||||
ctx.Handle(500, "setting.SettingPost(change repository name)", err)
|
||||
|
@ -84,7 +93,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
|||
ctx.Redirect(fmt.Sprintf("/%s/%s/settings", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name))
|
||||
case "transfer":
|
||||
if len(ctx.Repo.Repository.Name) == 0 || ctx.Repo.Repository.Name != ctx.Query("repository") {
|
||||
ctx.RenderWithErr("Please make sure you entered repository name is correct.", "repo/setting", nil)
|
||||
ctx.RenderWithErr("Please make sure you entered repository name is correct.", SETTING, nil)
|
||||
return
|
||||
} else if ctx.Repo.Repository.IsMirror {
|
||||
ctx.Error(404)
|
||||
|
@ -98,7 +107,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
|||
ctx.Handle(500, "setting.SettingPost(transfer: check existence)", err)
|
||||
return
|
||||
} else if !isExist {
|
||||
ctx.RenderWithErr("Please make sure you entered owner name is correct.", "repo/setting", nil)
|
||||
ctx.RenderWithErr("Please make sure you entered owner name is correct.", SETTING, nil)
|
||||
return
|
||||
} else if err = models.TransferOwnership(ctx.User, newOwner, ctx.Repo.Repository); err != nil {
|
||||
ctx.Handle(500, "setting.SettingPost(transfer repository)", err)
|
||||
|
@ -109,7 +118,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) {
|
|||
ctx.Redirect("/")
|
||||
case "delete":
|
||||
if len(ctx.Repo.Repository.Name) == 0 || ctx.Repo.Repository.Name != ctx.Query("repository") {
|
||||
ctx.RenderWithErr("Please make sure you entered repository name is correct.", "repo/setting", nil)
|
||||
ctx.RenderWithErr("Please make sure you entered repository name is correct.", SETTING, nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -156,7 +165,7 @@ func Collaboration(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
ctx.Data["Collaborators"] = us
|
||||
ctx.HTML(200, "repo/collaboration")
|
||||
ctx.HTML(200, COLLABORATION)
|
||||
}
|
||||
|
||||
func CollaborationPost(ctx *middleware.Context) {
|
||||
|
@ -166,7 +175,7 @@ func CollaborationPost(ctx *middleware.Context) {
|
|||
ctx.Redirect(ctx.Req.RequestURI)
|
||||
return
|
||||
}
|
||||
has, err := models.HasAccess(name, repoLink, models.AU_WRITABLE)
|
||||
has, err := models.HasAccess(name, repoLink, models.WRITABLE)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "setting.CollaborationPost(HasAccess)", err)
|
||||
return
|
||||
|
@ -187,7 +196,7 @@ func CollaborationPost(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
if err = models.AddAccess(&models.Access{UserName: name, RepoName: repoLink,
|
||||
Mode: models.AU_WRITABLE}); err != nil {
|
||||
Mode: models.WRITABLE}); err != nil {
|
||||
ctx.Handle(500, "setting.CollaborationPost(AddAccess)", err)
|
||||
return
|
||||
}
|
||||
|
@ -226,13 +235,13 @@ func WebHooks(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
ctx.Data["Webhooks"] = ws
|
||||
ctx.HTML(200, "repo/hooks")
|
||||
ctx.HTML(200, HOOKS)
|
||||
}
|
||||
|
||||
func WebHooksAdd(ctx *middleware.Context) {
|
||||
ctx.Data["IsRepoToolbarWebHooks"] = true
|
||||
ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Add Webhook"
|
||||
ctx.HTML(200, "repo/hooks_add")
|
||||
ctx.HTML(200, HOOK_ADD)
|
||||
}
|
||||
|
||||
func WebHooksAddPost(ctx *middleware.Context, form auth.NewWebhookForm) {
|
||||
|
@ -240,7 +249,7 @@ func WebHooksAddPost(ctx *middleware.Context, form auth.NewWebhookForm) {
|
|||
ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Add Webhook"
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "repo/hooks_add")
|
||||
ctx.HTML(200, HOOK_ADD)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -293,40 +302,46 @@ func WebHooksEdit(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
w.GetEvent()
|
||||
ctx.Data["Webhook"] = w
|
||||
ctx.HTML(200, "repo/hooks_edit")
|
||||
ctx.HTML(200, HOOK_EDIT)
|
||||
}
|
||||
|
||||
func WebHooksEditPost(ctx *middleware.Context, params martini.Params, form auth.NewWebhookForm) {
|
||||
ctx.Data["IsRepoToolbarWebHooks"] = true
|
||||
ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Webhook"
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "repo/hooks_add")
|
||||
return
|
||||
}
|
||||
|
||||
hookId, _ := base.StrTo(params["id"]).Int64()
|
||||
if hookId == 0 {
|
||||
ctx.Handle(404, "setting.WebHooksEditPost", nil)
|
||||
return
|
||||
}
|
||||
|
||||
w, err := models.GetWebhookById(hookId)
|
||||
if err != nil {
|
||||
if err == models.ErrWebhookNotExist {
|
||||
ctx.Handle(404, "setting.WebHooksEditPost(GetWebhookById)", nil)
|
||||
} else {
|
||||
ctx.Handle(500, "setting.WebHooksEditPost(GetWebhookById)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, HOOK_EDIT)
|
||||
return
|
||||
}
|
||||
|
||||
ct := models.JSON
|
||||
if form.ContentType == "2" {
|
||||
ct = models.FORM
|
||||
}
|
||||
|
||||
w := &models.Webhook{
|
||||
Id: hookId,
|
||||
RepoId: ctx.Repo.Repository.Id,
|
||||
Url: form.Url,
|
||||
ContentType: ct,
|
||||
Secret: form.Secret,
|
||||
HookEvent: &models.HookEvent{
|
||||
PushOnly: form.PushOnly,
|
||||
},
|
||||
IsActive: form.Active,
|
||||
w.Url = form.Url
|
||||
w.ContentType = ct
|
||||
w.Secret = form.Secret
|
||||
w.HookEvent = &models.HookEvent{
|
||||
PushOnly: form.PushOnly,
|
||||
}
|
||||
w.IsActive = form.Active
|
||||
if err := w.UpdateEvent(); err != nil {
|
||||
ctx.Handle(500, "setting.WebHooksEditPost(UpdateEvent)", err)
|
||||
return
|
||||
|
|
|
@ -17,10 +17,25 @@ import (
|
|||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
DASHBOARD base.TplName = "user/dashboard"
|
||||
PROFILE base.TplName = "user/profile"
|
||||
ISSUES base.TplName = "user/issues"
|
||||
PULLS base.TplName = "user/pulls"
|
||||
STARS base.TplName = "user/stars"
|
||||
)
|
||||
|
||||
func Dashboard(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Dashboard"
|
||||
ctx.Data["PageIsUserDashboard"] = true
|
||||
|
||||
if err := ctx.User.GetOrganizations(); err != nil {
|
||||
ctx.Handle(500, "home.Dashboard(GetOrganizations)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Orgs"] = ctx.User.Orgs
|
||||
ctx.Data["ContextUser"] = ctx.User
|
||||
|
||||
var err error
|
||||
ctx.Data["MyRepos"], err = models.GetRepositories(ctx.User.Id, true)
|
||||
if err != nil {
|
||||
|
@ -45,21 +60,21 @@ func Dashboard(ctx *middleware.Context) {
|
|||
for _, act := range actions {
|
||||
if act.IsPrivate {
|
||||
if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName,
|
||||
models.AU_READABLE); !has {
|
||||
models.READABLE); !has {
|
||||
continue
|
||||
}
|
||||
}
|
||||
feeds = append(feeds, act)
|
||||
}
|
||||
ctx.Data["Feeds"] = feeds
|
||||
ctx.HTML(200, "user/dashboard")
|
||||
ctx.HTML(200, DASHBOARD)
|
||||
}
|
||||
|
||||
func Profile(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Profile"
|
||||
ctx.Data["PageIsUserProfile"] = true
|
||||
|
||||
user, err := models.GetUserByName(params["username"])
|
||||
u, err := models.GetUserByName(params["username"])
|
||||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Handle(404, "user.Profile(GetUserByName)", err)
|
||||
|
@ -68,26 +83,30 @@ func Profile(ctx *middleware.Context, params martini.Params) {
|
|||
}
|
||||
return
|
||||
}
|
||||
ctx.Data["Owner"] = user
|
||||
// For security reason, hide e-mail address for anonymous visitors.
|
||||
if !ctx.IsSigned {
|
||||
u.Email = ""
|
||||
}
|
||||
ctx.Data["Owner"] = u
|
||||
|
||||
tab := ctx.Query("tab")
|
||||
ctx.Data["TabName"] = tab
|
||||
switch tab {
|
||||
case "activity":
|
||||
ctx.Data["Feeds"], err = models.GetFeeds(user.Id, 0, true)
|
||||
ctx.Data["Feeds"], err = models.GetFeeds(u.Id, 0, true)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Profile(GetFeeds)", err)
|
||||
return
|
||||
}
|
||||
default:
|
||||
ctx.Data["Repos"], err = models.GetRepositories(user.Id, ctx.IsSigned && ctx.User.Id == user.Id)
|
||||
ctx.Data["Repos"], err = models.GetRepositories(u.Id, ctx.IsSigned && ctx.User.Id == u.Id)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Profile(GetRepositories)", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.HTML(200, "user/profile")
|
||||
ctx.HTML(200, PROFILE)
|
||||
}
|
||||
|
||||
func Email2User(ctx *middleware.Context) {
|
||||
|
@ -119,7 +138,7 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) {
|
|||
for _, act := range actions {
|
||||
if act.IsPrivate {
|
||||
if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName,
|
||||
models.AU_READABLE); !has {
|
||||
models.READABLE); !has {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -254,13 +273,13 @@ func Issues(ctx *middleware.Context) {
|
|||
} else {
|
||||
ctx.Data["ShowCount"] = issueStats.OpenCount
|
||||
}
|
||||
ctx.HTML(200, "user/issue")
|
||||
ctx.HTML(200, ISSUES)
|
||||
}
|
||||
|
||||
func Pulls(ctx *middleware.Context) {
|
||||
ctx.HTML(200, "user/pulls")
|
||||
ctx.HTML(200, PULLS)
|
||||
}
|
||||
|
||||
func Stars(ctx *middleware.Context) {
|
||||
ctx.HTML(200, "user/stars")
|
||||
ctx.HTML(200, STARS)
|
||||
}
|
||||
|
|
|
@ -14,12 +14,21 @@ import (
|
|||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
SETTING base.TplName = "user/setting"
|
||||
SOCIAL base.TplName = "user/social"
|
||||
PASSWORD base.TplName = "user/password"
|
||||
PUBLICKEY base.TplName = "user/publickey"
|
||||
NOTIFICATION base.TplName = "user/notification"
|
||||
SECURITY base.TplName = "user/security"
|
||||
)
|
||||
|
||||
func Setting(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Setting"
|
||||
ctx.Data["PageIsUserSetting"] = true
|
||||
ctx.Data["IsUserPageSetting"] = true
|
||||
ctx.Data["Owner"] = ctx.User
|
||||
ctx.HTML(200, "user/setting")
|
||||
ctx.HTML(200, SETTING)
|
||||
}
|
||||
|
||||
func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
|
||||
|
@ -28,7 +37,7 @@ func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
|
|||
ctx.Data["IsUserPageSetting"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "user/setting")
|
||||
ctx.HTML(200, SETTING)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -59,7 +68,7 @@ func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
|
|||
ctx.User.Avatar = base.EncodeMd5(form.Avatar)
|
||||
ctx.User.AvatarEmail = form.Avatar
|
||||
if err := models.UpdateUser(ctx.User); err != nil {
|
||||
ctx.Handle(500, "setting.Setting", err)
|
||||
ctx.Handle(500, "setting.Setting(UpdateUser)", err)
|
||||
return
|
||||
}
|
||||
log.Trace("%s User setting updated: %s", ctx.Req.RequestURI, ctx.User.LowerName)
|
||||
|
@ -90,14 +99,14 @@ func SettingSocial(ctx *middleware.Context) {
|
|||
ctx.Handle(500, "user.SettingSocial(GetOauthByUserId)", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, "user/social")
|
||||
ctx.HTML(200, SOCIAL)
|
||||
}
|
||||
|
||||
func SettingPassword(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Password"
|
||||
ctx.Data["PageIsUserSetting"] = true
|
||||
ctx.Data["IsUserPageSettingPasswd"] = true
|
||||
ctx.HTML(200, "user/password")
|
||||
ctx.HTML(200, PASSWORD)
|
||||
}
|
||||
|
||||
func SettingPasswordPost(ctx *middleware.Context, form auth.UpdatePasswdForm) {
|
||||
|
@ -106,7 +115,7 @@ func SettingPasswordPost(ctx *middleware.Context, form auth.UpdatePasswdForm) {
|
|||
ctx.Data["IsUserPageSettingPasswd"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "user/password")
|
||||
ctx.HTML(200, PASSWORD)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -207,7 +216,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.HTML(200, "user/publickey")
|
||||
ctx.HTML(200, PUBLICKEY)
|
||||
}
|
||||
|
||||
func SettingNotification(ctx *middleware.Context) {
|
||||
|
@ -215,7 +224,7 @@ func SettingNotification(ctx *middleware.Context) {
|
|||
ctx.Data["Title"] = "Notification"
|
||||
ctx.Data["PageIsUserSetting"] = true
|
||||
ctx.Data["IsUserPageSettingNotify"] = true
|
||||
ctx.HTML(200, "user/notification")
|
||||
ctx.HTML(200, NOTIFICATION)
|
||||
}
|
||||
|
||||
func SettingSecurity(ctx *middleware.Context) {
|
||||
|
@ -223,5 +232,5 @@ func SettingSecurity(ctx *middleware.Context) {
|
|||
ctx.Data["Title"] = "Security"
|
||||
ctx.Data["PageIsUserSetting"] = true
|
||||
ctx.Data["IsUserPageSettingSecurity"] = true
|
||||
ctx.HTML(200, "user/security")
|
||||
ctx.HTML(200, SECURITY)
|
||||
}
|
||||
|
|
|
@ -17,12 +17,21 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const (
|
||||
SIGNIN base.TplName = "user/signin"
|
||||
SIGNUP base.TplName = "user/signup"
|
||||
DELETE base.TplName = "user/delete"
|
||||
ACTIVATE base.TplName = "user/activate"
|
||||
FORGOT_PASSWORD base.TplName = "user/forgot_passwd"
|
||||
RESET_PASSWORD base.TplName = "user/reset_passwd"
|
||||
)
|
||||
|
||||
func SignIn(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Log In"
|
||||
|
||||
if _, ok := ctx.Session.Get("socialId").(int64); ok {
|
||||
ctx.Data["IsSocialLogin"] = true
|
||||
ctx.HTML(200, "user/signin")
|
||||
ctx.HTML(200, SIGNIN)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -34,7 +43,7 @@ func SignIn(ctx *middleware.Context) {
|
|||
// Check auto-login.
|
||||
uname := ctx.GetCookie(setting.CookieUserName)
|
||||
if len(uname) == 0 {
|
||||
ctx.HTML(200, "user/signin")
|
||||
ctx.HTML(200, SIGNIN)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -57,7 +66,7 @@ func SignIn(ctx *middleware.Context) {
|
|||
secret := base.EncodeMd5(user.Rands + user.Passwd)
|
||||
value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName)
|
||||
if value != user.Name {
|
||||
ctx.HTML(200, "user/signin")
|
||||
ctx.HTML(200, SIGNIN)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -86,7 +95,7 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) {
|
|||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "user/signin")
|
||||
ctx.HTML(200, SIGNIN)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -94,7 +103,7 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) {
|
|||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
log.Trace("%s Log in failed: %s", ctx.Req.RequestURI, form.UserName)
|
||||
ctx.RenderWithErr("Username or password is not correct", "user/signin", &form)
|
||||
ctx.RenderWithErr("Username or password is not correct", SIGNIN, &form)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -151,7 +160,7 @@ func SignUp(ctx *middleware.Context) {
|
|||
|
||||
if setting.Service.DisableRegistration {
|
||||
ctx.Data["DisableRegistration"] = true
|
||||
ctx.HTML(200, "user/signup")
|
||||
ctx.HTML(200, SIGNUP)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -160,7 +169,7 @@ func SignUp(ctx *middleware.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, "user/signup")
|
||||
ctx.HTML(200, SIGNUP)
|
||||
}
|
||||
|
||||
func oauthSignUp(ctx *middleware.Context, sid int64) {
|
||||
|
@ -180,7 +189,7 @@ func oauthSignUp(ctx *middleware.Context, sid int64) {
|
|||
ctx.Data["username"] = strings.Replace(ctx.Session.Get("socialName").(string), " ", "", -1)
|
||||
ctx.Data["email"] = ctx.Session.Get("socialEmail")
|
||||
log.Trace("user.oauthSignUp(social ID): %v", ctx.Session.Get("socialId"))
|
||||
ctx.HTML(200, "user/signup")
|
||||
ctx.HTML(200, SIGNUP)
|
||||
}
|
||||
|
||||
func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) {
|
||||
|
@ -198,14 +207,14 @@ func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) {
|
|||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, "user/signup")
|
||||
ctx.HTML(200, SIGNUP)
|
||||
return
|
||||
}
|
||||
|
||||
if form.Password != form.RetypePasswd {
|
||||
ctx.Data["Err_Password"] = true
|
||||
ctx.Data["Err_RetypePasswd"] = true
|
||||
ctx.RenderWithErr("Password and re-type password are not same.", "user/signup", &form)
|
||||
ctx.RenderWithErr("Password and re-type password are not same.", SIGNUP, &form)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -217,22 +226,23 @@ func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) {
|
|||
}
|
||||
|
||||
var err error
|
||||
if u, err = models.RegisterUser(u); err != nil {
|
||||
if u, err = models.CreateUser(u); err != nil {
|
||||
switch err {
|
||||
case models.ErrUserAlreadyExist:
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErr("Username has been already taken", "user/signup", &form)
|
||||
ctx.RenderWithErr("Username has been already taken", SIGNUP, &form)
|
||||
case models.ErrEmailAlreadyUsed:
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErr("E-mail address has been already used", "user/signup", &form)
|
||||
ctx.RenderWithErr("E-mail address has been already used", SIGNUP, &form)
|
||||
case models.ErrUserNameIllegal:
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "user/signup", &form)
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), SIGNUP, &form)
|
||||
default:
|
||||
ctx.Handle(500, "user.SignUpPost(RegisterUser)", err)
|
||||
ctx.Handle(500, "user.SignUpPost(CreateUser)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Trace("%s User created: %s", ctx.Req.RequestURI, form.UserName)
|
||||
log.Trace("%s User created: %s", ctx.Req.RequestURI, u.Name)
|
||||
|
||||
// Bind social account.
|
||||
if isOauth {
|
||||
|
@ -265,7 +275,7 @@ func Delete(ctx *middleware.Context) {
|
|||
ctx.Data["Title"] = "Delete Account"
|
||||
ctx.Data["PageIsUserSetting"] = true
|
||||
ctx.Data["IsUserPageSettingDelete"] = true
|
||||
ctx.HTML(200, "user/delete")
|
||||
ctx.HTML(200, DELETE)
|
||||
}
|
||||
|
||||
func DeletePost(ctx *middleware.Context) {
|
||||
|
@ -286,7 +296,7 @@ func DeletePost(ctx *middleware.Context) {
|
|||
case models.ErrUserOwnRepos:
|
||||
ctx.Flash.Error("Your account still have ownership of repository, you have to delete or transfer them first.")
|
||||
default:
|
||||
ctx.Handle(500, "user.Delete", err)
|
||||
ctx.Handle(500, "user.Delete(DeleteUser)", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
@ -321,7 +331,7 @@ func Activate(ctx *middleware.Context) {
|
|||
} else {
|
||||
ctx.Data["ServiceNotEnabled"] = true
|
||||
}
|
||||
ctx.HTML(200, "user/activate")
|
||||
ctx.HTML(200, ACTIVATE)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -343,7 +353,7 @@ func Activate(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
ctx.Data["IsActivateFailed"] = true
|
||||
ctx.HTML(200, "user/activate")
|
||||
ctx.HTML(200, ACTIVATE)
|
||||
}
|
||||
|
||||
func ForgotPasswd(ctx *middleware.Context) {
|
||||
|
@ -351,12 +361,12 @@ func ForgotPasswd(ctx *middleware.Context) {
|
|||
|
||||
if setting.MailService == nil {
|
||||
ctx.Data["IsResetDisable"] = true
|
||||
ctx.HTML(200, "user/forgot_passwd")
|
||||
ctx.HTML(200, FORGOT_PASSWORD)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["IsResetRequest"] = true
|
||||
ctx.HTML(200, "user/forgot_passwd")
|
||||
ctx.HTML(200, FORGOT_PASSWORD)
|
||||
}
|
||||
|
||||
func ForgotPasswdPost(ctx *middleware.Context) {
|
||||
|
@ -381,7 +391,7 @@ func ForgotPasswdPost(ctx *middleware.Context) {
|
|||
|
||||
if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) {
|
||||
ctx.Data["ResendLimited"] = true
|
||||
ctx.HTML(200, "user/forgot_passwd")
|
||||
ctx.HTML(200, FORGOT_PASSWORD)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -393,7 +403,7 @@ func ForgotPasswdPost(ctx *middleware.Context) {
|
|||
ctx.Data["Email"] = email
|
||||
ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
|
||||
ctx.Data["IsResetSent"] = true
|
||||
ctx.HTML(200, "user/forgot_passwd")
|
||||
ctx.HTML(200, FORGOT_PASSWORD)
|
||||
}
|
||||
|
||||
func ResetPasswd(ctx *middleware.Context) {
|
||||
|
@ -406,7 +416,7 @@ func ResetPasswd(ctx *middleware.Context) {
|
|||
}
|
||||
ctx.Data["Code"] = code
|
||||
ctx.Data["IsResetForm"] = true
|
||||
ctx.HTML(200, "user/reset_passwd")
|
||||
ctx.HTML(200, RESET_PASSWORD)
|
||||
}
|
||||
|
||||
func ResetPasswdPost(ctx *middleware.Context) {
|
||||
|
@ -443,5 +453,5 @@ func ResetPasswdPost(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
ctx.Data["IsResetFailed"] = true
|
||||
ctx.HTML(200, "user/reset_passwd")
|
||||
ctx.HTML(200, RESET_PASSWORD)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue