summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-11-23 02:33:47 -0500
committerUnknwon <joe2010xtmf@163.com>2014-11-23 02:33:47 -0500
commit1b66600bd0e9eaa52f2f14f58c9cdf504efadaf5 (patch)
tree1f86ffa41b0b64a6a4bb06dd150998e95d29dbff
parentdc53270da91c369cb00f992a600a1e014d555278 (diff)
downloadgitea-1b66600bd0e9eaa52f2f14f58c9cdf504efadaf5.tar.gz
gitea-1b66600bd0e9eaa52f2f14f58c9cdf504efadaf5.zip
Fix #652
-rw-r--r--.gopmfile4
-rw-r--r--models/publickey.go5
-rw-r--r--models/repo.go2
-rw-r--r--routers/user/home.go54
4 files changed, 36 insertions, 29 deletions
diff --git a/.gopmfile b/.gopmfile
index c9441c18e3..2f9ebb9620 100644
--- a/.gopmfile
+++ b/.gopmfile
@@ -8,7 +8,7 @@ github.com/Unknwon/cae = commit:2e70a1351b
github.com/Unknwon/com = commit:2cbcbc6916
github.com/Unknwon/goconfig = commit:0f8d8dc1c0
github.com/Unknwon/i18n = commit:aec5f77857
-github.com/Unknwon/macaron = commit:5c8d1b7642
+github.com/Unknwon/macaron =
github.com/codegangsta/cli = commit:7381bc4e62
github.com/go-sql-driver/mysql = commit:8111ee3ec3
github.com/go-xorm/core = commit:3e0fa232ab
@@ -20,7 +20,7 @@ github.com/macaron-contrib/binding = commit:0e23661e7d
github.com/macaron-contrib/cache = commit:0bb9e6c9ef
github.com/macaron-contrib/captcha = commit:3567dc48b8
github.com/macaron-contrib/csrf = commit:422b79675c
-github.com/macaron-contrib/i18n = commit:2246f45894
+github.com/macaron-contrib/i18n =
github.com/macaron-contrib/session = commit:f00d48fd4f
github.com/macaron-contrib/toolbox = commit:57127bcc89
github.com/mattn/go-sqlite3 = commit:a80c27ba33
diff --git a/models/publickey.go b/models/publickey.go
index 29c12c6e3b..ba15ca4553 100644
--- a/models/publickey.go
+++ b/models/publickey.go
@@ -89,6 +89,11 @@ type PublicKey struct {
HasUsed bool `xorm:"-"`
}
+// OmitEmail returns content of public key but without e-mail address.
+func (k *PublicKey) OmitEmail() string {
+ return strings.Join(strings.Split(k.Content, " ")[:2], " ")
+}
+
// GetAuthorizedString generates and returns formatted public key string for authorized_keys file.
func (key *PublicKey) GetAuthorizedString() string {
return fmt.Sprintf(_TPL_PUBLICK_KEY, appPath, key.Id, key.Content)
diff --git a/models/repo.go b/models/repo.go
index 937bd8c1b6..e4f470680f 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -243,7 +243,7 @@ func IsRepositoryExist(u *User, repoName string) (bool, error) {
var (
illegalEquals = []string{"debug", "raw", "install", "api", "avatar", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin", "new"}
- illegalSuffixs = []string{".git"}
+ illegalSuffixs = []string{".git", ".keys"}
)
// IsLegalName returns false if name contains illegal characters.
diff --git a/routers/user/home.go b/routers/user/home.go
index ea669959e4..83dcb975fe 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -5,7 +5,9 @@
package user
import (
+ "bytes"
"fmt"
+ "strings"
"github.com/Unknwon/com"
@@ -127,6 +129,20 @@ func Pulls(ctx *middleware.Context) {
ctx.HTML(200, PULLS)
}
+func ShowSSHKeys(ctx *middleware.Context, uid int64) {
+ keys, err := models.ListPublicKeys(uid)
+ if err != nil {
+ ctx.Handle(500, "ListPublicKeys", err)
+ return
+ }
+
+ var buf bytes.Buffer
+ for i := range keys {
+ buf.WriteString(keys[i].OmitEmail())
+ }
+ ctx.RenderData(200, buf.Bytes())
+}
+
func Profile(ctx *middleware.Context) {
ctx.Data["Title"] = "Profile"
ctx.Data["PageIsUserProfile"] = true
@@ -138,6 +154,12 @@ func Profile(ctx *middleware.Context) {
return
}
+ isShowKeys := false
+ if strings.HasSuffix(uname, ".keys") {
+ isShowKeys = true
+ uname = strings.TrimSuffix(uname, ".keys")
+ }
+
u, err := models.GetUserByName(uname)
if err != nil {
if err == models.ErrUserNotExist {
@@ -148,6 +170,12 @@ func Profile(ctx *middleware.Context) {
return
}
+ // Show SSH keys.
+ if isShowKeys {
+ ShowSSHKeys(ctx, u.Id)
+ return
+ }
+
if u.IsOrganization() {
ctx.Redirect(setting.AppSubUrl + "/org/" + u.Name)
return
@@ -204,32 +232,6 @@ func Email2User(ctx *middleware.Context) {
ctx.Redirect(setting.AppSubUrl + "/user/" + u.Name)
}
-const (
- TPL_FEED = `<i class="icon fa fa-%s"></i>
- <div class="info"><span class="meta">%s</span><br>%s</div>`
-)
-
-// func Feeds(ctx *middleware.Context, form auth.FeedsForm) {
-// actions, err := models.GetFeeds(form.UserId, form.Page*20, false)
-// if err != nil {
-// ctx.JSON(500, err)
-// return
-// }
-
-// feeds := make([]string, 0, len(actions))
-// for _, act := range actions {
-// if act.IsPrivate {
-// if has, _ := models.HasAccess(ctx.User.Name, act.RepoUserName+"/"+act.RepoName,
-// models.READABLE); !has {
-// continue
-// }
-// }
-// feeds = append(feeds, fmt.Sprintf(TPL_FEED, base.ActionIcon(act.OpType),
-// base.TimeSince(act.Created), base.ActionDesc(act)))
-// }
-// ctx.JSON(200, &feeds)
-// }
-
func Issues(ctx *middleware.Context) {
ctx.Data["Title"] = "Your Issues"