From abc57b6e439c5ab9c3b6ed2cedeb10d50f5ae619 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 7 Nov 2014 14:46:13 -0500 Subject: work on #609 --- routers/repo/http.go | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'routers/repo/http.go') diff --git a/routers/repo/http.go b/routers/repo/http.go index 3641f4da..0ce83cef 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -7,8 +7,6 @@ package repo import ( "bytes" "compress/gzip" - "encoding/base64" - "errors" "fmt" "io" "io/ioutil" @@ -16,6 +14,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "regexp" "strconv" @@ -29,27 +28,6 @@ import ( "github.com/gogits/gogs/modules/setting" ) -func basicEncode(username, password string) string { - auth := username + ":" + password - return base64.StdEncoding.EncodeToString([]byte(auth)) -} - -func basicDecode(encoded string) (user string, name string, err error) { - var s []byte - s, err = base64.StdEncoding.DecodeString(encoded) - if err != nil { - return user, name, err - } - - a := strings.Split(string(s), ":") - if len(a) == 2 { - user, name = a[0], a[1] - } else { - err = errors.New("decode failed") - } - return user, name, err -} - func authRequired(ctx *middleware.Context) { ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"") ctx.Data["ErrorMsg"] = "no basic auth and digit auth" @@ -112,11 +90,12 @@ func Http(ctx *middleware.Context) { auths := strings.Fields(baHead) // currently check basic auth // TODO: support digit auth + // FIXME: middlewares/context.go did basic auth check already if len(auths) != 2 || auths[0] != "Basic" { ctx.Handle(401, "no basic auth and digit auth", nil) return } - authUsername, passwd, err = basicDecode(auths[1]) + authUsername, passwd, err = base.BasicAuthDecode(auths[1]) if err != nil { ctx.Handle(401, "no basic auth and digit auth", nil) return -- cgit v1.2.3