Exemplo n.º 1
0
func SetupPage(p *gos.Page, theme string) {
	if theme == "" {
		theme = gos.GetSite().SiteTheme
	}
	p.View.Theme = theme
	p.JsPosition = "end"

	// p.AddHead("<link href=\"//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css\" rel=\"stylesheet\">")
	p.AddHead(`<meta name="viewport" content="width=device-width, initial-scale=1">`)
	p.AddCss(&gos.ThemeItem{Value: "bootstrap.min.css"})
	p.AddCss(&gos.ThemeItem{Value: "font-awesome.min.css"})

	p.AddCss(&gos.ThemeItem{Value: fmt.Sprint(p.View.Value, ".css"), Folder: fmt.Sprint(gos.RunMode, "/page/", p.View.Folder), Theme: theme})

	p.Layout.AddTopRender(gos.NewTemplateRender("", "", "_header", nil))
	// p.Layout.AddBottomRender(gos.NewTemplateRender("", "", "_footer", nil))

	p.Layout.RenderFunc = Render
	p.SetUserAuth(auth.New(p.Ctx))

	RequireJs(p)
	p.AddJs(&gos.ThemeItem{Value: "jquery.js"})
}
Exemplo n.º 2
0
func UserAuth(ctx *gos.Context) *auth.UserAuth {
	return auth.New(ctx)
}
Exemplo n.º 3
0
func (this *ImageUpload) Prepare() bool {
	au := auth.New(this.Ctx)
	return au.IsOk()
}
Exemplo n.º 4
0
func (this *ImageUpload) DoUpload() {
	defer func() {
		if r := recover(); r != nil {
			gos.DoError(r)
		}
	}()
	now := time.Now()
	nowStr := now.Format("20060102")
	tagName := "file"
	tempPath := path.Join(gos.HomeDir, this.StoreRoot, "/temp")
	storePath := path.Join(gos.HomeDir, this.StoreRoot, "/pictures/", nowStr)

	if this.Ctx.Request.Method == "GET" {
		if err := this.ResumableJsTest(storePath); err == nil {
			this.ResumableJsCheckAndMeger(storePath, tempPath)
			this.Ctx.ResponseWriter.WriteHeader(200)
		} else {
			this.Ctx.ResponseWriter.WriteHeader(204)
		}
		return
	}

	websvr := &gos.WebApi{Ctx: this.Ctx}
	reply := map[string]string{}
	sf, err := this.ResumableJs(tagName, storePath, tempPath)
	if err != nil {
		gos.DoError(err)
		websvr.Reply(gos.DoError(err).Data(), nil)
		return
	}

	// sf.Store()

	if sf == nil {
		reply["filename"] = ""
		reply["ext"] = ""
		reply["url"] = ""
	} else {
		reply["filename"] = sf.StoreName
		reply["ext"] = sf.Ext

		folder := fmt.Sprint("/uploads/pictures/", nowStr, "/")
		reply["url"] = fmt.Sprint(folder, reply["filename"], "-m", sf.Ext)

		// err = resizeImage(storePath, sf.StoreName, sf.Ext)
		from := path.Join(gos.HomeDir, "webroot", folder, fmt.Sprint(reply["filename"], sf.Ext))
		to := path.Join(gos.HomeDir, "webroot", folder, fmt.Sprint(reply["filename"], "-m", sf.Ext))
		cmdStr := fmt.Sprint("convert -resize 800x600 ", from, " ", to)
		cmd := exec.Command("/bin/sh", "-c", cmdStr)
		_, err := cmd.Output()
		if err != nil {
			gos.DoError(err, cmdStr)
		}

		au := auth.New(this.Ctx)
		row := db.DataRow{}
		row["name"] = sf.StoreName
		row["ext"] = sf.Ext
		row["user_id"] = au.UserID()
		row["created_at"] = now

		_, err = db.NewInsertBuilder("images").Insert(row)
		if err != nil {
			websvr.Reply(gos.DoError(err).Data(), nil)
			return
		}
	}

	websvr.Reply(reply, nil)
}
Exemplo n.º 5
0
func (a *OpenApi) Prepare() bool {
	a.SetUserAuth(auth.New(a.WebApi.Ctx))
	return true
}