Exemplo n.º 1
0
func DeleteUser(ctx *middleware.Context, w http.ResponseWriter, r *http.Request) (interface{}, error) {
	var u user.User
	var err error
	u.ID = bson.ObjectIdHex(r.URL.Query().Get("id"))
	err = u.Delete()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return u, err
	}
	return u, nil
}
Exemplo n.º 2
0
func CreateUser(ctx *middleware.Context, w http.ResponseWriter, r *http.Request) (interface{}, error) {
	var u user.User
	err := json.NewDecoder(r.Body).Decode(&u)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return u, err
	}
	err = u.Create()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return u, err
	}
	return u, nil
}
Exemplo n.º 3
0
func (t TokenValidation) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	var u user.User
	u.Token = r.Header.Get("Token")

	if u.Token == "" {
		http.Error(w, "No token", http.StatusInternalServerError)
		return
	}
	u.Token = strings.TrimPrefix(strings.TrimSpace(u.Token), "Bearer: ")
	_, err := user.VerifyToken(u.Token)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	err = u.Authorize()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}