|
|
@ -261,7 +261,7 @@ func basicDecode(encoded string) (user string, name string, err error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func authRequired(ctx *middleware.Context) { |
|
|
|
func authRequired(ctx *middleware.Context) { |
|
|
|
ctx.ResponseWriter.Header().Set("WWW-Authenticate", `Basic realm="Gogs Auth"`) |
|
|
|
ctx.ResponseWriter.Header().Set("WWW-Authenticate", "Basic realm=\".\"") |
|
|
|
ctx.Data["ErrorMsg"] = "no basic auth and digit auth" |
|
|
|
ctx.Data["ErrorMsg"] = "no basic auth and digit auth" |
|
|
|
ctx.HTML(401, fmt.Sprintf("status/401")) |
|
|
|
ctx.HTML(401, fmt.Sprintf("status/401")) |
|
|
|
} |
|
|
|
} |
|
|
@ -273,6 +273,8 @@ func Http(ctx *middleware.Context, params martini.Params) { |
|
|
|
reponame = reponame[:len(reponame)-4] |
|
|
|
reponame = reponame[:len(reponame)-4] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//fmt.Println("req:", ctx.Req.Header)
|
|
|
|
|
|
|
|
|
|
|
|
repoUser, err := models.GetUserByName(username) |
|
|
|
repoUser, err := models.GetUserByName(username) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "repo.GetUserByName", nil) |
|
|
|
ctx.Handle(500, "repo.GetUserByName", nil) |
|
|
@ -297,7 +299,11 @@ func Http(ctx *middleware.Context, params martini.Params) { |
|
|
|
|
|
|
|
|
|
|
|
// check basic auth
|
|
|
|
// check basic auth
|
|
|
|
baHead := ctx.Req.Header.Get("Authorization") |
|
|
|
baHead := ctx.Req.Header.Get("Authorization") |
|
|
|
if baHead != "" { |
|
|
|
if baHead == "" { |
|
|
|
|
|
|
|
authRequired(ctx) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
auths := strings.Fields(baHead) |
|
|
|
auths := strings.Fields(baHead) |
|
|
|
if len(auths) != 2 || auths[0] != "Basic" { |
|
|
|
if len(auths) != 2 || auths[0] != "Basic" { |
|
|
|
ctx.Handle(401, "no basic auth and digit auth", nil) |
|
|
|
ctx.Handle(401, "no basic auth and digit auth", nil) |
|
|
@ -332,10 +338,6 @@ func Http(ctx *middleware.Context, params martini.Params) { |
|
|
|
ctx.Handle(401, "no basic auth and digit auth", nil) |
|
|
|
ctx.Handle(401, "no basic auth and digit auth", nil) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
authRequired(ctx) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dir := models.RepoPath(username, reponame) |
|
|
|
dir := models.RepoPath(username, reponame) |
|
|
|