示例#1
0
func AddComment(c *gin.Context) {

	var prof_in *Profile
	status := http.StatusOK
	if auth.IsAuthenticated(c) {

		conn := store.New(c)
		var comment Comment
		c.BindJSON(&comment)

		prof_id, _ := strconv.ParseInt(comment.Prof_Id, 10, 64)
		det_id, _ := strconv.ParseInt(comment.Det_Id, 10, 64)
		det_key := conn.DatastoreKeyWithKind("ProfileDetails", det_id)
		prof_in = &Profile{Id: prof_id, Parent: det_key}
		conn.Get(prof_in)

		comment.Id = uuid.NewV4().String()
		comment.Time = time.Now().Format("2006-01-02 15-04-05")
		comment.Author = auth.GetUser(c).Name
		prof_in.Comments = append(prof_in.Comments, comment)
		conn.Add(prof_in)

		status = http.StatusOK

	} else {
		auth.SessionSave(c)
		auth.Login(c)
	}

	c.JSON(status, prof_in.Comments)
}
示例#2
0
func AddLikes(c *gin.Context) {
	status := http.StatusOK
	var likes int64
	authenticated := "false"
	if auth.IsAuthenticated(c) {
		authenticated = "true"
		conn := store.New(c)
		prof_id, _ := strconv.ParseInt(c.Param("prof_id"), 10, 64)
		det_id, _ := strconv.ParseInt(c.Param("det_id"), 10, 64)
		det_key := conn.DatastoreKeyWithKind("ProfileDetails", det_id)
		prof_in := &Profile{Id: prof_id, Parent: det_key}

		conn.Get(prof_in)

		user := auth.GetUser(c)
		like_type := c.Query("type")
		like_id := c.Query("like_id")
		var incr = 1

		if auth.IsLiked(c, like_id) {
			incr = -1
			sort.Strings(user.Likes)
			i := sort.SearchStrings(user.Likes, like_id)
			user.Likes = append(user.Likes[:i], user.Likes[i+1:]...)
		} else {
			user.Likes = append(user.Likes, like_id)
		}
		conn.Goon.RunInTransaction(func(Goon *goon.Goon) error {
			Goon.Put(&user)
			return nil
		}, nil)
		if like_type == "profile" {
			prof_in.Likes += int64(incr)
			likes = prof_in.Likes
		}
		if like_type == "comment" {
			for i, comm := range prof_in.Comments {
				if comm.Id == like_id {
					prof_in.Comments[i].Likes += int64(incr)
					likes = prof_in.Comments[i].Likes
				}
			}
		}
		if like_type == "survey" {
			for i, surv := range prof_in.Surveys {
				if surv.Id == like_id {
					prof_in.Surveys[i].Likes += int64(incr)
					likes = prof_in.Surveys[i].Likes
				}
			}
		}
		conn.Add(prof_in)
		authenticated = "true"
		status = http.StatusOK

	}
	c.JSON(status, gin.H{"authenticated": authenticated, "likes": likes})

}
示例#3
0
func SendVolunteerRequest(c *gin.Context) {
	if auth.IsAuthenticated(c) {
		user := &auth.User{}
		conn := store.New(c)
		c.BindJSON(user)
		user.Temp_Req_Id = uuid.NewV4().String()
		user.Role = "pending"
		user.Ref_Email = auth.GetUser(c).Email
		conn.Add(user)
		SendEmailVolunteer(c, user)
		c.JSON(http.StatusOK, gin.H{"msg": "send email to volunteer"})
	} else {
		c.JSON(http.StatusOK, gin.H{"msg": "auth required"})
	}
}
示例#4
0
文件: facebook.go 项目: sankark/kyp
func RefreshFacebookTokens(c *gin.Context) {
	if auth.IsAuthenticated(c) {
		user := auth.GetUser(c)
		if user.LoginType == "facebook" {
			aecontext := appengine.NewContext(c.Request)
			conf := FBConfig()
			toksource := conf.TokenSource(aecontext, &user.Token)
			sourceToken := oauth2.ReuseTokenSource(&user.Token, toksource)
			client := oauth2.NewClient(aecontext, sourceToken)
			client.Get("...")
			t, _ := sourceToken.Token()
			user.Token = *t
			auth.UpdateUser(c, &user)
			log.Debugf(aecontext, fmt.Sprintf("refresh tokens %#v", t))
		}
	}
}
示例#5
0
文件: app.go 项目: sankark/kyp
func GetUser(c *gin.Context) {
	user := auth.GetUser(c)
	c.JSON(http.StatusOK, gin.H{"user": user})

}