From e72bb6594da72e5695706003f34b4317338e3d9e Mon Sep 17 00:00:00 2001 From: Gitea Date: Fri, 8 Jun 2018 21:40:27 -0400 Subject: [PATCH 1/2] add .gpg url (match github behaviour) --- models/user.go | 2 +- routers/user/home.go | 16 ++++++++++++++++ routers/user/profile.go | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/models/user.go b/models/user.go index 1497eef44..7f429cfc3 100644 --- a/models/user.go +++ b/models/user.go @@ -655,7 +655,7 @@ func NewGhostUser() *User { var ( reservedUsernames = []string{"assets", "css", "explore", "img", "js", "less", "plugins", "debug", "raw", "install", "api", "avatars", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin", "error", "new", ".", ".."} - reservedUserPatterns = []string{"*.keys"} + reservedUserPatterns = []string{"*.keys", ".gpg"} ) // isUsableName checks if name is reserved or pattern of name is not allowed diff --git a/routers/user/home.go b/routers/user/home.go index 2a193bbde..693b04b02 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -350,6 +350,22 @@ func ShowSSHKeys(ctx *context.Context, uid int64) { ctx.PlainText(200, buf.Bytes()) } +// ShowGPGKeys output all the public GPG keys of user by uid +func ShowGPGKeys(ctx *context.Context, uid int64) { + keys, err := models.ListGPGKeys(uid) + if err != nil { + ctx.ServerError("ListGPGKeys", err) + return + } + + var buf bytes.Buffer + for i := range keys { + buf.WriteString(keys[i]) + buf.WriteString("\n") + } + ctx.PlainText(200, buf.Bytes()) +} + func showOrgProfile(ctx *context.Context) { ctx.SetParams(":org", ctx.Params(":username")) context.HandleOrgAssignment(ctx) diff --git a/routers/user/profile.go b/routers/user/profile.go index fb731e715..8b5dd686b 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -58,9 +58,16 @@ func Profile(ctx *context.Context) { isShowKeys := false if strings.HasSuffix(uname, ".keys") { isShowKeys = true + uname = strings.TrimSuffix(uname, ".gpg") } - ctxUser := GetUserByName(ctx, strings.TrimSuffix(uname, ".keys")) + isShowGPG := false + if strings.HasSuffix(uname, ".gpg") { + isShowGPG = true + uname = strings.TrimSuffix(uname, ".gpg") + } + + ctxUser := GetUserByName(ctx, uname) if ctx.Written() { return } @@ -71,6 +78,12 @@ func Profile(ctx *context.Context) { return } + // Show GPG keys. + if isShowGPG { + ShowGPGKeys(ctx, ctxUser.ID) + return + } + if ctxUser.IsOrganization() { showOrgProfile(ctx) return From ce48cb551f967378c424a605963c4bb307512343 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Sat, 9 Jun 2018 12:04:27 -0400 Subject: [PATCH 2/2] wildcard --- models/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/user.go b/models/user.go index 7f429cfc3..4eeb3e22a 100644 --- a/models/user.go +++ b/models/user.go @@ -655,7 +655,7 @@ func NewGhostUser() *User { var ( reservedUsernames = []string{"assets", "css", "explore", "img", "js", "less", "plugins", "debug", "raw", "install", "api", "avatars", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin", "error", "new", ".", ".."} - reservedUserPatterns = []string{"*.keys", ".gpg"} + reservedUserPatterns = []string{"*.keys", "*.gpg"} ) // isUsableName checks if name is reserved or pattern of name is not allowed