Exemple #1
0
func (this *BulletinAdminEdit) Post() {
	form := bulletin.BulletinAdminForm{Id: int(this.object.Id)}
	if this.ValidFormSets(&form) == false {
		return
	}

	// get changed field names
	changes := utils.FormChanges(&this.object, &form)

	url := fmt.Sprintf("/admin/bulletin/%d", this.object.Id)

	// update changed fields only
	if len(changes) > 0 {
		form.SetToBulletin(&this.object)
		if err := models.UpdateById(this.object.Id, this.object, models.Obj2Table(changes)...); err == nil {
			this.FlashRedirect(url, 302, "UpdateSuccess")
			return
		} else {
			log.Error(err)
			this.Data["Error"] = err
		}
	} else {
		this.Redirect(url, 302)
	}
}
Exemple #2
0
func (form *PostForm) UpdatePost(post *models.Post, user *models.User) error {
	changes := utils.FormChanges(post, form)
	if len(changes) == 0 {
		return nil
	}
	utils.SetFormValues(form, post)
	post.CategoryId = form.Category
	post.TopicId = form.Topic
	for _, c := range changes {
		if c == "Content" {
			post.ContentCache = utils.RenderMarkdown(form.Content)
			changes = append(changes, "ContentCache")
		}
	}

	// update last edit author
	if post.LastAuthorId != user.Id {
		post.LastAuthorId = user.Id
		changes = append(changes, "LastAuthor")
	}

	changes = append(changes, "Updated")

	return models.UpdateById(post.Id, post, models.Obj2Table(changes)...)
}
Exemple #3
0
// view for update object
func (this *PostAdminEdit) Post() {
	form := this.GetForm(false)
	if this.ValidFormSets(&form) == false {
		return
	}

	// get changed field names
	changes := utils.FormChanges(&this.object, &form)

	url := fmt.Sprintf("/admin/post/%d", this.object.Id)

	// update changed fields only
	if len(changes) > 0 {
		//fix the bug of category not updated
		changes = append(changes, "Category")
		form.SetToPost(&this.object)
		if err := models.UpdateById(this.object.Id, this.object, models.Obj2Table(changes)...); err == nil {
			this.FlashRedirect(url, 302, "UpdateSuccess")
			return
		} else {
			log.Error(err)
			this.Data["Error"] = err
		}
	} else {
		this.Redirect(url, 302)
	}
}
Exemple #4
0
// Active implemented check Email actice code.
func (this *RegisterActive) Get() {
	// no need active
	if this.CheckActiveRedirect(false) {
		return
	}

	code := this.Params().Get(":code")

	var user models.User

	if auth.VerifyUserActiveCode(&user, code) {
		user.IsActive = true
		user.Rands = models.GetUserSalt()
		if err := models.UpdateById(user.Id, user, models.Obj2Table([]string{"IsActive", "Rands", "Updated"})...); err != nil {
			log.Error("Active: user Update ", err)
		}
		if this.IsLogin {
			this.User = user
		}

		this.Redirect("/active/success", 302)

	} else {
		this.Data["Success"] = false
	}

	this.Render("auth/active.html", this.Data)
}