Example #1
0
func filterSiteOwner(ctx *context.Context) {
	u := ctx.Input.Session("current_user").(*goth.User)

	user, err := models.GetUser(u.NickName)
	if err != nil {
		beego.Error(err)
		ctx.Redirect(302, "/404.html")
	}

	siteID, err := strconv.ParseInt(ctx.Input.Param(":id"), 10, 64)
	if err != nil {
		beego.Error(err)
		ctx.Redirect(302, "/404.html")
	}

	site, err := models.SiteByOwner(siteID, user.ID)
	if err != nil {
		beego.Error(err)
		ctx.Redirect(302, "/404.html")
	}
	ctx.Input.SetData("user", user)
	ctx.Input.SetData("site", site)
}
Example #2
0
func (c *PublishController) PublishSite() {
	cu := c.GetSession("current_user").(*goth.User)

	user, err := models.GetUser(cu.NickName)
	if err != nil {
		beego.Error(err)
		c.Redirect("/404.html", 302)
		return
	}

	f := PublishForm{}
	if err := c.ParseForm(&f); err != nil {
		beego.Error(err)
		c.Redirect("/404.html", 302)
		return
	}

	repository, err := github.GetRepository(cu.AccessToken, cu.NickName, f.Nwo)
	if err != nil {
		beego.Error(err)
		c.Redirect("/404.html", 302)
		return
	}

	tmpl, err := models.GetTemplate(f.Template)
	if err != nil {
		beego.Error(err)
		c.Redirect("/404.html", 302)
		return
	}

	siteName := siteName(repository)
	domain, fullURL := finalDomain(siteName, f)

	if err := models.CreateSite(user, repository, f.Template, fullURL); err != nil {
		beego.Error(err)
		c.Redirect("/404.html", 302)
		return
	}

	deployPath, err := themes.Pack(repository, tmpl.Path, fullURL, f.Landing)
	if err != nil {
		beego.Error(err)
		c.Redirect("/404.html", 302)
		return
	}
	defer os.RemoveAll(deployPath)

	if err := hosting.Publish(user, deployPath, siteName, domain); err != nil {
		beego.Error(err)
		c.Redirect("/404.html", 302)
		return
	}

	steps := newSteps("", "", "", "disabled")
	steps.Select.Attr["owner"] = *repository.Owner.Login
	steps.Configure.Attr["nwo"] = f.Nwo
	c.Data["steps"] = steps

	c.Data["currentUser"] = cu
	c.Data["preview"] = f
	c.Data["repository"] = repository
	c.Data["domainURL"] = fullURL

	c.TplName = "steps/finish.tpl"
}