Exemplo n.º 1
0
func (us UserService) SyncHeartbeats(currentUser models.User, r render.Render, req *http.Request) {
	currentUser.IsSyncingWakaTime = true
	utils.ORM.Save(&currentUser)
	go currentUser.PullNewestHeartbeats()

	if req.Referer() != "" {
		r.Redirect(req.Referer())
	} else {
		r.Redirect("/dashboard")
	}
}
Exemplo n.º 2
0
func (us UserService) Update(user models.User, req *http.Request, r render.Render) {
	var oldUser models.User
	err := utils.ORM.First(&oldUser, user.Id).Error
	if err != nil {
		r.HTML(500, "user/edit", nil)
		return
	}

	err = req.ParseForm()
	if err != nil {
		r.Error(5000)
	}
	structVal := structs.Map(user)
	changes := utils.GetDiffFormValues(req.PostForm, structVal)
	utils.Log.Debug("changed: %v", changes)
	err = utils.ORM.Table("users").Updates(changes).Error
	if err != nil {
		r.HTML(403, "user/edit", nil)
		return
	}
	var curUser models.User
	utils.ORM.First(&curUser, user.Id)

	if oldUser.WakaTimeApiKey != curUser.WakaTimeApiKey && curUser.WakaTimeApiKey != "" {
		utils.Log.Debug("Pulling down wakatime heartbeats")
		curUser.IsSyncingWakaTime = true
		utils.ORM.Save(&curUser)
		go curUser.PullNewestHeartbeats()
	}

	if strings.Contains(req.Referer(), "/settings/edit") {
		r.Redirect(req.Referer())
	} else {
		r.Redirect("/settings/edit")
	}
}