summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/admin/user.go4
-rw-r--r--routers/install.go2
-rw-r--r--routers/org/org.go96
-rw-r--r--routers/repo/http.go8
-rw-r--r--routers/repo/setting.go4
-rw-r--r--routers/user/home.go13
-rw-r--r--routers/user/user.go7
7 files changed, 113 insertions, 21 deletions
diff --git a/routers/admin/user.go b/routers/admin/user.go
index d1bbb48068..cf99db2bf7 100644
--- a/routers/admin/user.go
+++ b/routers/admin/user.go
@@ -67,7 +67,7 @@ func NewUserPost(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.RenderWithErr("Username has been already taken", USER_NEW, &form)
@@ -76,7 +76,7 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) {
case models.ErrUserNameIllegal:
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), USER_NEW, &form)
default:
- ctx.Handle(500, "admin.user.NewUser(RegisterUser)", err)
+ ctx.Handle(500, "admin.user.NewUser(CreateUser)", err)
}
return
}
diff --git a/routers/install.go b/routers/install.go
index 6ce7c98026..bb3c16eae4 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -227,7 +227,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
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
diff --git a/routers/org/org.go b/routers/org/org.go
index ff97402ebc..0595a81b3d 100644
--- a/routers/org/org.go
+++ b/routers/org/org.go
@@ -1,33 +1,117 @@
+// 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"
)
func Organization(ctx *middleware.Context, params martini.Params) {
- ctx.Data["Title"] = "Organization "+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.Data["Title"] = "Organization " + params["org"] + " Members"
ctx.HTML(200, "org/members")
}
func Teams(ctx *middleware.Context, params martini.Params) {
- ctx.Data["Title"] = "Organization "+params["org"]+" Teams"
+ ctx.Data["Title"] = "Organization " + params["org"] + " Teams"
ctx.HTML(200, "org/teams")
}
func New(ctx *middleware.Context) {
- ctx.Data["Title"] = "Create an Organization"
- ctx.HTML(200, "org/new")
+ ctx.Data["Title"] = "Create An Organization"
+ ctx.HTML(200, NEW)
+}
+
+func NewPost(ctx *middleware.Context, form auth.CreateOrganizationForm) {
+ 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.HTML(200, "org/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 Setting(ctx *middleware.Context, param martini.Params) {
diff --git a/routers/repo/http.go b/routers/repo/http.go
index d2bff29973..981266d548 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -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
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index 6479cb3041..3d48e79c3d 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -175,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
@@ -196,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
}
diff --git a/routers/user/home.go b/routers/user/home.go
index 0f2cee2565..86907b5a90 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -20,7 +20,7 @@ import (
const (
DASHBOARD base.TplName = "user/dashboard"
PROFILE base.TplName = "user/profile"
- ISSUES base.TplName = "user/issue"
+ ISSUES base.TplName = "user/issues"
PULLS base.TplName = "user/pulls"
STARS base.TplName = "user/stars"
)
@@ -29,6 +29,13 @@ 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 {
@@ -53,7 +60,7 @@ 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
}
}
@@ -131,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
}
}
diff --git a/routers/user/user.go b/routers/user/user.go
index 8144730e09..a50f126c0c 100644
--- a/routers/user/user.go
+++ b/routers/user/user.go
@@ -226,7 +226,7 @@ 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
@@ -235,13 +235,14 @@ func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) {
ctx.Data["Err_Email"] = true
ctx.RenderWithErr("E-mail address has been already used", SIGNUP, &form)
case models.ErrUserNameIllegal:
+ 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 {