예제 #1
0
파일: sysconfig.go 프로젝트: deepzz0/goblog
func (this *SysconfigController) updateSitemap(resp *helper.Response) {
	content := this.GetString("content")
	if content == "" {
		resp.Status = RS.RS_params_error
		resp.Tips(helper.WARNING, RS.RS_params_error)
		return
	}
	_, err := os.Stat(models.SiteFile)
	if err != nil && !strings.Contains(err.Error(), "no such file") {
		log.Error(err)
		return
	} else {
		os.Remove(models.SiteFile)
	}
	f, err := os.Create(models.SiteFile)
	if err != nil {
		log.Error(err)
		return
	}
	defer f.Close()
	_, err = f.WriteString(content)
	if err != nil {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|" + err.Error()}
	}
}
예제 #2
0
파일: sysconfig.go 프로젝트: deepzz0/goblog
func (this *SysconfigController) deleteVerify(resp *helper.Response) {
	name := this.GetString("name")
	if name == "" {
		resp.Status = RS.RS_params_error
		resp.Tips(helper.WARNING, RS.RS_params_error)
		return
	}
	models.ManageConf.DelVerification(name)
}
예제 #3
0
파일: sysconfig.go 프로젝트: deepzz0/goblog
func (this *SysconfigController) getSitemap(resp *helper.Response) {
	f, err := os.Open(models.SiteFile)
	if err != nil {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|" + err.Error()}
		return
	}
	defer f.Close()
	data, _ := ioutil.ReadAll(f)
	resp.Data = string(data)
}
예제 #4
0
파일: category.go 프로젝트: deepzz0/goblog
func (this *CategoryController) getCategory(resp *helper.Response) {
	id := this.GetString("id")
	if id != "" {
		if cat := models.Blogger.GetCategoryByID(id); cat != nil {
			b, _ := json.Marshal(cat)
			resp.Data = string(b)
		}
	} else {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|参数错误。"}
	}
}
예제 #5
0
파일: blogroll.go 프로젝트: deepzz0/goblog
func (this *BlogrollController) getBlogroll(resp *helper.Response) {
	id := this.GetString("id")
	if id != "" {
		if br := models.Blogger.GetBlogrollByID(id); br != nil {
			b, _ := json.Marshal(br)
			resp.Data = string(b)
		}
	} else {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|参数错误。"}
	}
}
예제 #6
0
파일: category.go 프로젝트: deepzz0/goblog
func (this *CategoryController) doDeleteTag(resp *helper.Response) {
	id := this.GetString("id")
	if id == "" {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "哦噢。。。|参数错误。"}
		return
	}
	if code := models.Blogger.DelTagByID(id); code != RS.RS_success {
		resp.Status = code
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "抱歉|系统没有找到该标签。"}
		return
	}
}
예제 #7
0
파일: topics.go 프로젝트: deepzz0/goblog
func (this *TopicsController) doDeleteTopic(resp *helper.Response) {
	id, err := this.GetInt("id")
	if err != nil {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "ID错误|走正常途径哦。"}
		return
	}
	err = models.TMgr.DelTopic(int32(id))
	if err != nil {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "删除失败|" + err.Error()}
		return
	}
}
예제 #8
0
파일: topics.go 프로젝트: deepzz0/goblog
func (this *TopicsController) getTopic(resp *helper.Response) {
	id, err := this.GetInt("id")
	if err != nil {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|ID格式不正确。"}
		return
	}
	if topic, err := models.TMgr.LoadTopic(int32(id)); err != nil || topic == nil {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|系统未查询到该文章。"}
		return
	} else {
		resp.Data = topic
	}
}
예제 #9
0
파일: user.go 프로젝트: deepzz0/goblog
func (this *UserController) modifyPasswd(resp *helper.Response) {
	modifypasswdT, err := template.ParseFiles("views/manage/user/modifypasswd.html")
	if err != nil {
		panic(err)
	}
	var buffer bytes.Buffer
	modifypasswdT.Execute(&buffer, nil)
	resp.Data = buffer.String()
}
예제 #10
0
파일: topics.go 프로젝트: deepzz0/goblog
func (this *TopicsController) doDeleteTopics(resp *helper.Response) {
	ids := this.GetString("ids")
	log.Debugf("%s", ids)
	if ids == "" {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "ID错误|走正常途径哦。"}
		return
	}
	sliceID := strings.Split(ids, ",")
	for _, v := range sliceID {
		id, err := strconv.Atoi(v)
		if err != nil {
			log.Error(err)
			resp.Status = RS.RS_failed
			resp.Err = helper.Error{Level: helper.WARNING, Msg: "ID错误|走正常途径哦。"}
			return
		}
		err = models.TMgr.DelTopic(int32(id))
		if err != nil {
			resp.Status = RS.RS_failed
			resp.Err = helper.Error{Level: helper.WARNING, Msg: "删除失败|" + err.Error()}
			return
		}
	}
}
예제 #11
0
파일: trash.go 프로젝트: deepzz0/goblog
func (this *TrashController) doRestore(resp *helper.Response) {
	id, err := this.GetInt32("id")
	if err != nil {
		resp.Status = RS.RS_failed
		resp.Tips(helper.WARNING, RS.RS_params_error)
		return
	}
	if topic := models.TMgr.GetWaitDelTopic(id); topic == nil {
		resp.Status = RS.RS_not_found
		resp.Tips(helper.WARNING, RS.RS_not_found)
		return
	} else {
		if code := models.TMgr.RestoreTopic(topic); code != RS.RS_success {
			resp.Status = code
			resp.Tips(helper.WARNING, code)
			return
		}
	}
}
예제 #12
0
파일: blogroll.go 프로젝트: deepzz0/goblog
func (this *BlogrollController) saveBlogroll(resp *helper.Response) {
	content := this.GetString("json")
	var br models.Blogroll
	err := json.Unmarshal([]byte(content), &br)
	if err != nil {
		log.Error(err)
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "内容错误|要仔细检查哦。"}
		return
	}
	if br.ID == "TEST" {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "内容错误|请修改你需要添加的工具。"}
		return
	}
	if blogroll := models.Blogger.GetBlogrollByID(br.ID); blogroll != nil {
		*blogroll = br
		sort.Sort(models.Blogger.Blogrolls)
	} else {
		br.CreateTime = time.Now()
		models.Blogger.AddBlogroll(&br)
	}
}
예제 #13
0
파일: category.go 프로젝트: deepzz0/goblog
func (this *CategoryController) saveCategory(resp *helper.Response) {
	content := this.GetString("json")
	var cat models.Category
	err := json.Unmarshal([]byte(content), &cat)
	if err != nil {
		log.Error(err)
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "内容错误|要仔细检查哦。"}
		return
	}
	if cat.ID == "TEST" {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "内容错误|请修改你需要添加的分类。"}
		return
	}
	if category := models.Blogger.GetCategoryByID(cat.ID); category != nil {
		*category = cat
		sort.Sort(models.Blogger.Categories)
	} else {
		cat.CreateTime = time.Now()
		models.Blogger.AddCategory(&cat)
	}
}
예제 #14
0
파일: social.go 프로젝트: deepzz0/goblog
func (this *SocialController) saveSocial(resp *helper.Response) {
	content := this.GetString("json")
	var sc models.Social
	err := json.Unmarshal([]byte(content), &sc)
	if err != nil {
		log.Error(err)
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "内容错误|要仔细检查哦。"}
		return
	}
	if sc.ID == "TEST" {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "内容错误|请修改你需要添加的社交。"}
		return
	}
	if social := models.Blogger.GetSocialByID(sc.ID); social != nil {
		*social = sc
		sort.Sort(models.Blogger.Socials)
	} else {
		sc.CreateTime = time.Now()
		models.Blogger.AddSocial(&sc)
	}
}
예제 #15
0
파일: user.go 프로젝트: deepzz0/goblog
func (this *UserController) doModifyInfo(resp *helper.Response) {
	if blogname := this.GetString("blogname"); blogname != "" {
		models.Blogger.BlogName = blogname
	}
	if icon := this.GetString("icon"); icon != "" {
		models.Blogger.HeadIcon = icon
	}
	if introduce := this.GetString("introduce"); introduce != "" {
		models.Blogger.Introduce = introduce
	}
	if sex := this.GetString("sex"); sex != "" {
		models.Blogger.Sex = sex
	}
	if email := this.GetString("email"); email != "" {
		models.Blogger.Email = email
	}
	if address := this.GetString("address"); address != "" {
		models.Blogger.Address = address
	}
	if education := this.GetString("education"); education != "" {
		models.Blogger.Education = education
	}
	resp.Success()
}
예제 #16
0
파일: trash.go 프로젝트: deepzz0/goblog
func (this *TrashController) doDelete(resp *helper.Response) {
	id, err := this.GetInt32("id")
	if err != nil {
		resp.Status = RS.RS_failed
		resp.Tips(helper.WARNING, RS.RS_params_error)
		return
	}
	if topic := models.TMgr.GetWaitDelTopic(id); topic == nil {
		resp.Status = RS.RS_not_found
		resp.Tips(helper.WARNING, RS.RS_not_found)
	} else {
		if err := models.TMgr.ImmeDelTopic(topic); err != nil {
			resp.Status = RS.RS_failed
			resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|" + err.Error()}
			return
		}
	}
}
예제 #17
0
파일: user.go 프로젝트: deepzz0/goblog
func (this *UserController) userInfo(resp *helper.Response) {
	infoT, err := template.ParseFiles("views/manage/user/user.html")
	if err != nil {
		panic(err)
	}
	Map := make(map[string]string)
	Map["BlogName"] = models.Blogger.BlogName
	Map["Icon"] = models.Blogger.HeadIcon
	Map["Introduce"] = models.Blogger.Introduce
	Map["Sex"] = models.Blogger.Sex
	Map["Username"] = models.Blogger.UserName
	Map["Email"] = models.Blogger.Email
	Map["Address"] = models.Blogger.Address
	Map["Education"] = models.Blogger.Education
	Map["LoginTime"] = models.Blogger.LoginTime.Format(helper.Layout_y_m_d_time)
	Map["IP"] = models.Blogger.LoginIp

	var buffer bytes.Buffer
	infoT.Execute(&buffer, Map)
	resp.Data = buffer.String()
}
예제 #18
0
파일: user.go 프로젝트: deepzz0/goblog
func (this *UserController) doModifyPasswd(resp *helper.Response) {
	oldPasswd := this.GetString("old")
	newPasswd := this.GetString("new")
	if oldPasswd == "" || newPasswd == "" {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|参数错误。"}
		return
	}
	if !helper.VerifyPasswd(models.Blogger.PassWord, models.Blogger.UserName, oldPasswd, models.Blogger.Salt) {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|原密码错误。"}
		return
	}
	models.Blogger.ChangePassword(newPasswd)
	resp.Success()
}
예제 #19
0
파일: sysconfig.go 프로젝트: deepzz0/goblog
func (this *SysconfigController) addVerify(resp *helper.Response) {
	name := this.GetString("name")
	content := this.GetString("content")
	if name == "" || content == "" {
		resp.Status = RS.RS_params_error
		resp.Tips(helper.WARNING, RS.RS_params_error)
		return
	}
	verify := models.ManageConf.GetVerification(name)
	if verify != nil {
		resp.Status = RS.RS_duplicate_add
		resp.Tips(helper.WARNING, RS.RS_duplicate_add)
		return
	}
	verify = models.NewVerify()
	verify.Name = name
	verify.Content = content
	models.ManageConf.AddVerification(verify)
}
예제 #20
0
파일: topics.go 프로젝트: deepzz0/goblog
func (this *TopicsController) saveTopic(resp *helper.Response) {
	operate := this.GetString("operate")
	if operate == "" {
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|操作类型错误。"}
		return
	}
	title := this.GetString("title")
	content := this.GetString("content")
	cat := this.GetString("cat")
	tags := this.GetString("tags")
	if title == "" || content == "" || cat == "" {
		log.Debugf("%s,%s,%s,%s, %s", title, content, cat, tags, operate)
		resp.Status = RS.RS_failed
		resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|请检查是否填写完整。"}
		return
	}
	if operate == "new" {
		topic := models.NewTopic()
		if strings.HasSuffix(title, "TAG:aboutme") {
			topic.ID = 1
			topic.Title = strings.Split(title, "-")[0]
		} else {
			if topic.ID == 1 {
				topic.ID = models.NextVal()
			}
			topic.Title = title
		}
		topic.Content = content
		if category := models.Blogger.GetCategoryByID(cat); category == nil {
			resp.Status = RS.RS_failed
			resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|查找不到该分类。"}
			return
		} else {
			topic.CategoryID = category.ID
		}
		if tags == "" {
			topic.TagIDs = make([]string, 0)
		} else {
			sliceTags := strings.Split(tags, ",")
			for _, tag := range sliceTags {
				topic.TagIDs = append(topic.TagIDs, tag)
			}
		}
		if err := models.TMgr.AddTopic(topic); err != nil {
			resp.Status = RS.RS_failed
			resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|" + err.Error()}
			return
		}
	} else {
		id, err := strconv.Atoi(operate)
		if err != nil {
			resp.Status = RS.RS_failed
			resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|修改文章ID解析失败。"}
			return
		}
		if t := models.TMgr.GetTopic(int32(id)); t == nil {
			resp.Status = RS.RS_failed
			resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|系统查找不到该文章ID。"}
			return
		} else {
			t.Title = title
			t.Content = content
			if err := models.TMgr.ModTopic(t, cat, tags); err != nil {
				resp.Status = RS.RS_failed
				resp.Err = helper.Error{Level: helper.WARNING, Msg: "错误|" + err.Error()}
				return
			}
		}
	}
}
예제 #21
0
파일: basedata.go 프로젝트: deepzz0/goblog
func (this *DataController) Base(resp *helper.Response) {
	resp.Data = models.ManageData
}