From 37d8d3afe9ec589574c0cc6380a36fa93b1be8f2 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 18 Nov 2014 11:07:16 -0500 Subject: more APIs on #12 --- modules/middleware/auth.go | 9 +++++++++ modules/middleware/context.go | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'modules/middleware') diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index 8388d2b25e..fc8e94bbd0 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -76,3 +76,12 @@ func ApiReqToken() macaron.Handler { } } } + +func ApiReqBasicAuth() macaron.Handler { + return func(ctx *Context) { + if !ctx.IsBasicAuth { + ctx.Error(403) + return + } + } +} diff --git a/modules/middleware/context.go b/modules/middleware/context.go index cbc0b0cf3c..fb33c48e0e 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -34,8 +34,9 @@ type Context struct { Flash *session.Flash Session session.Store - User *models.User - IsSigned bool + User *models.User + IsSigned bool + IsBasicAuth bool Repo struct { IsOwner bool @@ -172,7 +173,7 @@ func Contexter() macaron.Handler { ctx.Data["PageStartTime"] = time.Now() // Get user from session if logined. - ctx.User = auth.SignedInUser(ctx.Req.Request, ctx.Session) + ctx.User, ctx.IsBasicAuth = auth.SignedInUser(ctx.Req.Request, ctx.Session) if ctx.User != nil { ctx.IsSigned = true -- cgit v1.2.3