func suggestion(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) var info string if r.FormValue("ContentString") != "" { if recaptcha.Validate(r, r.RemoteAddr, r.FormValue("recaptcha_challenge_field"), r.FormValue("recaptcha_response_field")) == true { var post PostSuggestion post.Username = r.FormValue("Username") post.Content = []byte(r.FormValue("ContentString")) post.Timestamps = time.Now().Local() datastore.Put(c, datastore.NewIncompleteKey(c, "PostSuggestion", nil), &post) info = "Böylesine Muazzam Bir Bilgi Önerdiğin İçin Çok Teşekkür Ediyorum." } else { info = "Captcha Kodu Yanlış! Lütfen Tekrar Dene!" } } type PassedData struct { Info string } passedData := PassedData{ Info: info, } passedTemplate := new(bytes.Buffer) template.Must(template.ParseFiles("templates/suggestion.html")).Execute(passedTemplate, passedData) render.Render(w, r, passedTemplate) }
// Contact page func contact(w http.ResponseWriter, r *http.Request) { var status template.HTML status = "" // Parse the post data submit, subject, content, recaptcha_challenge_field, recaptcha_response_field, sender := r.FormValue("submit"), r.FormValue("subject"), r.FormValue("content"), r.FormValue("recaptcha_challenge_field"), r.FormValue("recaptcha_response_field"), r.FormValue("sender") // Check if there is content if subject != "" && content != "" && recaptcha_challenge_field != "" && recaptcha_response_field != "" && sender != "" { // Check the captcha if (recaptcha.Validate(r, r.RemoteAddr, recaptcha_challenge_field, recaptcha_response_field)) == true { c := appengine.NewContext(r) msg := &mail.Message{ Sender: "appengine@" + appengine.AppID(c) + ".appspotmail.com", To: []string{"*****@*****.**"}, Subject: subject, Body: sender + "sent you a mail:" + content, } if err := mail.Send(c, msg); err != nil { c.Errorf("Couldn't send email: %v", err) } status = `<div class="alert alert-success"> <a class="close" data-dismiss="alert">×</a> <strong>Woahhh!</strong> You just sent me a mail :-) </div>` } else { status = `<div class="alert alert-error"> <a class="close" data-dismiss="alert">×</a> <strong>Oops!</strong> The captcha was wrong - just try it again! </div>` } } else { if submit == "submit" { status = `<div class="alert alert-error"> <a class="close" data-dismiss="alert">×</a> <strong>Oops!</strong> You should enter all the required fields! </div>` } } passedTemplate := new(bytes.Buffer) template.Must(template.ParseFiles("statuscode.ch/contact/templates/contact.html")).Execute(passedTemplate, status) render.Render(w, r, passedTemplate) }