func TestServiceHtmlAvailable(t *testing.T) {

	htmlData, err := html.Asset(homepageFileName)
	assert.NoError(t, err)
	assert.NotNil(t, htmlData)

	htmlData, err = html.Asset(mainpageFileName)
	assert.NoError(t, err)
	assert.NotNil(t, htmlData)

}
Esempio n. 2
0
//ErrorPage shows the errorpage
func (service *Service) ErrorPage(w http.ResponseWriter, request *http.Request) {
	errornumber := mux.Vars(request)["errornumber"]
	log.Debug("Errorpage requested for error ", errornumber)

	htmlData, err := html.Asset(errorpageFilename)
	if err != nil {
		log.Error("ERROR rendering error page: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	// check if the error is a number to prevent XSS attacks
	errorcode, err := strconv.Atoi(errornumber)
	if err != nil {
		log.Info("Error code could not be converted to int")
		// The error page already loaded so we might as well use it
		errorcode = 400
		errornumber = "400"
	}

	// check if the error code is within the accepted 4xx client or 5xx server error range
	if errorcode > 599 || errorcode < 400 {
		log.Info("Error code out of bounds: ", errorcode)
		errorcode = 400
		errornumber = "400"
	}

	// now that we confirmed the error code is valid, we can safely use it to display on the error page
	htmlData = bytes.Replace(htmlData, []byte(`500`), []byte(errornumber), 1)
	w.Write(htmlData)
}
Esempio n. 3
0
func (service *Service) renderRegistrationFrom(w http.ResponseWriter, request *http.Request, validationErrors []string, totpsecret string) {
	htmlData, err := html.Asset(registrationFileName)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	//Don't use go templates since angular uses "{{ ... }}" syntax as well and this way the standalone page also works
	htmlData = bytes.Replace(htmlData, []byte("secret=1234123412341234"), []byte("secret="+totpsecret), 2)

	errorMap := make(map[string]bool)
	for _, errorkey := range validationErrors {
		errorMap[errorkey] = true
	}
	jsonErrors, err := json.Marshal(errorMap)

	if err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	htmlData = bytes.Replace(htmlData, []byte(`{"invalidsomething": true}`), jsonErrors, 1)

	sessions.Save(request, w)
	w.Write(htmlData)
}
Esempio n. 4
0
//APIDocs shows the api documentation
func (service *Service) APIDocs(w http.ResponseWriter, request *http.Request) {
	htmlData, err := html.Asset(apidocsPageFilename)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	w.Write(htmlData)
}
Esempio n. 5
0
//ShowPublicSite shows the public website
func (service *Service) ShowPublicSite(w http.ResponseWriter, request *http.Request) {
	htmlData, err := html.Asset(mainpageFileName)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	w.Write(htmlData)
}
func (service *Service) renderRegistrationFrom(w http.ResponseWriter, request *http.Request) {
	htmlData, err := html.Asset(registrationFileName)
	if err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	sessions.Save(request, w)
	w.Write(htmlData)
}
Esempio n. 7
0
//renderEmailConfirmationPage renders a small mobile friendly confirmation page after a user follows a link in an email
func (service *Service) renderEmailConfirmationPage(w http.ResponseWriter, request *http.Request, text string) {
	htmlData, err := html.Asset(emailconfirmationPage)
	if err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	htmlData = bytes.Replace(htmlData, []byte(`{{ text }}`), []byte(text), 1)
	sessions.Save(request, w)
	w.Write(htmlData)
}
Esempio n. 8
0
//ErrorPage shows the errorpage
func (service *Service) ErrorPage(w http.ResponseWriter, request *http.Request) {
	errornumber := mux.Vars(request)["errornumber"]
	log.Debug("Errorpage requested for error ", errornumber)

	htmlData, err := html.Asset(errorpageFilename)
	if err != nil {
		log.Error("ERROR rendering error page: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	htmlData = bytes.Replace(htmlData, []byte(`500`), []byte(errornumber), 1)
	w.Write(htmlData)
}
Esempio n. 9
0
//renderLoginForm shows the user login page
func (service *Service) renderLoginForm(w http.ResponseWriter, request *http.Request, indicateError bool, postbackURL string) {
	htmlData, err := html.Asset(loginFileName)
	if err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if indicateError {
		htmlData = bytes.Replace(htmlData, []byte(`{"invalidsomething": true}`), []byte(`{"invalidcredentials": true}`), 1)
	}
	htmlData = bytes.Replace(htmlData, []byte(`action="login"`), []byte(fmt.Sprintf("action=\"%s\"", postbackURL)), 1)
	sessions.Save(request, w)
	w.Write(htmlData)
}
Esempio n. 10
0
//ShowLoginForm shows the user login page on the initial request
func (service *Service) ShowLoginForm(w http.ResponseWriter, request *http.Request) {
	htmlData, err := html.Asset(loginFileName)
	if err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	loginSession, err := service.GetSession(request, SessionLogin, "loginsession")
	if err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	loginSession.Values["auth_client_id"] = request.URL.Query().Get("client_id")
	sessions.Save(request, w)
	w.Write(htmlData)

}
Esempio n. 11
0
//HomePage shows the home page when logged in, if not, delegate to showing the public website
func (service *Service) HomePage(w http.ResponseWriter, request *http.Request) {

	loggedinuser, err := service.GetLoggedInUser(request, w)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if loggedinuser == "" {
		service.ShowPublicSite(w, request)
		return
	}

	htmlData, err := html.Asset(homepageFileName)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	sessions.Save(request, w)
	w.Write(htmlData)
}
Esempio n. 12
0
func TestLoginHtmlAvailable(t *testing.T) {

	htmlData, err := html.Asset(loginFileName)
	assert.NoError(t, err)
	assert.NotNil(t, htmlData)
}
func TestRegistrationHtmlAvailable(t *testing.T) {

	htmlData, err := html.Asset(registrationFileName)
	assert.NoError(t, err)
	assert.NotNil(t, htmlData)
}