Exemplo n.º 1
0
Arquivo: gplus.go Projeto: haste/tiers
func GPlusHandler(w http.ResponseWriter, r *http.Request) {
	code, _ := ioutil.ReadAll(r.Body)
	accessToken, idToken, err := exchange(string(code))

	if err != nil {
		fmt.Println(err)
	}

	gplusid, _ := decodeIdToken(idToken)
	u, err := model.GetUserByGPlusId(gplusid)
	if err != nil {
		u = model.CreateGPlusUser(gplusid, accessToken)
	} else {
		model.UpdateGPlusToken(u.Id, accessToken)
	}

	session.Set(w, r, u.Id)
	fmt.Fprintln(w, `{ "success": true }`)
}
Exemplo n.º 2
0
Arquivo: tiers.go Projeto: haste/tiers
func LoginHandler(w http.ResponseWriter, r *http.Request) {
	email, password := r.PostFormValue("email"), r.PostFormValue("password")

	u, err := model.SignInUser(email, password)
	switch {
	case err == model.ErrUserNotFound:
		fmt.Fprintln(w, "Invalid username or password.")
		return
	}

	session.Set(w, r, u.Id)

	numProfiles := model.GetNumProfiles(u.Id)
	numQueued := model.GetNumQueuedProfiles(u.Id)
	switch {
	case numProfiles == 0 && numQueued == 0:
		http.Redirect(w, r, "/upload", 302)
	default:
		http.Redirect(w, r, "/", 302)
	}
}
Exemplo n.º 3
0
func ResetPassHandler(w http.ResponseWriter, r *http.Request) {
	password := r.PostFormValue("password")
	if len(password) == 0 {
		fmt.Fprintf(w, "Password can't be empty.")
		return
	}

	token := mux.Vars(r)["token"]
	user_id := model.ValidateResetToken(token)
	if user_id == 0 {
		fmt.Fprintf(w, "Invalid or expired token...")
		return
	}

	model.DeleteResetToken(token)
	model.SetUserPassword(user_id, password)

	session.Set(w, r, user_id)

	http.Redirect(w, r, "/", 302)
}