2016-06-16 08:10:35 +02:00
|
|
|
package controllers
|
2016-05-21 05:26:19 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/vmware/harbor/dao"
|
|
|
|
"github.com/vmware/harbor/models"
|
|
|
|
"github.com/vmware/harbor/utils/log"
|
|
|
|
)
|
|
|
|
|
2016-06-16 08:10:35 +02:00
|
|
|
// NavigationHeaderController handles requests to /navigation_header
|
2016-05-21 05:26:19 +02:00
|
|
|
type NavigationHeaderController struct {
|
|
|
|
BaseController
|
|
|
|
}
|
|
|
|
|
2016-05-23 09:43:15 +02:00
|
|
|
// Get renders user's navigation header
|
2016-05-21 05:26:19 +02:00
|
|
|
func (nhc *NavigationHeaderController) Get() {
|
|
|
|
sessionUserID := nhc.GetSession("userId")
|
|
|
|
var hasLoggedIn bool
|
|
|
|
var isAdmin int
|
|
|
|
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)
|
|
|
|
nhc.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
|
|
|
}
|
|
|
|
if u == nil {
|
|
|
|
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
|
|
|
|
nhc.CustomAbort(http.StatusUnauthorized, "")
|
|
|
|
}
|
|
|
|
isAdmin = u.HasAdminRole
|
|
|
|
}
|
|
|
|
nhc.Data["HasLoggedIn"] = hasLoggedIn
|
|
|
|
nhc.Data["IsAdmin"] = isAdmin
|
2016-06-16 08:10:35 +02:00
|
|
|
nhc.TplName = "navigation-header.htm"
|
2016-05-21 05:26:19 +02:00
|
|
|
nhc.Render()
|
|
|
|
}
|