aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-03-15 23:38:58 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-03-15 23:38:58 +0800
commitf047df6e2b69ecb41c3fe4bef746145916aa4063 (patch)
tree3dac61306b89a9040df6bad3afa2c98a9601fedb
parent6bdd6f9b18136a6066f3fc87349037027eb7a499 (diff)
parentb43cfc5b39c0aeec04b1810f01e57ece96abdd7e (diff)
Merge branch 'master' of github.com:gogits/gogs
-rw-r--r--README.md4
-rw-r--r--modules/middleware/context.go17
-rw-r--r--routers/repo/repo.go12
-rw-r--r--routers/repo/single.go1
-rw-r--r--routers/user/setting.go8
-rw-r--r--routers/user/user.go18
-rw-r--r--templates/user/dashboard.tmpl2
-rw-r--r--templates/user/profile.tmpl2
8 files changed, 31 insertions, 33 deletions
diff --git a/README.md b/README.md
index dd95e90d..526cc501 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,9 @@
Gogs - Go Git Service [![wercker status](https://app.wercker.com/status/ad0bdb0bc450ac6f09bc56b9640a50aa/s/ "wercker status")](https://app.wercker.com/project/bykey/ad0bdb0bc450ac6f09bc56b9640a50aa) [![Go Walker](http://gowalker.org/api/v1/badge)](https://gowalker.org/github.com/gogits/gogs)
=====================
-Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language, it currently supports Linux and Max OS X, but Windows has **NOT** supported yet due to installation problem with [libgit2](http://libgit2.github.com/) in Windows.
+Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language.
+
+Since we choose to use pure Go implmentation of Git manipulation, Gogs certainly supports **ALL platforms** that Go supports, including Linux, Max OS X, and Windows with **ZERO** dependency.
##### Current version: 0.0.8 Alpha
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 7a1dba3d..d3fe7bbf 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -41,6 +41,23 @@ func (ctx *Context) Query(name string) string {
// return ctx.p[name]
// }
+// HasError returns true if error occurs in form validation.
+func (ctx *Context) HasError() bool {
+ hasErr, ok := ctx.Data["HasError"]
+ if !ok {
+ return false
+ }
+ return hasErr.(bool)
+}
+
+// RenderWithErr used for page has form validation but need to prompt error to users.
+func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form) {
+ ctx.Data["HasError"] = true
+ ctx.Data["ErrorMsg"] = msg
+ auth.AssignForm(form, ctx.Data)
+ ctx.Render.HTML(200, tpl, ctx.Data)
+}
+
// Handle handles and logs error by given status.
func (ctx *Context) Handle(status int, title string, err error) {
ctx.Data["ErrorMsg"] = err
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 710e5a21..23f8ea10 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -20,7 +20,7 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
return
}
- if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) {
+ if ctx.HasError() {
ctx.Render.HTML(200, "repo/create", ctx.Data)
return
}
@@ -30,10 +30,7 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
user, err := models.GetUserById(form.UserId)
if err != nil {
if err.Error() == models.ErrUserNotExist.Error() {
- ctx.Data["HasError"] = true
- ctx.Data["ErrorMsg"] = "User does not exist"
- auth.AssignForm(form, ctx.Data)
- ctx.Render.HTML(200, "repo/create", ctx.Data)
+ ctx.RenderWithErr("User does not exist", "repo/create", &form)
return
}
}
@@ -48,10 +45,7 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
}
if err.Error() == models.ErrRepoAlreadyExist.Error() {
- ctx.Data["HasError"] = true
- ctx.Data["ErrorMsg"] = "Repository name has already been used"
- auth.AssignForm(form, ctx.Data)
- ctx.Render.HTML(200, "repo/create", ctx.Data)
+ ctx.RenderWithErr("Repository name has already been used", "repo/create", &form)
return
}
diff --git a/routers/repo/single.go b/routers/repo/single.go
index 036bc218..e9339510 100644
--- a/routers/repo/single.go
+++ b/routers/repo/single.go
@@ -52,6 +52,5 @@ func Setting(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Data["Title"].(string) + " - settings"
ctx.Data["IsRepoToolbarSetting"] = true
-
ctx.Render.HTML(200, "repo/setting", ctx.Data)
}
diff --git a/routers/user/setting.go b/routers/user/setting.go
index f38f2c14..cd12bb62 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -128,9 +128,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
}
if err := models.AddPublicKey(k); err != nil {
- ctx.Data["ErrorMsg"] = err
- log.Error("ssh.AddPublicKey: %v", err)
- ctx.Render.HTML(200, "base/error", ctx.Data)
+ ctx.Handle(200, "ssh.AddPublicKey", err)
return
} else {
ctx.Data["AddSSHKeySuccess"] = true
@@ -140,9 +138,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
// List existed SSH keys.
keys, err := models.ListPublicKey(ctx.User.Id)
if err != nil {
- ctx.Data["ErrorMsg"] = err
- log.Error("ssh.ListPublicKey: %v", err)
- ctx.Render.HTML(200, "base/error", ctx.Data)
+ ctx.Handle(200, "ssh.ListPublicKey", err)
return
}
diff --git a/routers/user/user.go b/routers/user/user.go
index 50b99183..4ba7da16 100644
--- a/routers/user/user.go
+++ b/routers/user/user.go
@@ -82,10 +82,7 @@ func SignIn(ctx *middleware.Context, form auth.LogInForm) {
user, err := models.LoginUserPlain(form.UserName, form.Password)
if err != nil {
if err.Error() == models.ErrUserNotExist.Error() {
- ctx.Data["HasError"] = true
- ctx.Data["ErrorMsg"] = "Username or password is not correct"
- auth.AssignForm(form, ctx.Data)
- ctx.Render.HTML(200, "user/signin", ctx.Data)
+ ctx.RenderWithErr("Username or password is not correct", "user/signin", &form)
return
}
@@ -121,7 +118,7 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) {
auth.AssignForm(form, ctx.Data)
}
- if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) {
+ if ctx.HasError() {
ctx.Render.HTML(200, "user/signup", ctx.Data)
return
}
@@ -133,18 +130,11 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) {
}
if err := models.RegisterUser(u); err != nil {
- ctx.Data["HasError"] = true
- auth.AssignForm(form, ctx.Data)
-
switch err.Error() {
case models.ErrUserAlreadyExist.Error():
- ctx.Data["Err_Username"] = true
- ctx.Data["ErrorMsg"] = "Username has been already taken"
- ctx.Render.HTML(200, "user/signup", ctx.Data)
+ ctx.RenderWithErr("Username has been already taken", "user/signup", &form)
case models.ErrEmailAlreadyUsed.Error():
- ctx.Data["Err_Email"] = true
- ctx.Data["ErrorMsg"] = "E-mail address has been already used"
- ctx.Render.HTML(200, "user/signup", ctx.Data)
+ ctx.RenderWithErr("E-mail address has been already used", "user/signup", &form)
default:
ctx.Handle(200, "user.SignUp", err)
}
diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl
index 14b34515..306c3bc1 100644
--- a/templates/user/dashboard.tmpl
+++ b/templates/user/dashboard.tmpl
@@ -22,7 +22,7 @@
<span class="clearfix"></span>
</li>
{{else}}
- <li>Not any activity yet.</li>
+ <li>No any activity yet.</li>
{{end}}
</ul>
</div>
diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl
index f2bb984b..94444520 100644
--- a/templates/user/profile.tmpl
+++ b/templates/user/profile.tmpl
@@ -39,7 +39,7 @@
<span class="clearfix"></span>
</li>
{{else}}
- <li>Not any public activity yet.</li>
+ <li>No any public activity yet.</li>
{{end}}
</ul>
</div>