Exemple #1
0
func (this *AvatarRouter) Get() error {
	this.Data["IsUserSettingPage"] = true
	//need login
	if this.CheckLoginRedirect() {
		return nil
	}

	form := auth.UserAvatarForm{}
	form.SetFromUser(&this.User)
	this.SetFormSets(&form)
	return this.Render("settings/user_avatar.html", this.Data)
}
Exemple #2
0
func (this *AvatarUploadRouter) Post() {
	this.Data["IsUserSettingPage"] = true
	//need login and active
	if this.CheckLoginRedirect() {
		return
	}

	// get file object
	file, handler, err := this.Ctx.Req().FormFile("avatar")
	if err != nil {
		return
	}
	defer file.Close()
	mime := handler.Header.Get("Content-Type")
	if err := auth.UploadUserAvatarToQiniu(file, handler.Filename, mime, setting.QiniuAvatarBucket, &this.User); err != nil {
		return
	}

	userAvatarForm := auth.UserAvatarForm{}
	userAvatarForm.SetFromUser(&this.User)
	this.SetFormSets(&userAvatarForm)
	this.FlashRedirect("/settings/avatar", 302, "AvatarUploadSuccess")
	this.Render("settings/user_avatar.html", this.Data)
}