Exemplo n.º 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)
}
Exemplo n.º 2
0
func ListProfile(c *gin.Context) {
	conn := store.New(c)

	prof_list := make([]Profile, 0)
	out_list := make([]ProfileOut, 0)
	conn.List(&prof_list)

	var prof Profile

	for _, prof = range prof_list {
		if auth.IsAuthorized(c, prof.Consti) {
			var pout_t ProfileOut
			det_list := &datastore.PropertyList{}
			conn.PropListGet(det_list, prof.Parent)
			pout_t.Details = PropertyListToMap(det_list)
			pout_t.Details["id"] = prof.Parent.IntID()
			pout_t.Comments = prof.Comments
			pout_t.Surveys = prof.Surveys
			pout_t.Consti = prof.Consti
			pout_t.Id = prof.Id
			pout_t.Meta = prof.Meta
			pout_t.Likes = prof.Likes
			pout_t.UnLikes = prof.UnLikes
			out_list = append(out_list, pout_t)
		}

	}

	auth.SessionSave(c)
	c.JSON(http.StatusOK, out_list)
}
Exemplo n.º 3
0
func GetProfile(c *gin.Context) {
	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)

	var pout_t ProfileOut
	det_list := &datastore.PropertyList{}
	conn.PropListGet(det_list, prof_in.Parent)
	pout_t.Details = PropertyListToMap(det_list)
	pout_t.Details["id"] = prof_in.Parent.IntID()
	pout_t.Comments = prof_in.Comments
	pout_t.Surveys = prof_in.Surveys
	pout_t.Consti = prof_in.Consti
	pout_t.Id = prof_in.Id
	pout_t.Meta = prof_in.Meta
	pout_t.Likes = prof_in.Likes
	pout_t.UnLikes = prof_in.UnLikes

	c.JSON(http.StatusOK, pout_t)
}
Exemplo n.º 4
0
func VerifyVolunteerRequest(c *gin.Context, user *auth.User) bool {
	r := c.Request
	conn := store.New(c)
	conn.Get(user)
	ctx := appengine.NewContext(r)
	session := auth.GetSession(c)
	log.Debugf(ctx, fmt.Sprintf("details %#v", session))
	req_id := session.Get("vol_req_id")
	log.Debugf(ctx, fmt.Sprintf("Vol_Req_id %#v", req_id))
	log.Debugf(ctx, "Vol_Req_id %v", req_id)
	if req_id != nil {
		session.Delete("vol_req_id")
		session.Save()
		if req_id == user.Temp_Req_Id {
			user.Role = "volunteer"
			user.Active = "false"
			conn.Add(user)
			NotifyAdmin(c, user)
			return true
		}
	} else {
		log.Debugf(ctx, "Vol_Req_id notfound")
		return false
	}
	return false
}
Exemplo n.º 5
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})

}
Exemplo n.º 6
0
Arquivo: auth.go Projeto: sankark/kyp
func UpdateUser(c *gin.Context, user *User) {
	conn := store.New(c)
	e_user := &User{Email: user.Email}
	conn.Get(e_user)
	e_user.Token = user.Token
	conn.Add(e_user)

}
Exemplo n.º 7
0
Arquivo: auth.go Projeto: sankark/kyp
func GetUser(c *gin.Context) User {
	user := SessionGet(c, "internal")
	if user != nil {
		return user.(User)
	}
	conn := store.New(c)
	user2 := User{Email: GetUserId(c)}
	conn.Get(&user2)
	SessionSet(c, "internal", user2)
	return user2
}
Exemplo n.º 8
0
func UpdateUser(c *gin.Context) {
	if auth.IsAdmin(c) {
		user := &auth.User{}
		c.BindJSON(user)
		conn := store.New(c)
		conn.Add(user)
		c.JSON(http.StatusOK, gin.H{"status": "success", "user": user})
	} else {
		c.JSON(http.StatusOK, gin.H{"msg": "auth required"})
	}
}
Exemplo n.º 9
0
func ListUser(c *gin.Context) {
	if auth.IsAdmin(c) {
		users := make([]auth.User, 0)
		conn := store.New(c)
		conn.List(&users)

		c.JSON(http.StatusOK, users)
	} else {
		c.JSON(http.StatusOK, gin.H{"msg": "auth required"})
	}
}
Exemplo n.º 10
0
func GetUser(c *gin.Context) {
	if auth.IsAdmin(c) {
		user_id := c.Param("user_id")
		user := &auth.User{}
		user.Email = user_id
		conn := store.New(c)
		conn.Get(user)
		c.JSON(http.StatusOK, gin.H{"status": "success", "user": user})
	} else {
		c.JSON(http.StatusOK, gin.H{"msg": "auth required"})
	}
}
Exemplo n.º 11
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"})
	}
}
Exemplo n.º 12
0
Arquivo: auth.go Projeto: sankark/kyp
func AddUser(c *gin.Context, user *User) {
	aecontext := appengine.NewContext(c.Request)
	conn := store.New(c)
	resp := conn.Get(user)
	if resp.Err_msg != "" {
		user.Active = "false"
		if user.Role == "" {
			user.Role = "support"
		}
		user.Likes = make([]string, 0)
		user.Unlikes = make([]string, 0)
		resp := conn.Add(user)
		if resp.Err_msg != "" {
			log.Debugf(aecontext, "user not stored due to %s", resp.Err_msg)
		}
	}

}
Exemplo n.º 13
0
func PutSampleProfile(c *gin.Context) {

	conn := store.New(c)
	status := http.StatusOK

	if auth.IsAuthorized(c, "admin") {
		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)
		det_list := &datastore.PropertyList{}
		conn.PropListGet(det_list, det_key)
		prof_in := &Profile{Id: prof_id, Parent: det_key}

		conn.Get(prof_in)

		for _, consti := range kyp.GetConstis() {
			prof_in.Id = 0
			prof_in.Consti = consti
			prof_in.Comments = make([]Comment, 0)
			prof_in.Likes = 0
			prof_in.UnLikes = 0
			prof_in.Status = "sample"
			s_det_key := conn.DatastoreKeyWithKind("ProfileDetails", 0)
			det_key = conn.PropListPut(det_list, s_det_key)
			prof_in.Parent = det_key
			for i, _ := range prof_in.Surveys {
				prof_in.Surveys[i].Id = uuid.NewV4().String()
				prof_in.Surveys[i].Prof_Id = ""
				prof_in.Surveys[i].Det_Id = ""
				prof_in.Surveys[i].Likes = 0
				prof_in.Surveys[i].UnLikes = 0
			}
			conn.Add(prof_in)

		}

	} else {
		status = http.StatusUnauthorized
	}

	auth.SessionSave(c)
	c.JSON(status, gin.H{"msg": "succesfully loaded"})

}
Exemplo n.º 14
0
func DeleteProfile(c *gin.Context) {

	conn := store.New(c)
	status := http.StatusOK
	var resp store.Response
	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)

	if auth.IsAuthorized(c, prof_in.Consti) {
		log.Debugf(conn.Context, fmt.Sprintf("profiles %#v", prof_in))
		resp = conn.Remove(conn.Goon.Key(prof_in))
		resp = conn.Remove(prof_in.Parent)

	} else {
		status = http.StatusUnauthorized
	}

	auth.SessionSave(c)
	c.JSON(status, resp)
}
Exemplo n.º 15
0
Arquivo: app.go Projeto: sankark/kyp
func getStore(c *gin.Context) *store.Connection {
	return store.New(c)
}
Exemplo n.º 16
0
func PutProfile(c *gin.Context) {

	conn := store.New(c)
	status := http.StatusOK

	prof_out := &ProfileOut{}
	c.BindJSON(prof_out)

	var resp store.Response
	keys := make(map[string]int64)

	if auth.IsAuthorized(c, prof_out.Consti) {
		det_id := NumberToInt(prof_out.Details["id"])
		det_key := conn.DatastoreKeyWithKind("ProfileDetails", det_id)
		det_list := &datastore.PropertyList{}
		log.Debugf(conn.Context, fmt.Sprintf("before conv %#v", det_list))
		det_list = MapToPropertyList(prof_out.Details)
		log.Debugf(conn.Context, fmt.Sprintf("after conv %#v", det_list))
		det_key = conn.PropListPut(det_list, det_key)
		log.Debugf(conn.Context, fmt.Sprintf("details %#v", det_list))

		prof_in := &Profile{Id: prof_out.Id, Parent: det_key}
		conn.Get(prof_in)
		prof_in.Parent = det_key
		prof_in.Comments = prof_out.Comments
		prof_in.Surveys = prof_out.Surveys
		if prof_in.Comments == nil {
			prof_in.Comments = make([]Comment, 0)
		}
		if prof_in.Surveys == nil {
			prof_in.Surveys = make([]Survey, 0)
		} else {
			for i, surv := range prof_in.Surveys {
				if surv.Id == "" {
					prof_in.Surveys[i].Id = uuid.NewV4().String()
				}
			}
		}
		prof_in.Consti = prof_out.Consti
		prof_in.Meta = prof_out.Meta
		resp = conn.Add(prof_in)

		keys["prof_id"] = resp.Data.(*datastore.Key).IntID()
		keys["det_id"] = det_key.IntID()

		for i, surv := range prof_in.Surveys {
			if surv.Prof_Id == "" {
				t_p_id := strconv.FormatInt(keys["prof_id"], 10)
				t_det_id := strconv.FormatInt(keys["det_id"], 10)
				prof_in.Surveys[i].Prof_Id = t_p_id
				prof_in.Surveys[i].Det_Id = t_det_id
			}
		}
		conn.Add(prof_in)
		log.Debugf(conn.Context, fmt.Sprintf("%#v", prof_in))

	} else {
		status = http.StatusUnauthorized
	}

	auth.SessionSave(c)
	c.JSON(status, keys)

}