Code convention

release/v1.15
Unknown 2014-05-24 15:28:31 -04:00
parent e33a104448
commit 80055bde86
11 changed files with 63 additions and 90 deletions

View File

@ -80,4 +80,4 @@ The [core team](http://gogs.io/team) of this project. See [contributors page](ht
## License
Gogs is under the MIT License. See the [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) file for the full license text.
This project is under the MIT License. See the [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) file for the full license text.

View File

@ -72,4 +72,4 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依
## 授权许可
Gogs 采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) 文件中。
本项目采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) 文件中。

View File

@ -752,14 +752,14 @@ func GetRepositoryById(id int64) (*Repository, error) {
}
// GetRepositories returns a list of repositories of given user.
func GetRepositories(user *User, private bool) ([]*Repository, error) {
func GetRepositories(uid int64, private bool) ([]*Repository, error) {
repos := make([]*Repository, 0, 10)
sess := orm.Desc("updated")
if !private {
sess.Where("is_private=?", false)
}
err := sess.Find(&repos, &Repository{OwnerId: user.Id})
err := sess.Find(&repos, &Repository{OwnerId: uid})
return repos, err
}

View File

@ -237,7 +237,7 @@ func ChangeUserName(user *User, newUserName string) (err error) {
}
}
repos, err := GetRepositories(user, true)
repos, err := GetRepositories(user.Id, true)
if err != nil {
return err
}

View File

@ -24,6 +24,8 @@ func Home(ctx *middleware.Context) {
return
}
ctx.Data["PageIsHome"] = true
// Show recent updated repositoires for new visiters.
repos, err := models.GetRecentUpdatedRepositories()
if err != nil {
@ -38,12 +40,11 @@ func Home(ctx *middleware.Context) {
}
}
ctx.Data["Repos"] = repos
ctx.Data["PageIsHome"] = true
ctx.HTML(200, "home")
}
func NotFound(ctx *middleware.Context) {
ctx.Data["PageIsNotFound"] = true
ctx.Data["Title"] = "Page Not Found"
ctx.Data["PageIsNotFound"] = true
ctx.Handle(404, "home.NotFound", nil)
}

View File

