1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-07-14 10:17:26 +08:00
docker-labs/handlers/new_session.go
Jonathan Leibiusky @xetorthio af9986c0f8 Validates that user is a human.
Add google recaptcha as an initial page before creating any session.
To configure recaptcha there are 2 environment variables that are needed
`GOOGLE_RECAPTCHA_SITE_KEY` and `GOOGLE_RECAPTCHA_SITE_SECRET`.
The code contains development defaults that should be set in production
to real values.
**NOTICE: Development defaults assume that the domain is `localhost`**
2016-11-15 16:53:44 -03:00

27 lines
506 B
Go

package handlers
import (
"fmt"
"log"
"net/http"
"github.com/franela/play-with-docker/services"
)
func NewSession(rw http.ResponseWriter, req *http.Request) {
if !services.IsHuman(req) {
// User it not a human
rw.WriteHeader(http.StatusConflict)
rw.Write([]byte("Only humans are allowed!"))
return
}
s, err := services.NewSession()
if err != nil {
log.Println(err)
//TODO: Return some error code
} else {
http.Redirect(rw, req, fmt.Sprintf("/p/%s", s.Id), http.StatusFound)
}
}