summaryrefslogtreecommitdiffstats
path: root/modules/middleware
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-11-07 14:46:13 -0500
committerUnknwon <joe2010xtmf@163.com>2014-11-07 14:46:13 -0500
commitabc57b6e439c5ab9c3b6ed2cedeb10d50f5ae619 (patch)
treef3625f90376d6c4fe2f1ee7a05ba23a5e0b10d9e /modules/middleware
parenta01b4baca2c1a1d011f19f2255eb9b703658b3dd (diff)
downloadgitea-abc57b6e439c5ab9c3b6ed2cedeb10d50f5ae619.tar.gz
gitea-abc57b6e439c5ab9c3b6ed2cedeb10d50f5ae619.zip
work on #609
Diffstat (limited to 'modules/middleware')
-rw-r--r--modules/middleware/context.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index d2620fed12..7d767b9e76 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -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