summaryrefslogtreecommitdiff
blob: 2e3b241102708193729d7ab8e3e5a3b6bd91b063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package templates

import (
	"html/template"
	"net/http"
)

// renderIndexTemplate renders all templates used for the login page
func RenderLoginTemplate(w http.ResponseWriter, r *http.Request) {

	data := struct {
		CameFrom string
	}{
		CameFrom: getPath(r),
	}

	templates := template.Must(
		template.Must(
			template.New("Show").
				ParseGlob("web/templates/layout/*.tmpl")).
			ParseGlob("web/templates/authentication/login.tmpl"))

	templates.ExecuteTemplate(w, "login.tmpl", data)
}

func getPath(r *http.Request) string {
	if r.URL.RawQuery == "" {
		return r.URL.Path
	} else {
		return r.URL.Path + "?" + r.URL.RawQuery
	}
}