diff --git a/conf/app.ini b/conf/app.ini index fcfbe9bc2..aa42129cc 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -3,8 +3,8 @@ RUN_USER = lunny [repository] ROOT = /Users/lunny/git/gogs-repositories -LANG_IGNS=Google Go -LICENSES=Apache v2 License +LANG_IGNS=Google Go|C +LICENSES=Apache v2 License|BSD (3-Clause) License [server] HTTP_ADDR = diff --git a/conf/gitignore/C b/conf/gitignore/C new file mode 100644 index 000000000..e7a909e4c --- /dev/null +++ b/conf/gitignore/C @@ -0,0 +1,18 @@ +# Object files +*.o +*.ko + +# Libraries +*.lib +*.a + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app \ No newline at end of file diff --git a/conf/license/BSD (3-Clause) License b/conf/license/BSD (3-Clause) License new file mode 100644 index 000000000..3af16b072 --- /dev/null +++ b/conf/license/BSD (3-Clause) License @@ -0,0 +1,27 @@ +Copyright (c) 2014 +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the {organization} nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/gogs.go b/gogs.go index f1a702ed2..96c0f84f2 100644 --- a/gogs.go +++ b/gogs.go @@ -20,7 +20,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.6.0313" +const APP_VER = "0.0.7.0313" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/repo.go b/models/repo.go index 6e45367c0..b7b5ac42b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -352,6 +352,10 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) { session.Rollback() return err } + if _, err := session.Delete(&Access{UserName: userName, RepoName: repo.Name}); err != nil { + session.Rollback() + return err + } if _, err = session.Exec("update user set num_repos = num_repos - 1 where id = ?", userId); err != nil { session.Rollback() return err diff --git a/models/user.go b/models/user.go index c59e4ae15..06db7d8ba 100644 --- a/models/user.go +++ b/models/user.go @@ -48,7 +48,9 @@ type User struct { NumFollowings int NumStars int NumRepos int - Avatar string `xorm:"varchar(2048) not null"` + Avatar string `xorm:"varchar(2048) not null"` + Location string + Website string Created time.Time `xorm:"created"` Updated time.Time `xorm:"updated"` } diff --git a/modules/auth/auth.go b/modules/auth/auth.go index e4748650c..b08552755 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -90,11 +90,6 @@ func (f *LogInForm) Validate(errors *binding.Errors, req *http.Request, context validate(errors, data, f) } -type FeedsForm struct { - UserId int64 `form:"userid" binding:"Required"` - Offset int64 `form:"offset"` -} - func getMinMaxSize(field reflect.StructField) string { for _, rule := range strings.Split(field.Tag.Get("binding"), ";") { if strings.HasPrefix(rule, "MinSize(") || strings.HasPrefix(rule, "MaxSize(") { diff --git a/modules/auth/user.go b/modules/auth/user.go index 4059edfdd..e868fac23 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -5,10 +5,15 @@ package auth import ( + "net/http" + "reflect" + "github.com/codegangsta/martini" "github.com/martini-contrib/render" "github.com/martini-contrib/sessions" + "github.com/gogits/binding" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" @@ -83,3 +88,43 @@ func SignOutRequire() martini.Handler { } } } + +type FeedsForm struct { + UserId int64 `form:"userid" binding:"Required"` + Offset int64 `form:"offset"` +} + +type UpdateProfileForm struct { + Email string `form:"email" binding:"Required;Email;MaxSize(50)"` + Website string `form:"website" binding:"AlphaDash;MaxSize(50)"` + Location string `form:"location" binding:"MaxSize(50)"` + Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"` +} + +func (f *UpdateProfileForm) Name(field string) string { + names := map[string]string{ + "Email": "Email address", + "Website": "Website", + "Location": "Location", + "Avatar": "Gravatar Email", + } + return names[field] +} + +func (f *UpdateProfileForm) 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 + + if len(errors.Overall) > 0 { + for _, err := range errors.Overall { + log.Error("UpdateProfileForm.Validate: %v", err) + } + return + } + + validate(errors, data, f) +} diff --git a/routers/repo/repo.go b/routers/repo/repo.go index a12b45d7b..e1809b4b7 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -46,7 +46,7 @@ func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data b if err == nil { if _, err = models.CreateRepository(user, form.RepoName, form.Description, form.Language, form.License, - form.Visibility == "private", form.InitReadme == "true"); err == nil { + form.Visibility == "private", form.InitReadme == "on"); err == nil { if err == nil { data["RepoName"] = user.Name + "/" + form.RepoName r.HTML(200, "repo/created", data) @@ -83,7 +83,7 @@ func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data b return } - r.Redirect("/", 200) + r.Redirect("/", 302) } func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { diff --git a/routers/user/setting.go b/routers/user/setting.go index 0669784be..63e4d8cb7 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -17,9 +17,31 @@ import ( "github.com/gogits/gogs/modules/log" ) -func Setting(r render.Render, data base.TmplData, session sessions.Session) { +func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) { data["Title"] = "Setting" data["PageIsUserSetting"] = true + + user := auth.SignedInUser(session) + if req.Method == "GET" { + data["Owner"] = user + } + + if hasErr, ok := data["HasError"]; ok && hasErr.(bool) { + r.HTML(200, "user/setting", data) + return + } + + user.Email = form.Email + user.Website = form.Website + user.Location = form.Location + user.Avatar = base.EncodeMd5(form.Avatar) + if err := models.UpdateUser(user); err != nil { + data["ErrorMsg"] = err + log.Error("setting.Setting: %v", err) + r.HTML(200, "base/error", data) + return + } + r.HTML(200, "user/setting", data) } diff --git a/routers/user/user.go b/routers/user/user.go index 59177a47b..2ce158b64 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -43,8 +43,7 @@ func Profile(params martini.Params, r render.Render, data base.TmplData, session return } - data["Avatar"] = user.Avatar - data["Username"] = user.Name + data["Owner"] = user r.HTML(200, "user/profile", data) } diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 79e6062bc..94ec33b69 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -4,16 +4,16 @@
- user-avatar + user-avatar - {{.Username}} + {{.Owner.Name}}
diff --git a/web.go b/web.go index 475b662b3..856d0f106 100644 --- a/web.go +++ b/web.go @@ -63,7 +63,7 @@ func runWeb(*cli.Context) { m.Any("/user/delete", auth.SignInRequire(true), user.Delete) m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) - m.Any("/user/setting", auth.SignInRequire(true), user.Setting) + m.Any("/user/setting", auth.SignInRequire(true), binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) m.Any("/user/setting/ssh", auth.SignInRequire(true), binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) m.Get("/user/:username", auth.SignInRequire(false), user.Profile)