Add update user profile back end, add new gitignore and license, add template data to public profile page
This commit is contained in:
parent
adedd9181c
commit
57bc2d1ca0
|
@ -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 =
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
|
@ -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.
|
2
gogs.go
2
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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -49,6 +49,8 @@ type User struct {
|
|||
NumStars int
|
||||
NumRepos int
|
||||
Avatar string `xorm:"varchar(2048) not null"`
|
||||
Location string
|
||||
Website string
|
||||
Created time.Time `xorm:"created"`
|
||||
Updated time.Time `xorm:"updated"`
|
||||
}
|
||||
|
|
|
@ -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(") {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
2
web.go
2
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)
|
||||
|
|
Loading…
Reference in New Issue