Beispiel #1
0
func (c *WptController) Search() {
	if c.Ctx.Input.IsGet() {
		beego.Debug("WptController Search Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("WptController Search Post")
	}
	search := c.Input().Get("search")
	if len(search) != 0 {
		objs, err := models.GetAllWptLike(search)
		if err != nil {
			beego.Error(err)
		}
		beego.Debug("Search :", objs)
		c.Data["Objs"] = objs
	} else {
		objs, err := models.GetAllWpt()
		if err != nil {
			beego.Error(err)
		}
		c.Data["Objs"] = objs

	}

	c.TplName = "wptsearch.html"
}
Beispiel #2
0
func parseDocs() {
	root, err := ParseDocs("docs/zh-CN")
	if err != nil {
		beego.Error(err)
	}

	if root != nil {
		docs["zh-CN"] = root
	}

	root, err = ParseDocs("docs/en-US")
	if err != nil {
		beego.Error(err)
	}

	if root != nil {
		docs["en-US"] = root
	}

	root, err = ParseDocs("docs/ru-RU")
	if err != nil {
		beego.Error(err)
	}

	if root != nil {
		docs["ru-RU"] = root
	}
}
Beispiel #3
0
// crawlDoc fetchs package from VCS.
func crawlDoc(path string, etag string, views int64) (pdoc *Package, err error) {
	// I have no idea what the f**k does this mean.
	if i := strings.Index(path, "/libgo/go/"); i > 0 && utils.IsGoRepoPath(path[i+len("/libgo/go/"):]) {
		// Go Frontend source tree mirror.
		pdoc = nil
		err = errors.New("Go Frontend source tree mirror.")
	} else {
		var pdocNew *Package
		pdocNew, err = getRepo(httpClient, path, etag)

		// For timeout logic in client.go to work, we cannot leave connections idling. This is ugly.
		httpTransport.CloseIdleConnections()

		if err != errNotModified && pdocNew != nil {
			pdoc = pdocNew
			pdoc.Views = views
		}
	}

	switch {
	case err == nil:
		pdoc.Views = views
		if err = SaveProject(pdoc); err != nil {
			beego.Error("doc.SaveProject(", path, "):", err)
		}
	case isNotFound(err):
		// We do not need to delete standard library, so here is fine.
		if err = models.DeleteProject(path); err != nil {
			beego.Error("doc.DeleteProject(", path, "):", err)
		}
	}
	return pdoc, err
}
Beispiel #4
0
func (c *ApiController) AddGroup() {
	var (
		err    error
		stores []string
		racks  int
		copys  int
		res    map[string]interface{} = make(map[string]interface{})
	)

	res["success"] = true

	stores = strings.Split(c.GetString("stores"), ",")

	if racks, err = c.GetInt("racks"); err != nil {
		beego.Error(err)
		c.responseError(err)
	}

	if copys, err = c.GetInt("copys"); err != nil {
		beego.Error(err)
		c.responseError(err)
	}

	if err = ops.OpsManager.AddGroup(stores, racks, copys); err != nil {
		beego.Error(err)
		c.responseError(err)
	}

	c.Data["json"] = res
	c.ServeJSON()
}
Beispiel #5
0
func updateImportInfo(q *qbs.Qbs, path string, pid int, add bool) {
	// Save package information.
	info := new(PkgInfo)
	err := q.WhereEqual("path", path).Find(info)
	if err == nil {
		// Check if pid exists in this project.
		i := strings.Index(info.ImportPid, "$"+strconv.Itoa(pid)+"|")
		switch {
		case i == -1 && add: // Add operation and does not contain.
			info.ImportPid += "$" + strconv.Itoa(pid) + "|"
			info.ImportedNum++
			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo(): add:", path, err)
			}
		case i > -1 && !add: // Delete operation and contains.
			info.ImportPid = strings.Replace(info.ImportPid, "$"+strconv.Itoa(pid)+"|", "", 1)
			info.ImportedNum--
			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo(): delete:", path, err)
			}
		}
	}

	// Error means this project does not exist, simply skip.
}
Beispiel #6
0
func (c *LoginController) Post() {
	account := c.Input().Get("account")
	password := c.Input().Get("password")
	autologin := c.Input().Get("autologin") == "on"

	//数据库比较
	pass, err := models.VerifyUser(common.MakeMD5(account), common.MakeMD5(password))
	if err != nil {
		c.Redirect("/login", 301)
		beego.Error(err)
		return
	}
	if pass {
		beego.Error("login successful!")
		maxage := 0
		if autologin {
			maxage = 1<<31 - 1
		}
		c.Ctx.SetCookie("account", common.MakeMD5(account), maxage, "/")
		c.Ctx.SetCookie("password", common.MakeMD5(password), maxage, "/")

		c.SetSession("account", common.MakeMD5(account))
		// c.SetSession("password", password)
	} else {
		c.Redirect("/login", 301)
		beego.Error("login failed!")
		return
	}
	c.Redirect("/", 301)
	return
}
Beispiel #7
0
func (c *ApiController) AddVolume() {
	var (
		err     error
		groupId int64
		n       int
		res     map[string]interface{} = make(map[string]interface{})
	)

	res["success"] = true

	if groupId, err = c.GetInt64("groupId"); err != nil {
		beego.Error(err)
		c.responseError(err)
	}

	if n, err = c.GetInt("n"); err != nil {
		beego.Error(err)
		c.responseError(err)
	}

	if err = ops.OpsManager.AddVolume(uint64(groupId), n); err != nil {
		beego.Error(err)
		c.responseError(err)
	}

	c.Data["json"] = res
	c.ServeJSON()
}
Beispiel #8
0
func initDb() {
	iniconf, err := config.NewConfig("ini", "conf/app.conf")
	if err != nil {
		beego.Error(err)
	}
	driverName := iniconf.String("orm::driver_name")
	dataSource := iniconf.String("orm::data_source")
	maxIdle, _ := iniconf.Int("orm::max_idle_conn")
	maxOpen, _ := iniconf.Int("orm::max_open_conn")

	// set default database
	err = orm.RegisterDataBase("default", driverName, dataSource, maxIdle, maxOpen)
	if err != nil {
		beego.Error(err)
	}
	//	orm.Debug = true

	//orm.RunCommand()							//执行命令行的

	err = orm.RunSyncdb("default", false, false) //建表的
	////数据库别名,不强制建数据库,打印建表过程

	if err != nil {
		beego.Error(err)
	}
}
Beispiel #9
0
func (c *DqsjController) AdminGua() {
	bool, _ := chackDqsjAccount(c.Ctx)
	if bool {

	} else {
		c.Redirect("/dqsj/adminlogin", 302)
		return
	}
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminGua Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminGua Post")
	}
	op := c.Input().Get("op")
	beego.Debug("op :", op)
	switch op {
	case "del":
		id := c.Input().Get("id")
		err := models.DeleteGuaItem(id)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/dqsj/admingua", 302)
		return
	case "state0":
		id := c.Input().Get("id")
		err := models.UpdateGuaItem(id, 1)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/dqsj/admingua", 302)
		return
	case "state1":
		id := c.Input().Get("id")
		err := models.UpdateGuaItem(id, 0)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/dqsj/admingua", 302)
		return
	}
	panitem, err := models.GetAllGuaItem()
	if err != nil {
		beego.Error(err)
	}
	//计算总概率
	allProbability := int64(0)
	for i := 0; i < len(panitem); i++ {
		if panitem[i].State == 1 {
			allProbability += panitem[i].Probability
		}
	}
	for i := 0; i < len(panitem); i++ {
		panitem[i].AllProbability = allProbability
	}
	c.Data["GuaItem"] = panitem

	c.TplName = "dqsjadmingua.html"
}
Beispiel #10
0
func (c *Comments) Remove() {

	r := RJson{Msg: T("internal")}
	c.Data["json"] = &r

	i := c.GetSession("role")
	if i == nil || i.(int) != M.RoleAdmin {
		r.Msg = T("restrict_access")
		return
	}

	id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
	if err != nil {
		beego.Error(err)
		return
	}

	err = DM.DeleteByPk(&M.Comment{}, id)
	if err != nil {
		beego.Error(err)
		return
	}

	r.Msg = ""
	r.Success = true
}
Beispiel #11
0
func (this *CategoryController) Get() {
	this.Data["headerTitle"] = "Categories"
	this.TplNames = "category.html"
	this.Data["isCategory"] = true
	this.Data["isLogin"] = checkLogin(this.Ctx)

	op := this.Input().Get("op")
	if op == "add" {
		name := this.Input().Get("name")
		err := models.AddCategory(name)
		if err != nil {
			beego.Error(err)
		}
	} else if op == "del" {
		id := this.Input().Get("id")
		err := models.DeleteCategory(id)
		if err != nil {
			beego.Error(err)
		}
	}
	var err error
	this.Data["Categories"], err = models.AllCategories(false)
	if err != nil {
		beego.Error(err)
	}
}
Beispiel #12
0
func (this *MainController) Get() {
	page, err := this.GetInt64("p", 1)
	if err != nil {
		beego.Error(err)
	}

	extend := map[string]string{}
	tid := this.GetString("tid", "")
	key := this.GetString("key")
	if tid != "" {
		extend["type_id"] = tid
	}

	beego.Info(extend)
	maps, err := models.GetArtPageList(10, (page-1)*10, extend, key)

	if err != nil {
		beego.Error(err)
	}
	count, err := models.GetCount(extend, key)
	if err != nil {
		beego.Error(err)
	}
	p := pagination.NewPaginator(this.Ctx.Request, 10, count)
	beego.Info(p)
	this.Data["paginator"] = p
	types := models.GetAllType()
	this.Data["articles"] = maps
	this.Data["types"] = types
	this.Data["key"] = key
	beego.AppConfig.String("banner1.name")

	this.TplNames = "index.tpl"
}
Beispiel #13
0
func (this *ConfigController) Prepare() {
	banner1_url := beego.AppConfig.String("banner1.url")
	banner1_id, _ := beego.AppConfig.Int("banner1.id")
	art := models.Article{Id: banner1_id}
	err := models.GetByProperty(&art)
	if err != nil {
		beego.Error(err)
	}
	this.Data["banner1_url"] = banner1_url
	this.Data["banner1_art"] = art

	banner2_url := beego.AppConfig.String("banner2.url")
	banner2_id, _ := beego.AppConfig.Int("banner2.id")
	art2 := models.Article{Id: banner2_id}
	err2 := models.GetByProperty(&art2)
	if err2 != nil {
		beego.Error(err)
	}
	this.Data["banner2_url"] = banner2_url
	this.Data["banner2_art"] = art2

	banner3_url := beego.AppConfig.String("banner3.url")
	banner3_id, _ := beego.AppConfig.Int("banner3.id")
	art3 := models.Article{Id: banner3_id}
	err3 := models.GetByProperty(&art3)
	if err3 != nil {
		beego.Error(err)
	}
	this.Data["banner3_url"] = banner3_url
	this.Data["banner3_art"] = art3
}
func (c *AdminNoticeController) Get() {
	bool, username := chackAccount(c.Ctx)
	if bool {

	} else {
		c.Redirect("/admin", 302)
		return
	}
	c.Data["isUser"] = bool
	c.Data["User"] = username
	op := c.Input().Get("op")
	switch op {
	case "del":
		id := c.Input().Get("id")
		err := models.DeleteAdminUserNotice(id)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/admin/notice", 302)
		return
	}
	objs, err := models.GetAllNotice()
	if err != nil {
		beego.Error(objs)
	}
	c.Data["Objs"] = objs
	c.TplName = "adminnotice.html"
}
Beispiel #15
0
func (this *HomeController) Get() {
	this.Data["IsHome"] = true
	this.TplNames = "home.html"

	this.Data["IsLogin"] = checkAccount(this.Ctx)

	category := this.Input().Get("cate")

	var err error
	topics := make([]*models.Topic, 0)

	if len(category) == 0 {
		topics, err = models.GetAllTopics(true)
	} else {
		topics, err = models.GetTopicsByCategory(category, true)
	}
	if err != nil {
		beego.Error(err)
	}
	this.Data["Topics"] = topics

	Category, err := models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}

	this.Data["Categories"] = Category

}
Beispiel #16
0
// Handler beego filter handler for serve captcha image
func (c *Captcha) Handler(ctx *context.Context) {
	var chars []byte

	id := path.Base(ctx.Request.RequestURI)
	if i := strings.Index(id, "."); i != -1 {
		id = id[:i]
	}

	key := c.key(id)

	if len(ctx.Input.Query("reload")) > 0 {
		chars = c.genRandChars()
		if err := c.store.Put(key, chars, c.Expiration); err != nil {
			ctx.Output.SetStatus(500)
			ctx.WriteString("captcha reload error")
			beego.Error("Reload Create Captcha Error:", err)
			return
		}
	} else {
		if v, ok := c.store.Get(key).([]byte); ok {
			chars = v
		} else {
			ctx.Output.SetStatus(404)
			ctx.WriteString("captcha not found")
			return
		}
	}

	img := NewImage(chars, c.StdWidth, c.StdHeight)
	if _, err := img.WriteTo(ctx.ResponseWriter); err != nil {
		beego.Error("Write Captcha Image Error:", err)
	}
}
Beispiel #17
0
// LoadPkgDoc loads project introduction documentation.
func LoadPkgDoc(path, lang, docType string) (doc string) {
	if len(lang) < 2 {
		return ""
	}

	lang = lang[:2]

	pdoc := &PkgDoc{
		Path: path,
		Lang: lang,
		Type: docType,
	}

	if has, err := x.Get(pdoc); has {
		if err != nil {
			beego.Error("models.LoadPkgDoc(", path, lang, docType,
				") -> Fail to get PkgDoc:", err.Error())
			return doc
		}
		return pdoc.Doc
	}

	pdoc.Lang = "en"
	if has, err := x.Get(pdoc); has {
		if err != nil {
			beego.Error("models.LoadPkgDoc(", path,
				") -> Fail to get PkgDoc:", err.Error())
			return doc
		}
		return pdoc.Doc
	}
	return doc
}
Beispiel #18
0
func (this *MainController) Post() {
	body, err := ioutil.ReadAll(this.Ctx.Request.Body)
	if err != nil {
		beego.Error(err)
		this.Ctx.ResponseWriter.WriteHeader(500)
		return
	}
	beego.Info(string(body))
	var wreq *Request
	if wreq, err = DecodeRequest(body); err != nil {
		beego.Error(err)
		this.Ctx.ResponseWriter.WriteHeader(500)
		return
	}
	beego.Info(wreq.Content)
	wresp, err := dealwith(wreq)
	if err != nil {
		beego.Error(err)
		this.Ctx.ResponseWriter.WriteHeader(500)
		return
	}
	data, err := wresp.Encode()
	if err != nil {
		beego.Error(err)
		this.Ctx.ResponseWriter.WriteHeader(500)
		return
	}
	this.Ctx.WriteString(string(data))
	return
}
Beispiel #19
0
func GetCacheUserData(token string) (userData *m.UserData) {

	if redisx == nil {
		return nil
	}
	v := redisx.Get("USERDATA_" + token)

	if v != nil {

		bJson, err := lib.GetBytes(v)
		if err != nil {
			beego.Error(err.Error())
			return nil
		}

		beego.Debug("Get cache user data:" + string(bJson))

		err = json.Unmarshal(bJson, &userData)
		if err != nil {
			beego.Error(err.Error())
			return nil
		}

	}

	return userData
}
Beispiel #20
0
func (this *OpsController) Post() {
	agentId := this.GetString("agent_id")
	action := this.GetString("action")

	switch action {
	case "":
		monitorStr, err := getMonitorByAgentId(agentId)
		if err != nil {
			this.Data["AgentError"] = fmt.Sprintf("Request AgentId [%s] monitor info error: %s", agentId, err)
			beego.Error("Request AgentId [%s] monitor info error: %s", agentId, err)
		} else {
			err = saveOrUpdateMonitor(monitorStr)
			this.Data["AgentError"] = fmt.Sprintf("Save error: %s", err)
			beego.Error("saveOrUpdateMonitor monitorStr [%s] Error %s", monitorStr, err)
		}
	case "delete":
		monitor := entity.Monitor{}
		monitor.AgentId = agentId
		err := monitor.DeleteByAgentId()
		if err != nil {
			this.Data["AgentError"] = fmt.Sprintf("Delete Monitor error %s", err)
		}
	}

	this.Get()
}
Beispiel #21
0
func (c *ApiController) AddFreeVolume() {

	var (
		err  error
		host string
		bdir string
		idir string
		n    int32
		res  map[string]interface{}
	)

	res = make(map[string]interface{})
	res["success"] = true

	host = c.GetString("host")
	bdir = c.GetString("bdir")
	idir = c.GetString("idir")
	if n, err = c.GetInt32("n"); err != nil {
		beego.Error(err)
		c.responseError(err)
	}

	if err = ops.OpsManager.AddFreeVolume(host, n, bdir, idir); err != nil {
		beego.Error(err)
		c.responseError(err)
	}

	c.Data["json"] = res
	c.ServeJSON()
}
Beispiel #22
0
func (this *OpsMonitorRestController) Get() {
	agentId := this.GetString("agent_id")

	//TODO 暂时直接从nats请求信息,需要持久话健康信息和负载信息
	monitorStr, err := getMonitorByAgentId(agentId)

	result := entity.ResponseMessage{}

	if err != nil {
		result.Code = utils.ResponseCodeFailed
		result.Data = fmt.Sprintf("Request AgentId [%s] monitor info error: %s", agentId, err)
		beego.Error("Request AgentId %s monitor info error %s", agentId, err)
		monitor := entity.Monitor{}
		monitor.AgentId = agentId
		err = monitor.DeleteByAgentId()
		if err != nil {
			this.Data["AgentError"] = fmt.Sprintf("Delete Monitor error %s", err)
		}

	} else {
		result.Code = utils.ResponseCodeSuccess
		result.Data = monitorStr
		err = saveOrUpdateMonitor(monitorStr)
		beego.Error("saveOrUpdateMonitor monitorStr [%s] Error %s", monitorStr, err)
	}
	this.Data["json"] = &result
	this.ServeJSON(false)
}
Beispiel #23
0
func (this *AttachController) Post() {
	var (
		attachment string
		fileExist  string
	)
	// 获取文件名
	_, fh, err := this.GetFile("updatePack")
	if err != nil {
		beego.Error(err)
	}
	if fh != nil {
		//验证文件是否已存在
		attachment = fh.Filename
		fileExist = path.Join("updatePack", attachment)
		beego.Info("filePath: ", fileExist)
		if _, err = os.Stat(fileExist); err == nil {
			this.Ctx.Output.Body([]byte("文件已存在"))
			beego.Info("上传文件已存在")
			return
		}
		// 保存文件
		err = this.SaveToFile("updatePack", fileExist)
		if err != nil {
			beego.Error(err)
		}
	}
	this.Ctx.Output.Body([]byte("OK"))
	//解压缩并生成更新列表
	go UnzipUpdatePack(attachment)
	return
}
Beispiel #24
0
func (c *ArticleController) Get() {
	// 是否是删除操作
	switch c.Input().Get("op") {
	case "del":
		if !IsLogin(c.Ctx) {
			c.Redirect("/login", 301)
			return
		}
		models.DelArticle(c.Input().Get("id"))
		break
	}
	//获取显示第几页
	page, err := strconv.ParseInt(c.Input().Get("p"), 10, 64)
	if err != nil || page < 1 {
		page = 1
	}
	awcs, err := models.GetArticleCatagory(page)
	if err != nil {
		beego.Error(err)
	}
	totalNum, err := models.GetArticleCount()
	if err != nil {
		beego.Error(err)
	}
	c.Data["pages"] = CalcPaginate(page, 10, totalNum)
	c.Data["awcs"] = awcs

	c.Data["IsArticle"] = true
	c.Data["IsLogin"] = IsLogin(c.Ctx)
	c.TplName = "article.html"
}
Beispiel #25
0
// UpdateTagInfo updates prohect tag information, returns false if the project does not exist.
func UpdateTagInfo(path string, tags []string, add bool) bool {
	// Connect to database.
	q := connDb()
	defer q.Db.Close()

	info := new(PkgInfo)
	err := q.WhereEqual("path", path).Find(info)
	if err != nil {
		return false
	}

	for _, v := range tags {
		i := strings.Index(info.Tags, "$"+v+"|")
		switch {
		case i == -1 && add: // Add operation and does not contain.
			info.Tags += "$" + v + "|"
			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.UpdateTagInfo(): add:", path, err)
			}
		case i > -1 && !add: // Delete opetation and contains.
			info.Tags = strings.Replace(info.Tags, "$"+v+"|", "", 1)
			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.UpdateTagInfo(): add:", path, err)
			}
		}
	}

	return true
}
Beispiel #26
0
func (this *RootUploadRouter) Post() {
	num, err := this.GetInt("CKEditorFuncNum")
	//	file, handler, err := this.GetFile("upload")
	file, _, err := this.GetFile("upload")
	if err != nil {
		beego.Error(err)
		return
	}

	defer file.Close()
	url, err := common.UploadFile("image", file)
	if err != nil {
		beego.Error(err)
		fmt.Fprintf(this.Ctx.ResponseWriter, Script, num, common.Webconfig.StaticURL+"/"+url, err)
	} else {
		beego.Error(err)
		fmt.Fprintf(this.Ctx.ResponseWriter, Script, num, common.Webconfig.StaticURL+"/"+url, "")
	}
	//	url, err := SaveFile("static/uploads", handler.Filename, file)//保存到本地
	// if err != nil {
	// 	fmt.Fprintf(this.Ctx.ResponseWriter, Script, num, common.Webconfig.SiteURL+"/"+url, err)
	// } else {
	// 	fmt.Fprintf(this.Ctx.ResponseWriter, Script, num, common.Webconfig.SiteURL+"/"+url, "")
	// }

}
Beispiel #27
0
func initBlogMap() {
	os.Mkdir("blog", os.ModePerm)
	langs := strings.Split(beego.AppConfig.String("lang::types"), "|")
	for _, l := range langs {
		os.Mkdir("blog/"+l, os.ModePerm)
	}

	if !utils.FileExists("conf/blogTree.json") {
		beego.Error("models.initBlogMap -> conf/blogTree.json does not exist")
		return
	}

	f, err := os.Open("conf/blogTree.json")
	if err != nil {
		beego.Error("models.initBlogMap -> load data:", err.Error())
		return
	}
	defer f.Close()

	d := json.NewDecoder(f)
	err = d.Decode(&blogTree)
	if err != nil {
		beego.Error("models.initBlogMap -> decode data:", err.Error())
		return
	}

	blogLock.Lock()
	defer blogLock.Unlock()

	blogMap = make(map[string]*docFile)
	for _, v := range blogTree.Tree {
		blogMap[v.Path] = getFile("blog/" + v.Path)
	}
}
Beispiel #28
0
func (this *TopicController) FileAdd() {
	this.Ctx.Request.ParseMultipartForm(32 << 20)
	file, _, err := this.Ctx.Request.FormFile("file")
	if err != nil {
		beego.Error("[上传文件错误]" + err.Error())
	}
	defer file.Close()
	datas, err := ioutil.ReadAll(file)
	fmt.Println("fmt", datas)
	if err != nil {
		beego.Error("[读取文件错误]" + err.Error())
	}

	beego.Info(string(datas) + "[datas]")

	a := string(datas)
	result := string(blackfriday.MarkdownBasic(datas))
	result = strings.Replace(result, "<code>", "<code class=\"go\">", -1)
	// this.Ctx.WriteString(string(datas)) 为什么这里不输出

	beego.Info(a)

	this.Data["json"] = result
	this.ServeJson()
}
Beispiel #29
0
func (this *UserController) processUserPasswordForm(user *models.User) {
	valid := validation.Validation{}
	userPasswordForm := UserPasswordForm{}
	if err := this.ParseForm(&userPasswordForm); err != nil {
		beego.Error(err)
	}
	_, err := valid.Valid(userPasswordForm)
	if err != nil {
		beego.Error(err)
		this.Abort("400")
	}
	if !user.VerifyPassword(userPasswordForm.CurrentPassword) {
		valid.SetError("CurrentPassword", "当前密码错误")
	}
	if len(valid.Errors) > 0 {
		this.Data["UserPasswordFormValidErrors"] = valid.Errors
		beego.Trace(fmt.Sprint(valid.Errors))
	} else {
		user.SetPassword(userPasswordForm.Password)
		if err := user.Update(); err != nil {
			this.Abort("500")
		}
		this.FlashWrite("notice", "密码已更新!")
		this.Redirect(this.Ctx.Request.RequestURI, 302)
	}
}
Beispiel #30
0
// 查看文章详情
func (c *TopicController) View() {
	c.TplNames = "topic_view.html"

	// 获取文章数据
	topic, err := models.GetTopic(c.Ctx.Input.Param("0"))
	if err != nil {
		beego.Error(err)
		c.Redirect("/", 302)
		return
	}
	// 先将文章内容数据丢出给前台,就不论是否获取评论成功与否,文章都能显示
	c.Data["Topic"] = topic
	c.Data["Label"] = strings.Split(topic.Label, " ")
	c.Data["Tid"] = c.Ctx.Input.Param("0")

	// 获取评论数据
	replies, err := models.GetAllReplies(c.Ctx.Input.Param("0"))
	if err != nil {
		beego.Error(err)
		return
	}

	c.Data["Replies"] = replies
	c.Data["IsLogin"] = checkLogin(c.Ctx)
}