예제 #1
0
파일: admin.go 프로젝트: elvin-du/myblog
/*
管理员注册
*/
func (this *Admin) RegisterHandler(rw http.ResponseWriter, req *http.Request) {
	logger.Infoln("entered Register()")
	switch req.Method {
	case "GET":
		t, err := template.ParseFiles("views/admin/register.html")
		if nil != err {
			logger.Errorln(err)
			return
		}
		if err = t.Execute(rw, nil); nil != err {
			logger.Errorln(err)
			return
		}
	case "POST":
		req.ParseForm()
		name := req.FormValue("username")
		psw := req.FormValue("password")
		confirmPsw := req.FormValue("confirm_password")
		if psw != confirmPsw {
			//TBD
		}
		model := models.Model{}
		model.AddUser(name, psw)
		http.Redirect(rw, req, "/", http.StatusFound)
	}
}
예제 #2
0
파일: admin.go 프로젝트: elvin-du/myblog
func (this *Admin) AddBlogHandler(rw http.ResponseWriter, req *http.Request) {
	logger.Infoln("entered AddBlogHandler()")
	req.ParseForm()
	//name,err :=CheckCookie(r)
	//if err != nil{
	//	log.Println(err)
	//	http.Redirect(w,r,"/", http.StatusFound)
	//	return
	//	}
	switch req.Method {
	case "GET":
		t, err := template.ParseFiles("views/admin/add_blog.html")
		if nil != err {
			logger.Errorln(err)
			return
		}
		//查询博客标签
		m := models.Model{}
		tags, err := m.QueryTags()
		if nil != err {
			logger.Errorln(err)
		}
		//为了使用查询出来的博客标签,格式化查询结果
		type tmp struct {
			Tags []models.Tag
		}
		tmp2 := tmp{tags}
		if err = t.Execute(rw, tmp2); nil != err {
			logger.Errorln(err)
			return
		}
	case "POST":
		title := req.FormValue("title")
		content := req.FormValue("content")
		tag := req.FormValue("tag")
		tagId, _ := strconv.Atoi(tag) //从前端返回的是tag的ID
		logger.Debugln("title: ", title)
		logger.Debugln("content: ", content)
		logger.Debugln("arcticleTag: ", tag)

		model := models.Model{}
		model.AddBlog(title, content, tagId)
		http.Redirect(rw, req, "/", http.StatusFound)
	}
}
예제 #3
0
func CheckNamePsw(name, psw string) error {
	medol := models.Model{}
	return medol.CheckNamePsw(name, psw)
}