2016-06-16 08:10:35 +02:00
|
|
|
package controllers
|
2016-05-24 12:22:06 +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
|
|
|
// SignInController handles requests to /sign_in
|
2016-05-24 12:22:06 +02:00
|
|
|
type SignInController struct {
|
|
|
|
BaseController
|
|
|
|
}
|
|
|
|
|
2016-06-02 09:44:53 +02:00
|
|
|
//Get renders sign_in page
|
2016-05-24 12:22:06 +02:00
|
|
|
func (sic *SignInController) Get() {
|
|
|
|
sessionUserID := sic.GetSession("userId")
|
|
|
|
var hasLoggedIn bool
|
|
|
|
var username string
|
|
|
|
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)
|
|
|
|
sic.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
|
|
|
}
|
|
|
|
if u == nil {
|
|
|
|
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
|
|
|
|
sic.CustomAbort(http.StatusUnauthorized, "")
|
|
|
|
}
|
|
|
|
username = u.Username
|
|
|
|
}
|
2016-06-22 09:15:25 +02:00
|
|
|
sic.Data["AuthMode"] = sic.AuthMode
|
2016-05-24 12:22:06 +02:00
|
|
|
sic.Data["Username"] = username
|
|
|
|
sic.Data["HasLoggedIn"] = hasLoggedIn
|
2016-06-16 08:10:35 +02:00
|
|
|
sic.TplName = "sign-in.htm"
|
2016-05-24 12:22:06 +02:00
|
|
|
sic.Render()
|
|
|
|
}
|