From 9330c943cd17152c5aca1619f6b87382e3800732 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 18 Nov 2015 23:52:09 -0500 Subject: work on #1891 --- modules/middleware/auth.go | 12 ++++++++++++ modules/middleware/context.go | 8 -------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'modules/middleware') diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index 823e457a..2dd9b0fd 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -109,6 +109,18 @@ func Toggle(options *ToggleOptions) macaron.Handler { } } + // Try auto-signin when not signed in. + if !ctx.IsSigned { + succeed, err := AutoSignIn(ctx) + if err != nil { + ctx.Handle(500, "AutoSignIn", err) + return + } else if succeed { + ctx.Redirect(ctx.Req.URL.Path) + return + } + } + if options.AdminRequire { if !ctx.User.IsAdmin { ctx.Error(403) diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 4839ccf9..4b217b63 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -209,14 +209,6 @@ func Contexter() macaron.Handler { ctx.Data["PageStartTime"] = time.Now() - // Check auto-signin. - if sess.Get("uid") == nil { - if _, err := AutoSignIn(ctx); err != nil { - ctx.Handle(500, "AutoSignIn", err) - return - } - } - // Get user from session if logined. ctx.User, ctx.IsBasicAuth = auth.SignedInUser(ctx.Context, ctx.Session) -- cgit v1.2.3