1
0
Fork 0
forked from forgejo/forgejo
This commit is contained in:
Unknwon 2014-11-07 14:46:13 -05:00
parent a01b4baca2
commit abc57b6e43
6 changed files with 53 additions and 35 deletions

View file

@ -173,6 +173,27 @@ func Contexter() macaron.Handler {
// Get user from session if logined.
ctx.User = auth.SignedInUser(ctx.Req.Header, ctx.Session)
// Check with basic auth again.
if ctx.User == nil {
baHead := ctx.Req.Header.Get("Authorization")
auths := strings.Fields(baHead)
if len(auths) == 2 && auths[0] == "Basic" {
uname, passwd, _ := base.BasicAuthDecode(auths[1])
u, err := models.GetUserByName(uname)
if err != nil {
if err != models.ErrUserNotExist {
ctx.Handle(500, "GetUserByName", err)
return
}
} else {
if u.ValidtePassword(passwd) {
ctx.User = u
}
}
}
}
if ctx.User != nil {
ctx.IsSigned = true
ctx.Data["IsSigned"] = ctx.IsSigned