當前位置: 首頁>>代碼示例>>Golang>>正文


Golang captcha.Captchaer函數代碼示例

本文整理匯總了Golang中github.com/go-macaron/captcha.Captchaer函數的典型用法代碼示例。如果您正苦於以下問題:Golang Captchaer函數的具體用法?Golang Captchaer怎麽用?Golang Captchaer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Captchaer函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: initCaptch

func initCaptch(m *macaron.Macaron) {
	m.Use(cache.Cacher())

	width := 240
	height := 80
	expiration := int64(600)

	cfg := macaron.Config()
	capcfg, err := cfg.GetSection("captcha")

	if err != nil {
		width = capcfg.Key("width").MustInt(width)
		height = capcfg.Key("height").MustInt(height)
		expiration = capcfg.Key("expire").MustInt64(expiration)
	}

	m.Use(captcha.Captchaer(captcha.Options{
		URLPrefix:        "/captcha/img/", // 獲取驗證碼圖片的 URL 前綴,默認為 "/captcha/"
		FieldIdName:      "captcha_id",    // 表單隱藏元素的 ID 名稱,默認為 "captcha_id"
		FieldCaptchaName: "captcha",       // 用戶輸入驗證碼值的元素 ID,默認為 "captcha"
		ChallengeNums:    6,               // 驗證字符的個數,默認為 6
		Width:            width,           // 驗證碼圖片的寬度,默認為 240 像素
		Height:           height,          // 驗證碼圖片的高度,默認為 80 像素
		Expiration:       expiration,      // 驗證碼過期時間,默認為 600 秒
		CachePrefix:      "captcha_",      // 用於存儲驗證碼正確值的 Cache 鍵名,默認為 "captcha_"
	}))
}
開發者ID:wcreate,項目名稱:wuc,代碼行數:27,代碼來源:init.go

示例2: main

func main() {
	m := macaron.Classic()
	m.Use(cache.Cacher())
	// m.Use(session.Sessioner())
	m.Use(session.Sessioner(session.Options{
		Provider:       "memory",
		ProviderConfig: "",
		CookieName:     "Kfx",
		CookiePath:     "/",
		Gclifetime:     3600,
		Maxlifetime:    3600,
		Secure:         false,
		CookieLifeTime: 0,
		Domain:         "/",
		IDLength:       16,
		Section:        "session",
	}))
	m.Use(csrf.Csrfer())
	m.Use(captcha.Captchaer(captcha.Options{
		// 獲取驗證碼圖片的 URL 前綴,默認為 "/captcha/"
		URLPrefix: "/captcha/",
		// 表單隱藏元素的 ID 名稱,默認為 "captcha_id"
		FieldIdName: "captcha_id",
		// 用戶輸入驗證碼值的元素 ID,默認為 "captcha"
		FieldCaptchaName: "captcha",
		// 驗證字符的個數,默認為 6
		ChallengeNums: 6,
		// 驗證碼圖片的寬度,默認為 240 像素
		Width: 240,
		// 驗證碼圖片的高度,默認為 80 像素
		Height: 80,
		// 驗證碼過期時間,默認為 600 秒
		Expiration: 600,
		// 用於存儲驗證碼正確值的 Cache 鍵名,默認為 "captcha_"
		CachePrefix: "captcha_",
	}))
	m.Use(renders.Renderer(renders.Options{
		Directory:       "templates",
		Extensions:      []string{".html"},
		Charset:         "UTF-8",
		IndentJSON:      true,
		IndentXML:       true,
		HTMLContentType: "text/html",
	}))

	m.Get("/", index.Index)

	m.NotFound(func(r renders.Render) {
		r.HTML(200, "404.html", map[string]interface{}{"Title": "Home"})
	})
	m.Run()
}
開發者ID:myafeier,項目名稱:GoCMS,代碼行數:52,代碼來源:main.go

示例3: main

func main() {
	log.Debug("Starting server...")

	m := macaron.New()
	m.Use(macaron.Logger())
	m.Use(macaron.Recovery())
	m.Use(cache.Cacher())
	m.Use(session.Sessioner(session.Options{CookieName: "s"}))
	m.Use(captcha.Captchaer(captcha.Options{Width: 120, Height: 40}))
	m.Use(macaron.Static("static", macaron.StaticOptions{Prefix: "/static"}))
	m.Use(pongo2.Pongoer())
	//m.Use(i18n.I18n(i18n.Options{
	//	Langs: []string{"en-US", "zh-CN"},
	//	Names: []string{"English", "簡體中文"},
	//}))
	m.Use(spider.SpiderFunc())
	m.Use(token.Tokener())

	boot.BootStrap()
	router.Route(m)

	m.Run(boot.WebListenIP, boot.WebPort)
}
開發者ID:xtfly,項目名稱:goman,代碼行數:23,代碼來源:app.go

示例4: newMacaron

// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
	m := macaron.New()
	if !setting.DisableRouterLog {
		m.Use(macaron.Logger())
	}
	m.Use(macaron.Recovery())
	if setting.EnableGzip {
		m.Use(gzip.Gziper())
	}
	if setting.Protocol == setting.FCGI {
		m.SetURLPrefix(setting.AppSubUrl)
	}
	m.Use(macaron.Static(
		path.Join(setting.StaticRootPath, "public"),
		macaron.StaticOptions{
			SkipLogging: setting.DisableRouterLog,
		},
	))
	m.Use(macaron.Static(
		setting.AvatarUploadPath,
		macaron.StaticOptions{
			Prefix:      "avatars",
			SkipLogging: setting.DisableRouterLog,
		},
	))
	m.Use(macaron.Renderer(macaron.RenderOptions{
		Directory:  path.Join(setting.StaticRootPath, "templates"),
		Funcs:      []gotmpl.FuncMap{template.Funcs},
		IndentJSON: macaron.Env != macaron.PROD,
	}))

	localeNames, err := bindata.AssetDir("conf/locale")
	if err != nil {
		log.Fatal(4, "Fail to list locale files: %v", err)
	}
	localFiles := make(map[string][]byte)
	for _, name := range localeNames {
		localFiles[name] = bindata.MustAsset("conf/locale/" + name)
	}
	m.Use(i18n.I18n(i18n.Options{
		SubURL:          setting.AppSubUrl,
		Files:           localFiles,
		CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
		Langs:           setting.Langs,
		Names:           setting.Names,
		DefaultLang:     "en-US",
		Redirect:        true,
	}))
	m.Use(cache.Cacher(cache.Options{
		Adapter:       setting.CacheAdapter,
		AdapterConfig: setting.CacheConn,
		Interval:      setting.CacheInternal,
	}))
	m.Use(captcha.Captchaer(captcha.Options{
		SubURL: setting.AppSubUrl,
	}))
	m.Use(session.Sessioner(setting.SessionConfig))
	m.Use(csrf.Csrfer(csrf.Options{
		Secret:     setting.SecretKey,
		SetCookie:  true,
		Header:     "X-Csrf-Token",
		CookiePath: setting.AppSubUrl,
	}))
	m.Use(toolbox.Toolboxer(m, toolbox.Options{
		HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
			&toolbox.HealthCheckFuncDesc{
				Desc: "Database connection",
				Func: models.Ping,
			},
		},
	}))
	m.Use(middleware.Contexter())
	return m
}
開發者ID:abhijitmamarde,項目名稱:gogs,代碼行數:75,代碼來源:web.go

示例5: newMacaron

func newMacaron() *macaron.Macaron {
	m := macaron.New()

	// DISABLE_ROUTER_LOG: 激活該選項來禁止打印路由日誌
	// 判斷是否禁用,如果禁用則引入macaron日誌
	if !setting.DisableRouterLog {
		m.Use(macaron.Logger())
	}
	// 引入macaron恢複機製
	m.Use(macaron.Recovery())

	if setting.Protocol == setting.FCGI {
		m.SetURLPrefix(setting.AppSubUrl)
	}

	// 設定靜態資源路徑
	m.Use(macaron.Static(
		path.Join(setting.StaticRootPath, "public"),
		macaron.StaticOptions{
			SkipLogging: setting.DisableRouterLog,
		},
	))
	m.Use(macaron.Static(
		setting.AvatarUploadPath,
		macaron.StaticOptions{
			Prefix:      "avatars",
			SkipLogging: setting.DisableRouterLog,
		},
	))

	// 設置渲染模板
	m.Use(macaron.Renderer(macaron.RenderOptions{
		Directory:         path.Join(setting.StaticRootPath, "templates"),
		AppendDirectories: []string{path.Join(setting.CustomPath, "templates")},
		Funcs:             template.NewFuncMap(),
		IndentJSON:        macaron.Env != macaron.PROD,
	}))

	// 指定國際化目錄
	localeNames, err := bindata.AssetDir("conf/locale")
	if err != nil {
		log.Fatal(4, "Fail to list locale files: %v", err)
	}
	localFiles := make(map[string][]byte)
	for _, name := range localeNames {
		localFiles[name] = bindata.MustAsset("conf/locale/" + name)
	}

	m.Use(i18n.I18n(i18n.Options{
		SubURL:          setting.AppSubUrl,
		Files:           localFiles,
		CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
		Langs:           setting.Langs,
		Names:           setting.Names,
		DefaultLang:     "en-US",
		Redirect:        true,
	}))
	m.Use(cache.Cacher(cache.Options{
		Adapter:       setting.CacheAdapter,
		AdapterConfig: setting.CacheConn,
		Interval:      setting.CacheInternal,
	}))
	m.Use(captcha.Captchaer(captcha.Options{
		SubURL: setting.AppSubUrl,
	}))
	m.Use(session.Sessioner(setting.SessionConfig))
	m.Use(csrf.Csrfer(csrf.Options{
		Secret:     setting.SecretKey,
		Cookie:     setting.CSRFCookieName,
		SetCookie:  true,
		Header:     "X-Csrf-Token",
		CookiePath: setting.AppSubUrl,
	}))
	m.Use(toolbox.Toolboxer(m, toolbox.Options{
		HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
			&toolbox.HealthCheckFuncDesc{
				Desc: "Database connection",
				Func: models.Ping,
			},
		},
	}))
	//m.Use(context.Contexter())
	return m
}
開發者ID:kuuyee,項目名稱:gogs-learn,代碼行數:84,代碼來源:web.go


注:本文中的github.com/go-macaron/captcha.Captchaer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。