-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes-handlers.go
93 lines (74 loc) · 2.08 KB
/
routes-handlers.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"encoding/json"
"fmt"
"html/template"
"log"
"net/http"
"path"
)
func renderView(view string) *template.Template {
content := path.Join("./views/", view)
header := "./views/template/header.html"
footer := "./views/template/footer.html"
tpl, err := template.ParseFiles(content, header, footer)
if err != nil {
panic("Error while rendering pages.")
}
return tpl
}
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println(r.RequestURI)
next.ServeHTTP(w, r)
})
}
func home(w http.ResponseWriter, r *http.Request) {
tpl := renderView("index.html")
tpl.ExecuteTemplate(w, "index", map[string]interface{}{"RecaptchaSiteKey": ReCaptchaConf.SiteKey})
}
func about(w http.ResponseWriter, r *http.Request) {
tpl := renderView("about.html")
tpl.ExecuteTemplate(w, "about", nil)
}
func faq(w http.ResponseWriter, r *http.Request) {
tpl := renderView("faq.html")
tpl.ExecuteTemplate(w, "faq", nil)
}
func offer(w http.ResponseWriter, r *http.Request) {
var o Offer
err := json.NewDecoder(r.Body).Decode(&o)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
err = CheckRecaptcha(ReCaptchaConf.Secret, o.ReCaptchaToken)
if err != nil {
log.Println(err)
return
}
var message string
message = "<b>Azienda</b>: " + o.Azienda
message += "\n<b>Email</b>: " + o.Email
message += "\n<b>Sede di lavoro</b>: " + o.Sede
message += "\n<b>Ruolo</b>: " + o.Ruolo
message += "\n<b>Salario</b>: " + o.Salario
message += "\n<b>Disponibilità</b>: "
if o.FullTime && o.PartTime {
message += "Full-Time/Part-time"
} else if o.FullTime {
message += "Full-Time"
} else {
message += "Part-Time"
}
message += "\n\n<b>Descrizione</b>\n" + o.Descrizione
message += "\n\n<b>Competenze Richieste</b>\n" + o.Competenze
if o.Benefits != "" {
message += "\n\n<b>Benefits</b>\n" + o.Benefits
}
sendOfferToAdminGroup(message)
response := "{\"message\": \"success\"}"
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, response)
}