mirror of
https://github.com/goharbor/harbor.git
synced 2024-09-16 07:56:39 +02:00
38 lines
877 B
Go
38 lines
877 B
Go
|
package ng
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/vmware/harbor/dao"
|
||
|
"github.com/vmware/harbor/models"
|
||
|
"github.com/vmware/harbor/utils/log"
|
||
|
)
|
||
|
|
||
|
type OptionalMenuController struct {
|
||
|
BaseController
|
||
|
}
|
||
|
|
||
|
func (omc *OptionalMenuController) Get() {
|
||
|
sessionUserID := omc.GetSession("userId")
|
||
|
|
||
|
var hasLoggedIn bool
|
||
|
if sessionUserID != nil {
|
||
|
hasLoggedIn = true
|
||
|
userID := sessionUserID.(int)
|
||
|
u, err := dao.GetUser(models.User{UserID: userID})
|
||
|
if err != nil {
|
||
|
log.Errorf("Error occurred in GetUser, error: %v", err)
|
||
|
omc.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
||
|
}
|
||
|
if u == nil {
|
||
|
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
|
||
|
omc.CustomAbort(http.StatusUnauthorized, "")
|
||
|
}
|
||
|
omc.Data["Username"] = u.Username
|
||
|
}
|
||
|
omc.Data["HasLoggedIn"] = hasLoggedIn
|
||
|
omc.TplName = "ng/optional-menu.htm"
|
||
|
omc.Render()
|
||
|
|
||
|
}
|