mirror of
https://dev.sigpipe.me/dashie/git.txt
synced 2025-10-06 06:02:41 +02:00
35 lines
682 B
Go
35 lines
682 B
Go
package context
|
|
|
|
import (
|
|
"dev.sigpipe.me/dashie/git.txt/models"
|
|
"dev.sigpipe.me/dashie/git.txt/models/errors"
|
|
"gopkg.in/macaron.v1"
|
|
)
|
|
|
|
// AssignUser to context
|
|
func AssignUser() macaron.Handler {
|
|
return func(ctx *Context) {
|
|
userName := ctx.Params("user")
|
|
|
|
// Anonymous user doesn't really exists, that's nil
|
|
if userName == "anonymous" {
|
|
ctx.Gitxt.User = nil
|
|
ctx.RepoOwnerUsername = "anonymous"
|
|
return
|
|
}
|
|
|
|
user, err := models.GetUserByName(userName)
|
|
if err != nil {
|
|
if errors.IsUserNotExist(err) {
|
|
ctx.NotFound()
|
|
} else {
|
|
ctx.Handle(500, "GetUserByName", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
ctx.Gitxt.User = user
|
|
ctx.RepoOwnerUsername = userName
|
|
}
|
|
}
|