Exemplo n.º 1
0
func ShowTeachers(w http.ResponseWriter, req *http.Request) {
	req.ParseForm()

	ok, err := serv.CheckToken(req.FormValue("token"))
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	} else if !ok {
		http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
		return
	}

	teachers, err := serv.ShowTeachers()
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	w.Write(pgpub.CreateQueryJson(teachers))
}
Exemplo n.º 2
0
func WebsocketConnect(w http.ResponseWriter, req *http.Request) {
	req.ParseForm()

	oauthToken := req.FormValue("token")
	ok, err := serv.CheckToken(oauthToken)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	} else if !ok {
		http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
		return
	}

	uid, err := serv.GetUidFromToken(oauthToken)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	err = im.EstablishConnect(uid, w, req)
}