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() }
func (this *ArticleController) Delete() { var ajaxResult models.AjaxResult id := this.Ctx.Input.Param(":id") articleId, err := strconv.Atoi(id) if err != nil { ajaxResult = models.AjaxResult{Success: false} ajaxResult.Error = err.Error() } else { article := new(models.Article) ajaxResult = article.Delete(articleId) } this.Data["json"] = ajaxResult this.ServeJson() }
func (this *ArtilcecategoryController) Delete() { var ajaxResult models.AjaxResult id := this.Ctx.Input.Param(":id") categoryId, err := strconv.Atoi(id) if err != nil { ajaxResult = models.AjaxResult{Success: false} ajaxResult.Error = err.Error() } else { category := new(models.Articlecategory) ajaxResult = category.Delete(categoryId) } this.Data["json"] = ajaxResult this.ServeJson() }
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() }
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()) }