]> source.dussan.org Git - gitea.git/commitdiff
Add update user profile back end, add new gitignore and license, add template data...
authorUnknown <joe2010xtmf@163.com>
Thu, 13 Mar 2014 07:39:18 +0000 (03:39 -0400)
committerUnknown <joe2010xtmf@163.com>
Thu, 13 Mar 2014 07:39:18 +0000 (03:39 -0400)
13 files changed:
conf/app.ini
conf/gitignore/C [new file with mode: 0644]
conf/license/BSD (3-Clause) License [new file with mode: 0644]
gogs.go
models/repo.go
models/user.go
modules/auth/auth.go
modules/auth/user.go
routers/repo/repo.go
routers/user/setting.go
routers/user/user.go
templates/user/profile.tmpl
web.go

index fcfbe9bc2d7af57d723981ff66e5a8beb4ee9f84..aa42129ccec90dae6353a9a38cbabc640dd06847 100644 (file)
@@ -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 (file)
index 0000000..e7a909e
--- /dev/null
@@ -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 (file)
index 0000000..3af16b0
--- /dev/null
@@ -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 f1a702ed2237f0cb43b0d821ef2c5d184f7a7480..96c0f84f2bbc5ef83989fd0d3658c970f4770fdd 100644 (file)
--- 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())
index 6e45367c09ac6e9dd83b44f76d056dd10cc4c379..b7b5ac42b02a2493a27261529e98fe8f368768c7 100644 (file)
@@ -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
index c59e4ae152a8a38893cd7257fe5371b9f581e596..06db7d8ba29d965bb0339c830b31756619a2d2f2 100644 (file)
@@ -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"`
 }
index e4748650c28803637b54125b845cc282c803be0c..b0855275549fc895f2b33b27009743966423d433 100644 (file)
@@ -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(") {
index 4059edfdd3fb7e042151d07381f02917f46acedd..e868fac23d68c547367a719d78a5f1fbc1e8a392 100644 (file)
@@ -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)
+}
index a12b45d7b978af54615e93e2345ac3b459c984d2..e1809b4b7e601c206193d087dcb1bb6ec9ddfaf1 100644 (file)
@@ -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) {
index 0669784be0a3fac51864c2024a7158ffe4c9f55c..63e4d8cb7d63f2d0e94030ee9ea1e5dc7079169d 100644 (file)
@@ -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)
 }
 
index 59177a47b9b67682a99f97a9ee1563acc1f66c19..2ce158b641ab552826415882d52c354dd5c3cc1e 100644 (file)
@@ -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)
 }
 
index 79e6062bcbeb3243513194ea8e6321a6b85692ad..94ec33b69619eb0d727cfc34d4ca37211e2e49ae 100644 (file)
@@ -4,16 +4,16 @@
     <div id="gogs-user-profile" class="col-md-3">
         <div class="profile-avatar text-center">
             <a href="#" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar">
-                <img id="gogs-user-avatar" src="http://1.gravatar.com/avatar/{{.Avatar}}?s=200" alt="user-avatar" title="username"/>
+                <img id="gogs-user-avatar" src="http://1.gravatar.com/avatar/{{.Owner.Avatar}}?s=200" alt="user-avatar" title="username"/>
             </a>
-            <span id="gogs-user-name" class="center-block" href="#">{{.Username}}</span>
+            <span id="gogs-user-name" class="center-block" href="#">{{.Owner.Name}}</span>
         </div>
         <div class="profile-info">
             <ul class="list-group">
-                <li class="list-group-item"><i class="fa fa-thumb-tack"></i>City, County, State, Nation</li>
-                <li class="list-group-item"><i class="fa fa-envelope"></i><a href="#">Email@EmailAddress.com</a></li>
-                <li class="list-group-item"><i class="fa fa-link"></i><a href="#">http://yousite/</a></li>
-                <li class="list-group-item"><i class="fa fa-clock-o"></i>Joined At 03.02, 2014</li>
+                <li class="list-group-item"><i class="fa fa-thumb-tack"></i>{{.Owner.Location}}</li>
+                <li class="list-group-item"><i class="fa fa-envelope"></i><a href="#">{{.Owner.Email}}</a></li>
+                <li class="list-group-item"><i class="fa fa-link"></i><a href="#">{{.Owner.Website}}</a></li>
+                <li class="list-group-item"><i class="fa fa-clock-o"></i>{{.Owner.Created}}</li>
             </ul>
         </div>
     </div>
diff --git a/web.go b/web.go
index 475b662b3907fd97f210b2db5c4eaa93533e9898..856d0f106d914332494bc399eaf438400c23101d 100644 (file)
--- 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)