Exemple #1
0
func HandleLogin(w http.ResponseWriter, r *http.Request) {
	acc, err := data.GetAccountByHandle(r.FormValue("handle"))
	catch(err)
	if acc == nil {
		http.Error(w, "", http.StatusUnauthorized)
		return
	}

	ok, err := acc.CmpPassword(r.FormValue("password"))
	catch(err)
	if !ok {
		http.Error(w, "", http.StatusUnauthorized)
		return
	}

	sess, err := Store.Get(r, "s")
	catch(err)

	sess.Values["me.id"] = acc.Id
	err = sess.Save(r, w)
	catch(err)

	host, _, err := net.SplitHostPort(r.RemoteAddr)
	catch(err)
	err = data.NewActivity(acc, fmt.Sprintf("logged in from %s", host)).Put()
	catch(err)
	hub.Send([]interface{}{"SYNC", "activities"})
}
Exemple #2
0
func ServeAccountByHandle(w http.ResponseWriter, r *http.Request) {
	me, _ := context.Get(r, "me").(*data.Account)
	if me == nil || (me.Level != data.Judge && me.Level != data.Administrator) {
		http.Error(w, "", http.StatusForbidden)
		return
	}

	acc, err := data.GetAccountByHandle(r.FormValue("handle"))
	catch(err)

	if acc == nil {
		http.Error(w, "Not Found", http.StatusNotFound)
		return
	}

	err = json.NewEncoder(w).Encode(acc)
	catch(err)
}