summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gogs.go2
-rw-r--r--models/repo.go4
-rw-r--r--models/user.go17
-rw-r--r--modules/auth/user.go2
-rw-r--r--routers/repo/repo.go54
-rw-r--r--routers/user/ssh.go39
-rw-r--r--routers/user/user.go34
-rw-r--r--templates/base/error.tmpl3
-rw-r--r--templates/base/navbar.tmpl4
-rw-r--r--templates/repo/create.tmpl6
-rw-r--r--web.go14
11 files changed, 96 insertions, 83 deletions
diff --git a/gogs.go b/gogs.go
index e239737e23..7bbcd803e5 100644
--- a/gogs.go
+++ b/gogs.go
@@ -19,7 +19,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.1.0307"
+const APP_VER = "0.0.2.0307"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
diff --git a/models/repo.go b/models/repo.go
index 6fc590566e..04e8c75c1b 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -48,9 +48,7 @@ func IsRepositoryExist(user *User, reposName string) (bool, error) {
return s.IsDir(), nil
}
-//
-// create a repository for a user or orgnaziation
-//
+// CreateRepository creates a repository for given user or orgnaziation.
func CreateRepository(user *User, reposName string) (*Repo, error) {
f := RepoPath(user.Name, reposName)
_, err := git.InitRepository(f, true)
diff --git a/models/user.go b/models/user.go
index a1ec293a71..36cdfc8a43 100644
--- a/models/user.go
+++ b/models/user.go
@@ -190,6 +190,23 @@ func GetUserById(id int64) (*User, error) {
return user, nil
}
+func GetUserByName(name string) (*User, error) {
+ if len(name) == 0 {
+ return nil, ErrUserNotExist
+ }
+ user := &User{
+ LowerName: strings.ToLower(name),
+ }
+ has, err := orm.Get(user)
+ if err != nil {
+ return nil, err
+ }
+ if !has {
+ return nil, ErrUserNotExist
+ }
+ return user, nil
+}
+
// LoginUserPlain validates user by raw user name and password.
func LoginUserPlain(name, passwd string) (*User, error) {
user := User{LowerName: strings.ToLower(name), Passwd: passwd}
diff --git a/modules/auth/user.go b/modules/auth/user.go
index 3a793f453d..e25593b737 100644
--- a/modules/auth/user.go
+++ b/modules/auth/user.go
@@ -69,7 +69,7 @@ func SignInRequire(redirect bool) martini.Handler {
data["IsSigned"] = true
data["SignedUserId"] = SignedInId(session)
data["SignedUserName"] = SignedInName(session)
- data["Avatar"] = SignedInUser(session).Avatar
+ data["SignedAvatar"] = SignedInUser(session).Avatar
}
}
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)
}
diff --git a/templates/base/error.tmpl b/templates/base/error.tmpl
index fbd424bff1..8f64494201 100644
--- a/templates/base/error.tmpl
+++ b/templates/base/error.tmpl
@@ -1,6 +1,7 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="gogs-body" class="container">
- An error is occurred : {{.ErrorMsg}}
+ <p>An error is occurred : {{.ErrorMsg}}</p>
+ <p>Application Version: {{AppVer}}</p>
</div>
{{template "base/footer" .}} \ No newline at end of file
diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl
index 565fb30c82..12434dad22 100644
--- a/templates/base/navbar.tmpl
+++ b/templates/base/navbar.tmpl
@@ -6,8 +6,8 @@
<a class="gogs-nav-item" href="#">Explore</a>
<a class="gogs-nav-item" href="#">Help</a>{{if .IsSigned}}
<a id="gogs-nav-out" class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/user/logout/"><i class="fa fa-power-off fa-lg"></i></a>
- <a id="gogs-nav-avatar" class="gogs-nav-item navbar-right" href="/user/profile" data-toggle="tooltip" data-placement="bottom" title="{{.SignedUserName}}">
- <img src="http://1.gravatar.com/avatar/{{.Avatar}}?s=28" alt="user-avatar" title="username"/>
+ <a id="gogs-nav-avatar" class="gogs-nav-item navbar-right" href="/user/{{.SignedUserName}}" data-toggle="tooltip" data-placement="bottom" title="{{.SignedUserName}}">
+ <img src="http://1.gravatar.com/avatar/{{.SignedAvatar}}?s=28" alt="user-avatar" title="username"/>
</a>
<a class="navbar-right gogs-nav-item" href="/repo/create" data-toggle="tooltip" data-placement="bottom" title="New Repository"><i class="fa fa-plus fa-lg"></i></a>
<a class="navbar-right gogs-nav-item" href="/user/publickey/list" data-toggle="tooltip" data-placement="bottom" title="Setting"><i class="fa fa-cogs fa-lg"></i></a>
diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl
index ffcffb09e3..4c7f4dd272 100644
--- a/templates/repo/create.tmpl
+++ b/templates/repo/create.tmpl
@@ -6,15 +6,15 @@
<div class="form-group">
<label class="col-md-2 control-label">Owner<strong class="text-danger">*</strong></label>
<div class="col-md-8">
- <p class="form-control-static">{{.UserName}}</p>
- <input type="hidden" value="{{.UserId}}" name="userId"/>
+ <p class="form-control-static">{{.SignedUserName}}</p>
+ <input type="hidden" value="{{.SignedUserId}}" name="userId"/>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Repository<strong class="text-danger">*</strong></label>
<div class="col-md-8">
- <input name="repo" type="text" class="form-control" placeholder="Type your repository name">
+ <input name="repo" type="text" class="form-control" placeholder="Type your repository name" required="required">
<span class="help-block">Great repository names are short and memorable. </span>
</div>
</div>
diff --git a/web.go b/web.go
index b047466991..fa889ba1aa 100644
--- a/web.go
+++ b/web.go
@@ -41,6 +41,9 @@ var AppHelpers template.FuncMap = map[string]interface{}{
"AppName": func() string {
return utils.Cfg.MustValue("", "APP_NAME")
},
+ "AppVer": func() string {
+ return APP_VER
+ },
}
func runWeb(*cli.Context) {
@@ -48,7 +51,7 @@ func runWeb(*cli.Context) {
m := martini.Classic()
- // Middleware.
+ // Middlewares.
m.Use(render.Renderer(render.Options{Funcs: []template.FuncMap{AppHelpers}}))
m.Use(base.InitContext())
@@ -61,14 +64,15 @@ func runWeb(*cli.Context) {
m.Any("/user/login", auth.SignOutRequire(), binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
m.Any("/user/logout", auth.SignInRequire(true), user.SignOut)
m.Any("/user/sign_up", auth.SignOutRequire(), binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
- m.Get("/user/profile", user.Profile) // should be /username
m.Any("/user/delete", auth.SignInRequire(true), user.Delete)
- m.Any("/user/publickey/add", user.AddPublicKey)
- m.Any("/user/publickey/list", user.ListPublicKey)
+ m.Get("/user/:username", auth.SignInRequire(false), user.Profile)
+
+ m.Any("/user/publickey/add", auth.SignInRequire(true), user.AddPublicKey)
+ m.Any("/user/publickey/list", auth.SignInRequire(true), user.ListPublicKey)
m.Any("/repo/create", auth.SignInRequire(true), repo.Create)
m.Any("/repo/delete", auth.SignInRequire(true), repo.Delete)
- m.Any("/repo/list", repo.List)
+ m.Any("/repo/list", auth.SignInRequire(false), repo.List)
listenAddr := fmt.Sprintf("%s:%s",
utils.Cfg.MustValue("server", "HTTP_ADDR"),