summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorlunnyxiao <xiaolunwen@gmail.com>2014-08-08 13:51:43 +0800
committerlunnyxiao <xiaolunwen@gmail.com>2014-08-08 13:51:43 +0800
commit7c7014262bdf90880826e6e6cc802bdab300b5ae (patch)
treea3b9803b8cb8ecc23517e73c1d0cdf73dcb213d5 /routers
parent57f6ec672ab059c57689a45c7f657923718e62bf (diff)
parent9d5c0c80a4984acc1a42da8360a712e4f5f615a0 (diff)
downloadgitea-7c7014262bdf90880826e6e6cc802bdab300b5ae.tar.gz
gitea-7c7014262bdf90880826e6e6cc802bdab300b5ae.zip
Merge branch 'dev' of github.com:gogits/gogs into dev
Diffstat (limited to 'routers')
-rw-r--r--routers/dev/debug.go18
-rw-r--r--routers/home.go5
-rw-r--r--routers/repo/setting.go63
-rw-r--r--routers/user/auth.go110
-rw-r--r--routers/user/home.go17
5 files changed, 126 insertions, 87 deletions
diff --git a/routers/dev/debug.go b/routers/dev/debug.go
deleted file mode 100644
index 6ef40a6226..0000000000
--- a/routers/dev/debug.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// 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 dev
-
-import (
- "net/http/pprof"
-
- "github.com/Unknwon/macaron"
-)
-
-func RegisterDebugRoutes(r *macaron.Macaron) {
- r.Any("/debug/pprof/cmdline", pprof.Cmdline)
- r.Any("/debug/pprof/profile", pprof.Profile)
- r.Any("/debug/pprof/symbol", pprof.Symbol)
- r.Any("/debug/pprof/**", pprof.Index)
-}
diff --git a/routers/home.go b/routers/home.go
index 770aca034b..4f7abea7a3 100644
--- a/routers/home.go
+++ b/routers/home.go
@@ -28,6 +28,11 @@ func Home(ctx *middleware.Context) {
return
}
+ if setting.OauthService != nil {
+ ctx.Data["OauthEnabled"] = true
+ ctx.Data["OauthService"] = setting.OauthService
+ }
+
ctx.Data["PageIsHome"] = true
ctx.HTML(200, HOME)
}
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index 3dc3bc5687..484cefb621 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -22,7 +22,7 @@ import (
const (
SETTINGS_OPTIONS base.TplName = "repo/settings/options"
- COLLABORATION base.TplName = "repo/collaboration"
+ COLLABORATION base.TplName = "repo/settings/collaboration"
HOOKS base.TplName = "repo/hooks"
HOOK_ADD base.TplName = "repo/hook_add"
@@ -134,26 +134,71 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
}
}
-func Collaboration(ctx *middleware.Context) {
+func SettingsCollaboration(ctx *middleware.Context) {
+ ctx.Data["Title"] = ctx.Tr("repo.settings")
+ ctx.Data["PageIsSettingsCollaboration"] = true
+
repoLink := strings.TrimPrefix(ctx.Repo.RepoLink, "/")
- ctx.Data["IsRepoToolbarCollaboration"] = true
- ctx.Data["Title"] = repoLink + " - collaboration"
+
+ if ctx.Req.Method == "POST" {
+ name := strings.ToLower(ctx.Query("collaborator"))
+ if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
+ ctx.Redirect(ctx.Req.URL.Path)
+ return
+ }
+ has, err := models.HasAccess(name, repoLink, models.WRITABLE)
+ if err != nil {
+ ctx.Handle(500, "HasAccess", err)
+ return
+ } else if has {
+ ctx.Redirect(ctx.Req.URL.Path)
+ return
+ }
+
+ u, err := models.GetUserByName(name)
+ if err != nil {
+ if err == models.ErrUserNotExist {
+ ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
+ ctx.Redirect(ctx.Req.URL.Path)
+ } else {
+ ctx.Handle(500, "GetUserByName", err)
+ }
+ return
+ }
+
+ if err = models.AddAccess(&models.Access{UserName: name, RepoName: repoLink,
+ Mode: models.WRITABLE}); err != nil {
+ ctx.Handle(500, "AddAccess2", err)
+ return
+ }
+
+ if setting.Service.EnableNotifyMail {
+ if err = mailer.SendCollaboratorMail(ctx.Render, u, ctx.User, ctx.Repo.Repository); err != nil {
+ ctx.Handle(500, "SendCollaboratorMail", err)
+ return
+ }
+ }
+
+ ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success"))
+ ctx.Redirect(ctx.Req.URL.Path)
+ return
+ }
// Delete collaborator.
remove := strings.ToLower(ctx.Query("remove"))
if len(remove) > 0 && remove != ctx.Repo.Owner.LowerName {
if err := models.DeleteAccess(&models.Access{UserName: remove, RepoName: repoLink}); err != nil {
- ctx.Handle(500, "setting.Collaboration(DeleteAccess)", err)
+ ctx.Handle(500, "DeleteAccess", err)
return
}
- ctx.Flash.Success("Collaborator has been removed.")
+ ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
return
}
names, err := models.GetCollaboratorNames(repoLink)
if err != nil {
- ctx.Handle(500, "setting.Collaboration(GetCollaborators)", err)
+ ctx.Handle(500, "GetCollaborators", err)
return
}
@@ -161,7 +206,7 @@ func Collaboration(ctx *middleware.Context) {
for i, name := range names {
us[i], err = models.GetUserByName(name)
if err != nil {
- ctx.Handle(500, "setting.Collaboration(GetUserByName)", err)
+ ctx.Handle(500, "GetUserByName", err)
return
}
}
@@ -170,7 +215,7 @@ func Collaboration(ctx *middleware.Context) {
ctx.HTML(200, COLLABORATION)
}
-func CollaborationPost(ctx *middleware.Context) {
+func SettingsCollaborationPost(ctx *middleware.Context) {
repoLink := strings.TrimPrefix(ctx.Repo.RepoLink, "/")
name := strings.ToLower(ctx.Query("collaborator"))
if len(name) == 0 || ctx.Repo.Owner.LowerName == name {
diff --git a/routers/user/auth.go b/routers/user/auth.go
index 90194e0c46..710d048f39 100644
--- a/routers/user/auth.go
+++ b/routers/user/auth.go
@@ -31,16 +31,16 @@ const (
func SignIn(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("sign_in")
- // if _, ok := ctx.Session.Get("socialId").(int64); ok {
- // ctx.Data["IsSocialLogin"] = true
- // ctx.HTML(200, SIGNIN)
- // return
- // }
+ if _, ok := ctx.Session.Get("socialId").(int64); ok {
+ ctx.Data["IsSocialLogin"] = true
+ ctx.HTML(200, SIGNIN)
+ return
+ }
- // if setting.OauthService != nil {
- // ctx.Data["OauthEnabled"] = true
- // ctx.Data["OauthService"] = setting.OauthService
- // }
+ if setting.OauthService != nil {
+ ctx.Data["OauthEnabled"] = true
+ ctx.Data["OauthService"] = setting.OauthService
+ }
// Check auto-login.
uname := ctx.GetCookie(setting.CookieUserName)
@@ -89,13 +89,13 @@ func SignIn(ctx *middleware.Context) {
func SignInPost(ctx *middleware.Context, form auth.SignInForm) {
ctx.Data["Title"] = ctx.Tr("sign_in")
- // sid, isOauth := ctx.Session.Get("socialId").(int64)
- // if isOauth {
- // ctx.Data["IsSocialLogin"] = true
- // } else if setting.OauthService != nil {
- // ctx.Data["OauthEnabled"] = true
- // ctx.Data["OauthService"] = setting.OauthService
- // }
+ sid, isOauth := ctx.Session.Get("socialId").(int64)
+ if isOauth {
+ ctx.Data["IsSocialLogin"] = true
+ } else if setting.OauthService != nil {
+ ctx.Data["OauthEnabled"] = true
+ ctx.Data["OauthService"] = setting.OauthService
+ }
if ctx.HasError() {
ctx.HTML(200, SIGNIN)
@@ -121,18 +121,18 @@ func SignInPost(ctx *middleware.Context, form auth.SignInForm) {
}
// Bind with social account.
- // if isOauth {
- // if err = models.BindUserOauth2(user.Id, sid); err != nil {
- // if err == models.ErrOauth2RecordNotExist {
- // ctx.Handle(404, "user.SignInPost(GetOauth2ById)", err)
- // } else {
- // ctx.Handle(500, "user.SignInPost(GetOauth2ById)", err)
- // }
- // return
- // }
- // ctx.Session.Delete("socialId")
- // log.Trace("%s OAuth binded: %s -> %d", ctx.Req.RequestURI, form.UserName, sid)
- // }
+ if isOauth {
+ if err = models.BindUserOauth2(u.Id, sid); err != nil {
+ if err == models.ErrOauth2RecordNotExist {
+ ctx.Handle(404, "GetOauth2ById", err)
+ } else {
+ ctx.Handle(500, "GetOauth2ById", err)
+ }
+ return
+ }
+ ctx.Session.Delete("socialId")
+ log.Trace("%s OAuth binded: %s -> %d", ctx.Req.RequestURI, form.UserName, sid)
+ }
ctx.Session.Set("uid", u.Id)
ctx.Session.Set("uname", u.Name)
@@ -148,14 +148,34 @@ func SignInPost(ctx *middleware.Context, form auth.SignInForm) {
func SignOut(ctx *middleware.Context) {
ctx.Session.Delete("uid")
ctx.Session.Delete("uname")
- // ctx.Session.Delete("socialId")
- // ctx.Session.Delete("socialName")
- // ctx.Session.Delete("socialEmail")
+ ctx.Session.Delete("socialId")
+ ctx.Session.Delete("socialName")
+ ctx.Session.Delete("socialEmail")
ctx.SetCookie(setting.CookieUserName, "", -1)
ctx.SetCookie(setting.CookieRememberName, "", -1)
ctx.Redirect("/")
}
+func oauthSignUp(ctx *middleware.Context, sid int64) {
+ // ctx.Data["Title"] = "OAuth Sign Up"
+ // ctx.Data["PageIsSignUp"] = true
+
+ // if _, err := models.GetOauth2ById(sid); err != nil {
+ // if err == models.ErrOauth2RecordNotExist {
+ // ctx.Handle(404, "user.oauthSignUp(GetOauth2ById)", err)
+ // } else {
+ // ctx.Handle(500, "user.oauthSignUp(GetOauth2ById)", err)
+ // }
+ // return
+ // }
+
+ // ctx.Data["IsSocialLogin"] = true
+ // 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, SIGNUP)
+}
+
func SignUp(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("sign_up")
@@ -165,34 +185,14 @@ func SignUp(ctx *middleware.Context) {
return
}
- // if sid, ok := ctx.Session.Get("socialId").(int64); ok {
- // oauthSignUp(ctx, sid)
- // return
- // }
+ if sid, ok := ctx.Session.Get("socialId").(int64); ok {
+ oauthSignUp(ctx, sid)
+ return
+ }
ctx.HTML(200, SIGNUP)
}
-// func oauthSignUp(ctx *middleware.Context, sid int64) {
-// ctx.Data["Title"] = "OAuth Sign Up"
-// ctx.Data["PageIsSignUp"] = true
-
-// if _, err := models.GetOauth2ById(sid); err != nil {
-// if err == models.ErrOauth2RecordNotExist {
-// ctx.Handle(404, "user.oauthSignUp(GetOauth2ById)", err)
-// } else {
-// ctx.Handle(500, "user.oauthSignUp(GetOauth2ById)", err)
-// }
-// return
-// }
-
-// ctx.Data["IsSocialLogin"] = true
-// 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, SIGNUP)
-// }
-
func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
ctx.Data["Title"] = ctx.Tr("sign_up")
diff --git a/routers/user/home.go b/routers/user/home.go
index 706c16d91f..177fa38be3 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -119,12 +119,19 @@ func Profile(ctx *middleware.Context) {
ctx.Data["Title"] = "Profile"
ctx.Data["PageIsUserProfile"] = true
- u, err := models.GetUserByName(ctx.Params(":username"))
+ uname := ctx.Params(":username")
+ // Special handle for FireFox requests favicon.ico.
+ if uname == "favicon.ico" {
+ ctx.Redirect("/img/favicon.png")
+ return
+ }
+
+ u, err := models.GetUserByName(uname)
if err != nil {
if err == models.ErrUserNotExist {
- ctx.Handle(404, "user.Profile(GetUserByName)", err)
+ ctx.Handle(404, "GetUserByName", err)
} else {
- ctx.Handle(500, "user.Profile(GetUserByName)", err)
+ ctx.Handle(500, "GetUserByName", err)
}
return
}
@@ -146,13 +153,13 @@ func Profile(ctx *middleware.Context) {
case "activity":
ctx.Data["Feeds"], err = models.GetFeeds(u.Id, 0, true)
if err != nil {
- ctx.Handle(500, "user.Profile(GetFeeds)", err)
+ ctx.Handle(500, "GetFeeds", err)
return
}
default:
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)
+ ctx.Handle(500, "GetRepositories", err)
return
}
}