func (c *PublishController) ConfigureSite() {
	cu := c.GetSession("current_user").(*goth.User)

	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
	}

	steps := newSteps("", "", "", "active")
	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.TplName = "steps/publish.tpl"
}
func (c *ConfigureController) ConfigureRepository() {
	cu := c.GetSession("current_user").(*goth.User)

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

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

	c.Data["steps"] = steps
	c.Data["currentUser"] = cu
	c.Data["repository"] = repository
	c.Data["templates"] = models.AllTemplates()

	c.TplName = "steps/configure.tpl"
}
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"
}