add .gpg url (match github behaviour)

This commit is contained in:
Gitea 2018-06-08 21:40:27 -04:00
parent 25b1a8099b
commit e72bb6594d
3 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -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)

View File

@ -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