示例#1
0
文件: gplus.go 项目: 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 }`)
}
示例#2
0
文件: tiers.go 项目: 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)
	}
}
示例#3
0
文件: resetpass.go 项目: haste/tiers
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)
}