@ -20,26 +20,27 @@ import (
func Dashboard(ctx *middleware.Context) {
ctx.Data["Title"] = "Dashboard"
ctx.Data["PageIsUserDashboard"] = true
repos, err := models.GetRepositories(&models.User{Id: ctx.User.Id}, true)
var err error
ctx.Data["MyRepos"], err = models.GetRepositories(ctx.User.Id, true)
if err != nil {
ctx.Handle(500, "home.Dashboard(GetRepositories)", err)
return
}
ctx.Data["MyRepos"] = repos
collaRepos, err := models.GetCollaborativeRepos(ctx.User.Name)
ctx.Data["CollaborativeRepos"], err = models.GetCollaborativeRepos(ctx.User.Name)
if err != nil {
ctx.Handle(500, "home.Dashboard(GetCollaborativeRepos)", err)
return
}
ctx.Data["CollaborativeRepos"] = collaRepos
actions, err := models.GetFeeds(ctx.User.Id, 0, false)
if err != nil {
ctx.Handle(500, "home.Dashboard", err)
ctx.Handle(500, "home.Dashboard(GetFeeds)", err)
return
}
// Check access of private repositories.
feeds := make([]*models.Action, 0, len(actions))
for _, act := range actions {
if act.IsPrivate {
@ -50,47 +51,42 @@ func Dashboard(ctx *middleware.Context) {
}
feeds = append(feeds, act)
}
ctx.Data["Feeds"] = feeds
ctx.HTML(200, "user/dashboard")
}
func Profile(ctx *middleware.Context, params martini.Params) {
ctx.Data["Title"] = "Profile"
ctx.Data["PageIsUserProfile"] = true
user, err := models.GetUserByName(params["username"])
if err != nil {
if err == models.ErrUserNotExist {
ctx.Handle(404, "user.Profile", err)
ctx.Handle(404, "user.Profile(GetUserByName)", err)
} else {
ctx.Handle(500, "user.Profile", err)
ctx.Handle(500, "user.Profile(GetUserByName)", err)
}
return
}
ctx.Data["Owner"] = user
tab := ctx.Query("tab")
ctx.Data["TabName"] = tab
switch tab {
case "activity":
feeds, err := models.GetFeeds(user.Id, 0, true)
ctx.Data["Feeds"], err = models.GetFeeds(user.Id, 0, true)
if err != nil {
ctx.Handle(500, "user.Profile", err)
ctx.Handle(500, "user.Profile(GetFeeds)", err)
return
}
ctx.Data["Feeds"] = feeds
default:
repos, err := models.GetRepositories(user, ctx.IsSigned && ctx.User.Id == user.Id)
ctx.Data["Repos"], err = models.GetRepositories(user.Id, ctx.IsSigned && ctx.User.Id == user.Id)
if err != nil {
ctx.Handle(500, "user.Profile", err)
ctx.Handle(500, "user.Profile(GetRepositories)", err)
return
}
ctx.Data["Repos"] = repos
}
ctx.Data["PageIsUserProfile"] = true
ctx.HTML(200, "user/profile")
}
@ -98,13 +94,12 @@ func Email2User(ctx *middleware.Context) {
u, err := models.GetUserByEmail(ctx.Query("email"))
if err != nil {
if err == models.ErrUserNotExist {
ctx.Handle(404, "user.Email2User", err)
ctx.Handle(404, "user.Email2User(GetUserByEmail)", err)
} else {
ctx.Handle(500, "user.Email2User(GetUserByEmail)", err)
}
return
}
ctx.Redirect("/user/" + u.Name)
}
@ -145,36 +140,32 @@ func Issues(ctx *middleware.Context) {
isShowClosed := ctx.Query("state") == "closed"
var assigneeId, posterId int64
var filterMode int
switch viewType {
case "assigned":
assigneeId = ctx.User.Id
filterMode = models.FM_ASSIGN
case "created_by":
posterId = ctx.User.Id
filterMode = models.FM_CREATE
}
_, _ = assigneeId, posterId
rid, _ := base.StrTo(ctx.Query("repoid")).Int64()
repoId, _ := base.StrTo(ctx.Query("repoid")).Int64()
issueStats := models.GetUserIssueStats(ctx.User.Id, filterMode)
// Get all repositories.
repos, err := models.GetRepositories(ctx.User, true)
repos, err := models.GetRepositories(ctx.User.Id, true)
if err != nil {
ctx.Handle(500, "user.Issues(GetRepositories)", err)
return
}
rids := make([]int64, 0, len(repos))
repoIds := make([]int64, 0, len(repos))
showRepos := make([]*models.Repository, 0, len(repos))
for _, repo := range repos {
if repo.NumIssues == 0 {
continue
}
rids = append(rids, repo.Id)
repoIds = append(repoIds, repo.Id)
repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
issueStats.AllCount += int64(repo.NumOpenIssues)
@ -195,8 +186,8 @@ func Issues(ctx *middleware.Context) {
}
}
if rid > 0 {
rids = []int64{rid}
if repoId > 0 {
repoIds = []int64{repoId}
}
page, _ := base.StrTo(ctx.Query("page")).Int()
@ -207,9 +198,9 @@ func Issues(ctx *middleware.Context) {
case "assigned":
fallthrough
case "created_by":
ius, err = models.GetIssueUserPairsByMode(ctx.User.Id, rid, isShowClosed, page, filterMode)
ius, err = models.GetIssueUserPairsByMode(ctx.User.Id, repoId, isShowClosed, page, filterMode)
default:
ius, err = models.GetIssueUserPairsByRepoIds(rids, isShowClosed, page)
ius, err = models.GetIssueUserPairsByRepoIds(repoIds, isShowClosed, page)
}
if err != nil {
ctx.Handle(500, "user.Issues(GetAllIssueUserPairs)", err)
@ -251,7 +242,7 @@ func Issues(ctx *middleware.Context) {
}
}
ctx.Data["RepoId"] = rid
ctx.Data["RepoId"] = repoId
ctx.Data["Repos"] = showRepos
ctx.Data["Issues"] = issues
ctx.Data["ViewType"] = viewType
@ -263,7 +254,7 @@ func Issues(ctx *middleware.Context) {
} else {
ctx.Data["ShowCount"] = issueStats.OpenCount
}
ctx.HTML(200, "issue/user")
ctx.HTML(200, "user/issue")
}
func Pulls(ctx *middleware.Context) {

View File

@ -27,16 +27,15 @@ func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
ctx.Data["PageIsUserSetting"] = true
ctx.Data["IsUserPageSetting"] = true
user := ctx.User
ctx.Data["Owner"] = user
if ctx.HasError() {
ctx.HTML(200, "user/setting")
return
}
ctx.Data["Owner"] = ctx.User
// Check if user name has been changed.
if user.Name != form.UserName {
if ctx.User.Name != form.UserName {
isExist, err := models.IsUserExist(form.UserName)
if err != nil {
ctx.Handle(500, "user.Setting(update: check existence)", err)
@ -44,27 +43,26 @@ func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
} else if isExist {
ctx.RenderWithErr("User name has been taken.", "user/setting", &form)
return
} else if err = models.ChangeUserName(user, form.UserName); err != nil {
} else if err = models.ChangeUserName(ctx.User, form.UserName); err != nil {
ctx.Handle(500, "user.Setting(change user name)", err)
return
}
log.Trace("%s User name changed: %s -> %s", ctx.Req.RequestURI, user.Name, form.UserName)
log.Trace("%s User name changed: %s -> %s", ctx.Req.RequestURI, ctx.User.Name, form.UserName)
user.Name = form.UserName
ctx.User.Name = form.UserName
}
user.FullName = form.FullName
user.Email = form.Email
user.Website = form.Website
user.Location = form.Location
user.Avatar = base.EncodeMd5(form.Avatar)
user.AvatarEmail = form.Avatar
if err := models.UpdateUser(user); err != nil {
ctx.User.FullName = form.FullName
ctx.User.Email = form.Email
ctx.User.Website = form.Website
ctx.User.Location = form.Location
ctx.User.Avatar = base.EncodeMd5(form.Avatar)
ctx.User.AvatarEmail = form.Avatar
if err := models.UpdateUser(ctx.User); err != nil {
ctx.Handle(500, "setting.Setting", err)
return
}
log.Trace("%s User setting updated: %s", ctx.Req.RequestURI, ctx.User.LowerName)
ctx.Flash.Success("Your profile has been successfully updated.")
ctx.Redirect("/user/settings")
}
@ -86,13 +84,12 @@ func SettingSocial(ctx *middleware.Context) {
return
}
socials, err := models.GetOauthByUserId(ctx.User.Id)
var err error
ctx.Data["Socials"], err = models.GetOauthByUserId(ctx.User.Id)
if err != nil {
ctx.Handle(500, "user.SettingSocial(GetOauthByUserId)", err)
return
}
ctx.Data["Socials"] = socials
ctx.HTML(200, "user/social")
}
@ -113,28 +110,26 @@ func SettingPasswordPost(ctx *middleware.Context, form auth.UpdatePasswdForm) {
return
}
user := ctx.User
tmpUser := &models.User{
Passwd: form.OldPasswd,
Salt: user.Salt,
Salt: ctx.User.Salt,
}
tmpUser.EncodePasswd()
if user.Passwd != tmpUser.Passwd {
if ctx.User.Passwd != tmpUser.Passwd {
ctx.Flash.Error("Old password is not correct.")
} else if form.NewPasswd != form.RetypePasswd {
ctx.Flash.Error("New password and re-type password are not same.")
} else {
user.Passwd = form.NewPasswd
user.Salt = models.GetUserSalt()
user.EncodePasswd()
if err := models.UpdateUser(user); err != nil {
ctx.User.Passwd = form.NewPasswd
ctx.User.Salt = models.GetUserSalt()
ctx.User.EncodePasswd()
if err := models.UpdateUser(ctx.User); err != nil {
ctx.Handle(200, "setting.SettingPassword", err)
return
}
log.Trace("%s User password updated: %s", ctx.Req.RequestURI, ctx.User.LowerName)
ctx.Flash.Success("Password is changed successfully. You can now sign in via new password.")
}
ctx.Redirect("/user/settings/password")
}
@ -170,13 +165,13 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
return
}
var err error
// List existed SSH keys.
keys, err := models.ListPublicKey(ctx.User.Id)
ctx.Data["Keys"], err = models.ListPublicKey(ctx.User.Id)
if err != nil {
ctx.Handle(500, "ssh.ListPublicKey", err)
return
}
ctx.Data["Keys"] = keys
// Add new SSH key.
if ctx.Req.Method == "POST" {

View File

@ -25,11 +25,6 @@ func SignIn(ctx *middleware.Context) {
return
}
if base.OauthService != nil {
ctx.Data["OauthEnabled"] = true
ctx.Data["OauthService"] = base.OauthService
}
// Check auto-login.
userName := ctx.GetCookie(base.CookieUserName)
if len(userName) == 0 {
@ -37,6 +32,11 @@ func SignIn(ctx *middleware.Context) {
return
}
if base.OauthService != nil {
ctx.Data["OauthEnabled"] = true
ctx.Data["OauthService"] = base.OauthService
}
isSucceed := false
defer func() {
if !isSucceed {
@ -85,24 +85,11 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) {
}
if ctx.HasError() {
println("shit")
ctx.HTML(200, "user/signin")
return
}
var user *models.User
var err error
/*if base.Service.LdapAuth {
user, err = models.LoginUserLdap(form.UserName, form.Password)
if err != nil {
log.Error("Fail to login through LDAP: %v", err)
}
}
// try local if not LDAP or it's failed
if !base.Service.LdapAuth || err != nil {
user, err = models.LoginUserPlain(form.UserName, form.Password)
}*/
user, err = models.LoginUser(form.UserName, form.Password)
user, err := models.LoginUser(form.UserName, form.Password)
if err != nil {
if err == models.ErrUserNotExist {
log.Trace("%s Log in failed: %s", ctx.Req.RequestURI, form.UserName)
@ -192,7 +179,6 @@ func oauthSignUp(ctx *middleware.Context, sid int64) {
ctx.Data["username"] = strings.Replace(ctx.Session.Get("socialName").(string), " ", "", -1)
ctx.Data["email"] = ctx.Session.Get("socialEmail")
log.Trace("user.oauthSignUp(social ID): %v", ctx.Session.Get("socialId"))
ctx.HTML(200, "user/signup")
}

View File

@ -2,7 +2,7 @@
{{template "base/navbar" .}}
<div id="body" class="container" data-page="user">
{{template "user/setting_nav" .}}
<div id="repo-setting-container" class="col-md-10">
<div id="user-setting-container" class="col-md-10">
{{template "base/alert" .}}
<div class="panel panel-default">
<div class="panel-heading">

View File

@ -2,7 +2,7 @@
{{template "base/navbar" .}}
<div id="body" class="container" data-page="user">
{{template "user/setting_nav" .}}
<div id="repo-setting-container" class="col-md-10">
<div id="user-setting-container" class="col-md-10">
{{template "base/alert" .}}
<div class="panel panel-default">
<div class="panel-heading">