summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-24 15:28:31 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-24 15:28:31 -0400
commit80055bde86c21f1245a7b45ba30406db7640fec0 (patch)
tree04a3da65727ad9ea31e3d39504a73b589c5386cf /routers
parente33a1044482f6f7e9e82c2b0f5523b1cfb5213a0 (diff)
downloadgitea-80055bde86c21f1245a7b45ba30406db7640fec0.tar.gz
gitea-80055bde86c21f1245a7b45ba30406db7640fec0.zip
Code convention
Diffstat (limited to 'routers')
-rw-r--r--routers/dashboard.go5
-rw-r--r--routers/user/home.go57
-rw-r--r--routers/user/setting.go51
-rw-r--r--routers/user/user.go26
4 files changed, 56 insertions, 83 deletions
diff --git a/routers/dashboard.go b/routers/dashboard.go
index 6387089e54..94324b1579 100644
--- a/routers/dashboard.go
+++ b/routers/dashboard.go
@@ -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)
}
diff --git a/routers/user/home.go b/routers/user/home.go
index 2a2401c58f..a9674ac242 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -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) {
diff --git a/routers/user/setting.go b/routers/user/setting.go
index b0944ece0d..1fae516a43 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -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" {
diff --git a/routers/user/user.go b/routers/user/user.go
index f9aba69a04..98480a41ce 100644
--- a/routers/user/user.go
+++ b/routers/user/user.go
@@ -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")
}