diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-07 17:08:21 -0500 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-07 17:08:21 -0500 |
commit | a2a59f8ad1192d3504abd50b2daf2ebfd97c86ca (patch) | |
tree | f18d38149410e483e5108da62512f32ca0c45a8a /routers | |
parent | ba5c7ea7719abbef792e8b9897dcfadf4d54bbab (diff) | |
download | gitea-a2a59f8ad1192d3504abd50b2daf2ebfd97c86ca.tar.gz gitea-a2a59f8ad1192d3504abd50b2daf2ebfd97c86ca.zip |
Change /user/profile URL to /user/:username
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/repo.go | 54 | ||||
-rw-r--r-- | routers/user/ssh.go | 39 | ||||
-rw-r--r-- | routers/user/user.go | 34 |
3 files changed, 60 insertions, 67 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index c34c33d74c..6ff949b90f 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -15,17 +15,14 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/utils/log" ) func Create(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { data["Title"] = "Create repository" if req.Method == "GET" { - r.HTML(200, "repo/create", map[string]interface{}{ - "UserName": auth.SignedInName(session), - "UserId": auth.SignedInId(session), - "IsSigned": auth.IsSignedIn(session), - }) + r.HTML(200, "repo/create", data) return } @@ -42,56 +39,49 @@ func Create(req *http.Request, r render.Render, data base.TmplData, session sess _, err = models.CreateRepository(u, req.FormValue("name")) } if err == nil { - r.HTML(200, "repo/created", map[string]interface{}{ - "RepoName": u.Name + "/" + req.FormValue("name"), - "IsSigned": auth.IsSignedIn(session), - }) + data["RepoName"] = u.Name + "/" + req.FormValue("name") + r.HTML(200, "repo/created", data) return } } if err != nil { - r.HTML(200, "base/error", map[string]interface{}{ - "Error": fmt.Sprintf("%v", err), - "IsSigned": auth.IsSignedIn(session), - }) + data["ErrorMsg"] = err + log.Error("repo.Create: %v", err) + r.HTML(200, "base/error", data) } } -func Delete(req *http.Request, r render.Render, session sessions.Session) { +func Delete(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { + data["Title"] = "Delete repository" + if req.Method == "GET" { - r.HTML(200, "repo/delete", map[string]interface{}{ - "Title": "Delete repository", - "IsSigned": auth.IsSignedIn(session), - }) + r.HTML(200, "repo/delete", data) return } u := &models.User{} err := models.DeleteRepository(u, "") if err != nil { - r.HTML(200, "base/error", map[string]interface{}{ - "Error": fmt.Sprintf("%v", err), - "IsSigned": auth.IsSignedIn(session), - }) + data["ErrorMsg"] = err + log.Error("repo.Delete: %v", err) + r.HTML(200, "base/error", data) } } -func List(req *http.Request, r render.Render, session sessions.Session) { +func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { + data["Title"] = "Repositories" + u := auth.SignedInUser(session) repos, err := models.GetRepositories(u) fmt.Println("repos", repos) if err != nil { - r.HTML(200, "base/error", map[string]interface{}{ - "Error": fmt.Sprintf("%v", err), - "IsSigned": auth.IsSignedIn(session), - }) + data["ErrorMsg"] = err + log.Error("repo.List: %v", err) + r.HTML(200, "base/error", data) return } - r.HTML(200, "repo/list", map[string]interface{}{ - "Title": "repositories", - "Repos": repos, - "IsSigned": auth.IsSignedIn(session), - }) + data["Repos"] = repos + r.HTML(200, "repo/list", data) } diff --git a/routers/user/ssh.go b/routers/user/ssh.go index c928407d4a..6589753529 100644 --- a/routers/user/ssh.go +++ b/routers/user/ssh.go @@ -5,7 +5,6 @@ package user import ( - "fmt" "net/http" "github.com/martini-contrib/render" @@ -13,14 +12,15 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/utils/log" ) -func AddPublicKey(req *http.Request, r render.Render, session sessions.Session) { +func AddPublicKey(req *http.Request, data base.TmplData, r render.Render, session sessions.Session) { + data["Title"] = "Add Public Key" + if req.Method == "GET" { - r.HTML(200, "user/publickey_add", map[string]interface{}{ - "Title": "Add Public Key", - "IsSigned": auth.IsSignedIn(session), - }) + r.HTML(200, "user/publickey_add", data) return } @@ -30,28 +30,25 @@ func AddPublicKey(req *http.Request, r render.Render, session sessions.Session) } err := models.AddPublicKey(k) if err != nil { - r.HTML(403, "status/403", map[string]interface{}{ - "Title": fmt.Sprintf("%v", err), - "IsSigned": auth.IsSignedIn(session), - }) + data["ErrorMsg"] = err + log.Error("ssh.AddPublicKey: %v", err) + r.HTML(200, "base/error", data) } else { - r.HTML(200, "user/publickey_added", map[string]interface{}{}) + r.HTML(200, "user/publickey_added", data) } } -func ListPublicKey(req *http.Request, r render.Render, session sessions.Session) { +func ListPublicKey(req *http.Request, data base.TmplData, r render.Render, session sessions.Session) { + data["Title"] = "Public Keys" + keys, err := models.ListPublicKey(auth.SignedInId(session)) if err != nil { - r.HTML(200, "base/error", map[string]interface{}{ - "Error": fmt.Sprintf("%v", err), - "IsSigned": auth.IsSignedIn(session), - }) + data["ErrorMsg"] = err + log.Error("ssh.ListPublicKey: %v", err) + r.HTML(200, "base/error", data) return } - r.HTML(200, "user/publickey_list", map[string]interface{}{ - "Title": "repositories", - "Keys": keys, - "IsSigned": auth.IsSignedIn(session), - }) + data["Keys"] = keys + r.HTML(200, "user/publickey_list", data) } diff --git a/routers/user/user.go b/routers/user/user.go index fae376dd28..7eac9b7429 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -5,9 +5,9 @@ package user import ( - "fmt" "net/http" + "github.com/codegangsta/martini" "github.com/martini-contrib/render" "github.com/martini-contrib/sessions" @@ -23,12 +23,18 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) { r.HTML(200, "user/dashboard", data) } -func Profile(r render.Render, data base.TmplData, session sessions.Session) { +func Profile(params martini.Params, r render.Render, data base.TmplData, session sessions.Session) { data["Title"] = "Profile" - data["IsSigned"] = auth.IsSignedIn(session) // TODO: Need to check view self or others. - user := auth.SignedInUser(session) + user, err := models.GetUserByName(params["username"]) + if err != nil { + data["ErrorMsg"] = err + log.Error("user.Profile: %v", err) + r.HTML(200, "base/error", data) + return + } + data["Avatar"] = user.Avatar data["Username"] = user.Name r.HTML(200, "user/profile", data) @@ -59,11 +65,10 @@ func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render data["ErrorMsg"] = err log.Error("user.SignIn: %v", data) - r.HTML(500, "base/error", nil) + r.HTML(200, "base/error", nil) return } - // login success session.Set("userId", user.Id) session.Set("userName", user.Name) r.Redirect("/") @@ -119,7 +124,7 @@ func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r ren default: data["ErrorMsg"] = err log.Error("user.SignUp: %v", data) - r.HTML(500, "base/error", nil) + r.HTML(200, "base/error", nil) } return } @@ -127,17 +132,18 @@ func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r ren r.Redirect("/user/login") } -func Delete(req *http.Request, r render.Render) { +// TODO: unfinished +func Delete(data base.TmplData, req *http.Request, r render.Render) { + data["Title"] = "Delete user" + if req.Method == "GET" { - r.HTML(200, "user/delete", map[string]interface{}{ - "Title": "Delete user", - }) + r.HTML(200, "user/delete", data) return } u := &models.User{} err := models.DeleteUser(u) - r.HTML(403, "status/403", map[string]interface{}{ - "Title": fmt.Sprintf("%v", err), - }) + data["ErrorMsg"] = err + log.Error("user.Delete: %v", data) + r.HTML(200, "base/error", nil) } |