Exemple #1
0
func (this *HomeController) SavePassword() {
	var ajaxResult models.AjaxResult
	var data map[string]interface{}
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &data)
	if err != nil {
		fmt.Println(err)
	}

	oldpwd := data["oldpwd"].(string)
	newpwd := data["newpwd"].(string)

	if utils.ToMD5([]byte(oldpwd)) != this.User.Password {
		ajaxResult.Success = false
		ajaxResult.Error = "原密码输入错误!"
	} else {
		user := new(models.User)
		user.Id = this.User.Id
		user.Username = this.UserName
		user.Password = utils.ToMD5([]byte(newpwd))
		ajaxResult = user.SaveUserInfo()
	}

	this.Data["json"] = ajaxResult
	this.ServeJson()
}
Exemple #2
0
func (this *PageController) Save() {
	ajaxResult := new(models.AjaxResult)
	page := new(models.Page)
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &page)
	if err != nil {
		ajaxResult.Error = err.Error()
	} else {
		err = page.Save()
		if err != nil {
			ajaxResult.Error = err.Error()
		} else {
			ajaxResult.Success = true
			ajaxResult.Msg = &page
		}
	}

	this.Data["json"] = ajaxResult
	this.ServeJson()
}
func (this *ArtilcecategoryController) Save() {
	ajaxResult := new(models.AjaxResult)
	category := new(models.Articlecategory)
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &category)
	if err != nil {
		ajaxResult.Error = err.Error()
	} else {
		err = category.Save()
		if err != nil {
			ajaxResult.Error = err.Error()
		} else {
			ajaxResult.Success = true
			ajaxResult.Msg = &category
		}
	}

	this.Data["json"] = ajaxResult
	this.ServeJson()
}
Exemple #4
0
func (this *LoginController) Post() {
	username := this.GetString("username")
	password := this.GetString("password")

	ajaxResult := new(models.AjaxResult)

	user := new(models.User)
	err := user.GetUserName(username)
	fmt.Println(user)
	if err != nil {
		ajaxResult.Error = "帐号不存在!"
	} else {
		if user.Password != utils.ToMD5([]byte(password)) {
			ajaxResult.Error = "密码输入错误!"
		} else {
			ajaxResult.Success = true
			this.SetSession("adminAuthen", utils.ToJson(user))
		}
	}

	this.Ctx.WriteString(ajaxResult.ToString())
}