summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-11-10 05:30:07 -0500
committerUnknwon <joe2010xtmf@163.com>2014-11-10 05:30:07 -0500
commite0de6cb5adf5a81a95840f648d8a388b566202bd (patch)
tree6407a7524675e00d2a942ffa2868074dbd17b96c /modules
parentff8578082eaa356637cc24a3a09548b37aad2371 (diff)
downloadgitea-e0de6cb5adf5a81a95840f648d8a388b566202bd.tar.gz
gitea-e0de6cb5adf5a81a95840f648d8a388b566202bd.zip
work on #616 and update locales
Diffstat (limited to 'modules')
-rw-r--r--modules/auth/auth.go53
-rw-r--r--modules/middleware/context.go20
2 files changed, 39 insertions, 34 deletions
diff --git a/modules/auth/auth.go b/modules/auth/auth.go
index 95e647f53a..b9266d6895 100644
--- a/modules/auth/auth.go
+++ b/modules/auth/auth.go
@@ -14,6 +14,7 @@ import (
"github.com/macaron-contrib/session"
"github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting"
)
@@ -24,20 +25,6 @@ func SignedInId(header http.Header, sess session.Store) int64 {
return 0
}
- if setting.Service.EnableReverseProxyAuth {
- webAuthUser := header.Get(setting.ReverseProxyAuthUser)
- if len(webAuthUser) > 0 {
- u, err := models.GetUserByName(webAuthUser)
- if err != nil {
- if err != models.ErrUserNotExist {
- log.Error(4, "GetUserByName: %v", err)
- }
- return 0
- }
- return u.Id
- }
- }
-
uid := sess.Get("uid")
if uid == nil {
return 0
@@ -56,8 +43,46 @@ func SignedInId(header http.Header, sess session.Store) int64 {
// SignedInUser returns the user object of signed user.
func SignedInUser(header http.Header, sess session.Store) *models.User {
+ if !models.HasEngine {
+ return nil
+ }
+
uid := SignedInId(header, sess)
+
if uid <= 0 {
+ if setting.Service.EnableReverseProxyAuth {
+ webAuthUser := header.Get(setting.ReverseProxyAuthUser)
+ if len(webAuthUser) > 0 {
+ u, err := models.GetUserByName(webAuthUser)
+ if err != nil {
+ if err != models.ErrUserNotExist {
+ log.Error(4, "GetUserByName: %v", err)
+ }
+ return nil
+ }
+ return u
+ }
+ }
+
+ // Check with basic auth.
+ baHead := header.Get("Authorization")
+ if len(baHead) > 0 {
+ 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 {
+ log.Error(4, "GetUserByName: %v", err)
+ }
+ return nil
+ }
+
+ if u.ValidtePassword(passwd) {
+ return u
+ }
+ }
+ }
return nil
}
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 7d767b9e76..58b4f7497b 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -174,26 +174,6 @@ 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