-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute_invitation.go
44 lines (40 loc) · 1.3 KB
/
route_invitation.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
package main
import (
"encoding/json"
"fmt"
"html/template"
"net/http"
. "github.com/logrusorgru/aurora"
)
func StartInvitation(w http.ResponseWriter, r *http.Request) {
fmt.Println(Gray(8-1, "Starting StartInvitation..."))
templates := template.Must(
template.ParseFiles(
"templates/OUT_navbar.html",
"templates/OUT_head.html",
"templates/OUT_footer.html",
"templates/OUT_subscribe.html",
"templates/OUT_invitation.html"))
templates.ExecuteTemplate(w, "layout", nil)
}
func SubmitInvitation(w http.ResponseWriter, r *http.Request) {
fmt.Println(Gray(8-1, "Starting SubmitInvitation..."))
email := r.FormValue("email")
whyjoin := r.FormValue("whyjoin")
whoareyou := r.FormValue("whoareyou")
whichcompanies := r.FormValue("whichcompanies")
anythingelse := r.FormValue("anythingelse")
err := InsertInvitation(email, whyjoin, whoareyou, whichcompanies, anythingelse)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
if err.Error() == "sql: no rows in result set" {
err = SendInvitationEmail(email)
if err == nil {
json.NewEncoder(w).Encode("Success! We have sent you an email")
} else {
json.NewEncoder(w).Encode("Something was wrong, please contact admin")
}
} else {
json.NewEncoder(w).Encode("Something was wrong, please contact admin")
}
}