Example #1
0
func register(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	req := registerReq{}

	if err := util.ParseJSON(r.Body, w, &req); err != nil {
		return
	}

	_, msg, err := models.NewUser(req.Email, req.Password)

	if err != nil {
		w.WriteHeader(500)
		return
	}

	if len(msg) > 0 {
		util.JSONResponse(w, validate.ValidationMsgsToJSON(msg), 400)
		return
	}

	w.WriteHeader(201)
}
Example #2
0
func updateUser(w http.ResponseWriter, r *http.Request, u *models.User) {
	defer r.Body.Close()

	req := registerReq{}

	if err := util.ParseJSON(r.Body, w, &req); err != nil {
		return
	}

	msg, err := u.Update(req.Email, req.Password)

	if err != nil {
		w.WriteHeader(500)
		return
	}

	if len(msg) > 0 {
		util.JSONResponse(w, validate.ValidationMsgsToJSON(msg), 400)
		return
	}

	util.JSONResponse(w, u, 200)
}