Fix auth issue on #80
This commit is contained in:
parent
6277f8497c
commit
2dc0329c5f
1 changed files with 19 additions and 17 deletions
|
@ -58,7 +58,8 @@ func Http(ctx *middleware.Context, params martini.Params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// only public pull don't need auth
|
// only public pull don't need auth
|
||||||
var askAuth = !(!repo.IsPrivate && isPull) || base.Service.RequireSignInView
|
isPublicPull := !repo.IsPrivate && isPull
|
||||||
|
var askAuth = !isPublicPull || base.Service.RequireSignInView
|
||||||
|
|
||||||
var authUser *models.User
|
var authUser *models.User
|
||||||
|
|
||||||
|
@ -91,32 +92,33 @@ func Http(ctx *middleware.Context, params martini.Params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
newUser := &models.User{Passwd: passwd, Salt: authUser.Salt}
|
newUser := &models.User{Passwd: passwd, Salt: authUser.Salt}
|
||||||
|
|
||||||
newUser.EncodePasswd()
|
newUser.EncodePasswd()
|
||||||
if authUser.Passwd != newUser.Passwd {
|
if authUser.Passwd != newUser.Passwd {
|
||||||
ctx.Handle(401, "no basic auth and digit auth", nil)
|
ctx.Handle(401, "no basic auth and digit auth", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var tp = models.AU_WRITABLE
|
if !isPublicPull {
|
||||||
if isPull {
|
var tp = models.AU_WRITABLE
|
||||||
tp = models.AU_READABLE
|
if isPull {
|
||||||
}
|
tp = models.AU_READABLE
|
||||||
|
}
|
||||||
|
|
||||||
has, err := models.HasAccess(authUsername, username+"/"+reponame, tp)
|
has, err := models.HasAccess(authUsername, username+"/"+reponame, tp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(401, "no basic auth and digit auth", nil)
|
ctx.Handle(401, "no basic auth and digit auth", nil)
|
||||||
return
|
return
|
||||||
} else if !has {
|
} else if !has {
|
||||||
if tp == models.AU_READABLE {
|
if tp == models.AU_READABLE {
|
||||||
has, err = models.HasAccess(authUsername, username+"/"+reponame, models.AU_WRITABLE)
|
has, err = models.HasAccess(authUsername, username+"/"+reponame, models.AU_WRITABLE)
|
||||||
if err != nil || !has {
|
if err != nil || !has {
|
||||||
|
ctx.Handle(401, "no basic auth and digit auth", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
ctx.Handle(401, "no basic auth and digit auth", nil)
|
ctx.Handle(401, "no basic auth and digit auth", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ctx.Handle(401, "no basic auth and digit auth", nil)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue