auth.go 615 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package middleware
  5. import (
  6. "github.com/codegangsta/martini"
  7. )
  8. // SignInRequire requires user to sign in.
  9. func SignInRequire(redirect bool) martini.Handler {
  10. return func(ctx *Context) {
  11. if !ctx.IsSigned {
  12. if redirect {
  13. ctx.Render.Redirect("/")
  14. }
  15. return
  16. }
  17. }
  18. }
  19. // SignOutRequire requires user to sign out.
  20. func SignOutRequire() martini.Handler {
  21. return func(ctx *Context) {
  22. if ctx.IsSigned {
  23. ctx.Render.Redirect("/")
  24. }
  25. }
  26. }