mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
update per comments, add support for basic auth
This commit is contained in:
parent
7165156f2d
commit
fc24341c17
24
api/user.go
24
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)
|
||||
|
Loading…
Reference in New Issue
Block a user