From fc24341c1730ffe6d60c9a8587ed8a44affb7c50 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Fri, 15 Apr 2016 01:55:33 -0700 Subject: [PATCH] update per comments, add support for basic auth --- api/user.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/api/user.go b/api/user.go index d4c0c1851..58aa29ec3 100644 --- a/api/user.go +++ b/api/user.go @@ -29,14 +29,11 @@ import ( // UserAPI handles request to /api/users/{} type UserAPI struct { BaseAPI - currentUserID int - userID int - SelfRegistration bool - IsAdmin bool - AuthMode string - IsBasicAuth bool - UserNameInBasicAuth string - PasswordInBasicAuth string + currentUserID int + userID int + SelfRegistration bool + IsAdmin bool + AuthMode string } // Prepare validates the URL and parms @@ -54,10 +51,9 @@ func (ua *UserAPI) Prepare() { } if ua.Ctx.Input.IsPost() { - ua.UserNameInBasicAuth, ua.PasswordInBasicAuth, ua.IsBasicAuth = ua.Ctx.Request.BasicAuth() - sessionUserID := ua.GetSession("userId") - if sessionUserID == nil { + _, _, ok := ua.Ctx.Request.BasicAuth() + if sessionUserID == nil && !ok { return } } @@ -91,6 +87,7 @@ func (ua *UserAPI) Prepare() { log.Errorf("Error occurred in IsAdminRole:%v", err) ua.CustomAbort(http.StatusInternalServerError, "Internal error.") } + } // Get ... @@ -156,11 +153,6 @@ func (ua *UserAPI) Post() { user := models.User{} ua.DecodeJSONReq(&user) - if ua.IsBasicAuth { - user.Username = ua.UserNameInBasicAuth - user.Password = ua.PasswordInBasicAuth - } - _, err := dao.Register(user) if err != nil { log.Errorf("Error occurred in Register: %v", err)