mirror of
https://github.com/goharbor/harbor
synced 2025-04-21 01:33:58 +00:00
Merge pull request #3837 from reasonerjt/remove-code
Remove useless code from UI router and API
This commit is contained in:
commit
ea607393d5
|
@ -21,11 +21,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/astaxie/beego/validation"
|
"github.com/astaxie/beego/validation"
|
||||||
"github.com/vmware/harbor/src/common/dao"
|
|
||||||
"github.com/vmware/harbor/src/common/models"
|
|
||||||
http_error "github.com/vmware/harbor/src/common/utils/error"
|
http_error "github.com/vmware/harbor/src/common/utils/error"
|
||||||
"github.com/vmware/harbor/src/common/utils/log"
|
"github.com/vmware/harbor/src/common/utils/log"
|
||||||
"github.com/vmware/harbor/src/ui/auth"
|
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
@ -151,59 +148,6 @@ func (b *BaseAPI) DecodeJSONReqAndValidate(v interface{}) {
|
||||||
b.Validate(v)
|
b.Validate(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateUser checks if the request triggered by a valid user
|
|
||||||
// TODO remove
|
|
||||||
func (b *BaseAPI) ValidateUser() int {
|
|
||||||
userID, needsCheck, ok := b.GetUserIDForRequest()
|
|
||||||
if !ok {
|
|
||||||
log.Warning("No user id in session, canceling request")
|
|
||||||
b.CustomAbort(http.StatusUnauthorized, "")
|
|
||||||
}
|
|
||||||
if needsCheck {
|
|
||||||
u, err := dao.GetUser(models.User{UserID: userID})
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Error occurred in GetUser, error: %v", err)
|
|
||||||
b.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
|
||||||
}
|
|
||||||
if u == nil {
|
|
||||||
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
|
|
||||||
b.CustomAbort(http.StatusUnauthorized, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return userID
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUserIDForRequest tries to get user ID from basic auth header and session.
|
|
||||||
// It returns the user ID, whether need further verification(when the id is from session) and if the action is successful
|
|
||||||
// TODO remove
|
|
||||||
func (b *BaseAPI) GetUserIDForRequest() (int, bool, bool) {
|
|
||||||
username, password, ok := b.Ctx.Request.BasicAuth()
|
|
||||||
if ok {
|
|
||||||
log.Infof("Requst with Basic Authentication header, username: %s", username)
|
|
||||||
user, err := auth.Login(models.AuthModel{
|
|
||||||
Principal: username,
|
|
||||||
Password: password,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Error while trying to login, username: %s, error: %v", username, err)
|
|
||||||
user = nil
|
|
||||||
}
|
|
||||||
if user != nil {
|
|
||||||
b.SetSession("userId", user.UserID)
|
|
||||||
b.SetSession("username", user.Username)
|
|
||||||
// User login successfully no further check required.
|
|
||||||
return user.UserID, false, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sessionUserID, ok := b.GetSession("userId").(int)
|
|
||||||
if ok {
|
|
||||||
// The ID is from session
|
|
||||||
return sessionUserID, true, true
|
|
||||||
}
|
|
||||||
log.Debug("No valid user id in session.")
|
|
||||||
return 0, false, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect does redirection to resource URI with http header status code.
|
// Redirect does redirection to resource URI with http header status code.
|
||||||
func (b *BaseAPI) Redirect(statusCode int, resouceID string) {
|
func (b *BaseAPI) Redirect(statusCode int, resouceID string) {
|
||||||
requestURI := b.Ctx.Request.RequestURI
|
requestURI := b.Ctx.Request.RequestURI
|
||||||
|
|
|
@ -32,15 +32,11 @@ func initRouters() {
|
||||||
|
|
||||||
//Page Controllers:
|
//Page Controllers:
|
||||||
beego.Router("/", &controllers.IndexController{})
|
beego.Router("/", &controllers.IndexController{})
|
||||||
beego.Router("/sign-in", &controllers.IndexController{})
|
|
||||||
beego.Router("/sign-up", &controllers.IndexController{})
|
|
||||||
beego.Router("/reset_password", &controllers.IndexController{})
|
beego.Router("/reset_password", &controllers.IndexController{})
|
||||||
|
|
||||||
beego.Router("/harbor", &controllers.IndexController{})
|
beego.Router("/harbor", &controllers.IndexController{})
|
||||||
|
|
||||||
beego.Router("/harbor/sign-in", &controllers.IndexController{})
|
beego.Router("/harbor/sign-in", &controllers.IndexController{})
|
||||||
beego.Router("/harbor/sign-up", &controllers.IndexController{})
|
|
||||||
beego.Router("/harbor/dashboard", &controllers.IndexController{})
|
|
||||||
beego.Router("/harbor/projects", &controllers.IndexController{})
|
beego.Router("/harbor/projects", &controllers.IndexController{})
|
||||||
beego.Router("/harbor/projects/:id/repositories", &controllers.IndexController{})
|
beego.Router("/harbor/projects/:id/repositories", &controllers.IndexController{})
|
||||||
beego.Router("/harbor/projects/:id/repositories/*", &controllers.IndexController{})
|
beego.Router("/harbor/projects/:id/repositories/*", &controllers.IndexController{})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user