Пример #1
0
func loginHandler(w http.ResponseWriter, r *http.Request) {
	coms := communicator.New(w)

	username := r.FormValue("username")
	password := r.FormValue("password")

	u, err := models.FetchUser("username", username)
	if err != nil {
		coms.Error("Unable to login user")
		return
	}

	if err := u.Login(password); err != nil {
		coms.Errorf("Unable to login %v", err)
		return
	}

	claims := make(map[string]interface{})
	claims["id"] = u.ID
	claims["exp"] = time.Now().Add(time.Hour * 72).Unix()

	ts, err := restrict.Token(claims)
	if err != nil {
		coms.Fail("Failure signing the token")
		sentry.CaptureError(err, nil)
		return
	}

	coms.With(ts).OK()
}
Пример #2
0
func secretHandler(w http.ResponseWriter, r *http.Request, t *jwt.Token) {
	coms := communicator.New(w)

	u, err := models.FetchUser("id", t.Claims["id"])
	if err != nil {
		coms.Error("That user does not exist!")
		return
	}

	coms.With(u).OK()
}