summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gogs.go2
-rw-r--r--modules/auth/form.go1
-rw-r--r--modules/auth/repo.go53
-rw-r--r--routers/repo/repo.go42
-rw-r--r--routers/user/user.go4
-rw-r--r--templates/repo/create.tmpl12
-rw-r--r--templates/repo/created.tmpl8
-rw-r--r--web.go2
8 files changed, 93 insertions, 31 deletions
diff --git a/gogs.go b/gogs.go
index 552a4db272..1e689e83b5 100644
--- a/gogs.go
+++ b/gogs.go
@@ -19,7 +19,7 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true
-const APP_VER = "0.0.2.0307"
+const APP_VER = "0.0.2.0308"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
diff --git a/modules/auth/form.go b/modules/auth/form.go
index a90f3d8542..b085527554 100644
--- a/modules/auth/form.go
+++ b/modules/auth/form.go
@@ -17,6 +17,7 @@ import (
"github.com/gogits/gogs/modules/log"
)
+// Web form interface.
type Form interface {
Name(field string) string
}
diff --git a/modules/auth/repo.go b/modules/auth/repo.go
new file mode 100644
index 0000000000..6656654f56
--- /dev/null
+++ b/modules/auth/repo.go
@@ -0,0 +1,53 @@
+// 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 auth
+
+import (
+ "net/http"
+ "reflect"
+
+ "github.com/codegangsta/martini"
+
+ "github.com/gogits/binding"
+
+ "github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/log"
+)
+
+type CreateRepoForm struct {
+ UserId int64 `form:"userId"`
+ RepoName string `form:"repo" binding:"Required"`
+ Visibility string `form:"visibility"`
+ Description string `form:"desc" binding:"MaxSize(100)"`
+ Language string `form:"language"`
+ InitReadme string `form:"initReadme"`
+}
+
+func (f *CreateRepoForm) Name(field string) string {
+ names := map[string]string{
+ "RepoName": "Repository name",
+ "Description": "Description",
+ }
+ return names[field]
+}
+
+func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
+ if req.Method == "GET" || errors.Count() == 0 {
+ return
+ }
+
+ data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
+ data["HasError"] = true
+ AssignForm(f, data)
+
+ if len(errors.Overall) > 0 {
+ for _, err := range errors.Overall {
+ log.Error("CreateRepoForm.Validate: %v", err)
+ }
+ return
+ }
+
+ validate(errors, data, f)
+}
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index e9ad7d1ab4..834195d83f 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -7,7 +7,6 @@ package repo
import (
"fmt"
"net/http"
- "strconv"
"github.com/martini-contrib/render"
"github.com/martini-contrib/sessions"
@@ -18,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/log"
)
-func Create(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
+func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
data["Title"] = "Create repository"
if req.Method == "GET" {
@@ -26,30 +25,37 @@ func Create(req *http.Request, r render.Render, data base.TmplData, session sess
return
}
+ if hasErr, ok := data["HasError"]; ok && hasErr.(bool) {
+ r.HTML(200, "repo/create", data)
+ return
+ }
+
// TODO: access check
- id, err := strconv.ParseInt(req.FormValue("userId"), 10, 64)
- if err == nil {
- var u *models.User
- u, err = models.GetUserById(id)
- if u == nil {
- err = models.ErrUserNotExist
- }
- if err == nil {
- _, err = models.CreateRepository(u, req.FormValue("name"))
+ user, err := models.GetUserById(form.UserId)
+ if err != nil {
+ if err.Error() == models.ErrUserNotExist.Error() {
+ data["HasError"] = true
+ data["ErrorMsg"] = "User does not exist"
+ auth.AssignForm(form, data)
+ r.HTML(200, "repo/create", data)
+ return
}
- if err == nil {
- data["RepoName"] = u.Name + "/" + req.FormValue("name")
+ }
+
+ if err == nil {
+ // TODO: init description and readme
+ if _, err = models.CreateRepository(user, form.RepoName); err == nil {
+ data["RepoName"] = user.Name + "/" + form.RepoName
r.HTML(200, "repo/created", data)
+ fmt.Println("good!!!!")
return
}
}
- if err != nil {
- data["ErrorMsg"] = err
- log.Error("repo.Create: %v", err)
- r.HTML(200, "base/error", data)
- }
+ data["ErrorMsg"] = err
+ log.Error("repo.Create: %v", err)
+ r.HTML(200, "base/error", data)
}
func Delete(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
diff --git a/routers/user/user.go b/routers/user/user.go
index a07d79e454..51a84400ab 100644
--- a/routers/user/user.go
+++ b/routers/user/user.go
@@ -64,8 +64,8 @@ func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render
}
data["ErrorMsg"] = err
- log.Error("user.SignIn: %v", data)
- r.HTML(200, "base/error", nil)
+ log.Error("user.SignIn: %v", err)
+ r.HTML(200, "base/error", data)
return
}
diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl
index 4c7f4dd272..e7a3633489 100644
--- a/templates/repo/create.tmpl
+++ b/templates/repo/create.tmpl
@@ -3,6 +3,7 @@
<div class="container" id="gogs-body">
<form action="/repo/create" method="post" class="form-horizontal gogs-card" id="gogs-repo-create">
<h3>Create New Repository</h3>
+ <div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div>
<div class="form-group">
<label class="col-md-2 control-label">Owner<strong class="text-danger">*</strong></label>
<div class="col-md-8">
@@ -11,10 +12,10 @@
</div>
</div>
- <div class="form-group">
+ <div class="form-group {{if .Err_RepoName}}has-error has-feedback{{end}}">
<label class="col-md-2 control-label">Repository<strong class="text-danger">*</strong></label>
<div class="col-md-8">
- <input name="repo" type="text" class="form-control" placeholder="Type your repository name" required="required">
+ <input name="repo" type="text" class="form-control" placeholder="Type your repository name" value="{{.repo}}" required="required">
<span class="help-block">Great repository names are short and memorable. </span>
</div>
</div>
@@ -23,13 +24,14 @@
<label class="col-md-2 control-label">Visibility<strong class="text-danger">*</strong></label>
<div class="col-md-8">
<p class="form-control-static">Public</p>
+ <input type="hidden" value="public" name="visibility"/>
</div>
</div>
- <div class="form-group">
+ <div class="form-group {{if .Err_Description}}has-error has-feedback{{end}}">
<label class="col-md-2 control-label">Description</label>
<div class="col-md-8">
- <textarea name="desc" class="form-control" placeholder="Type your repository name"></textarea>
+ <textarea name="desc" class="form-control" placeholder="Type your repository description">{{.desc}}</textarea>
</div>
</div>
@@ -51,7 +53,7 @@
<div class="col-md-8 col-md-offset-2">
<div class="checkbox">
<label>
- <input type="checkbox" value="true" name="init-md">
+ <input type="checkbox" value="" name="initReadme">
<strong>Initialize this repository with a README</strong>
</label>
</div>
diff --git a/templates/repo/created.tmpl b/templates/repo/created.tmpl
index aa47cb3fdc..35803e3938 100644
--- a/templates/repo/created.tmpl
+++ b/templates/repo/created.tmpl
@@ -1,8 +1,8 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
-<div class="container">
-<div class="col-md-offset-4 col-md-3">
- Created successfully!
- </div>
+<div class="container" id="gogs-body">
+ <div class="col-md-offset-4 col-md-3">
+ Created successfully!
+ </div>
</div>
{{template "base/footer" .}} \ No newline at end of file
diff --git a/web.go b/web.go
index 2b6041b123..1b61ca0e1b 100644
--- a/web.go
+++ b/web.go
@@ -69,7 +69,7 @@ func runWeb(*cli.Context) {
m.Any("/user/publickey/add", auth.SignInRequire(true), user.AddPublicKey)
m.Any("/user/publickey/list", auth.SignInRequire(true), user.ListPublicKey)
- m.Any("/repo/create", auth.SignInRequire(true), repo.Create)
+ m.Any("/repo/create", auth.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
m.Any("/repo/delete", auth.SignInRequire(true), repo.Delete)
m.Any("/repo/list", auth.SignInRequire(false), repo.List)