• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang session.NewManager函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/astaxie/beego/session.NewManager函数的典型用法代码示例。如果您正苦于以下问题:Golang NewManager函数的具体用法?Golang NewManager怎么用?Golang NewManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewManager函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: init

func init() {
	db, _ = sql.Open("mysql", myConfig.Db_user+":"+myConfig.Db_password+"@"+myConfig.Db_address+"/"+myConfig.Db_schema)
	err := db.Ping()
	if err == nil {
		log.Println("DB responded")
	} else {
		log.Println("DB not responding: ", err)
	}

	dbKeepalive := time.NewTicker(time.Minute * 5)
	go func() {
		for _ = range dbKeepalive.C {
			err := db.Ping()
			if err != nil {
				log.Println("DB Connection droppped")
			}
		}
	}()

	anonSessions, err = session.NewManager("memory", `{"cookieName":"anonsession_id","gclifetime":3600}`)
	if err != nil {
		log.Println(err)
	}
	go anonSessions.GC()

	globalSessions, err = session.NewManager("memory", `{"cookieName":"session_id","gclifetime":3600}`)
	if err != nil {
		log.Println(err)
	}
	go globalSessions.GC()
}
开发者ID:nathan-tebay,项目名称:superflyreports,代码行数:31,代码来源:userAuth.go


示例2: registerSession

func registerSession() error {
	if BConfig.WebConfig.Session.SessionOn {
		var err error
		sessionConfig := AppConfig.String("sessionConfig")
		if sessionConfig == "" {
			conf := map[string]interface{}{
				"cookieName":      BConfig.WebConfig.Session.SessionName,
				"gclifetime":      BConfig.WebConfig.Session.SessionGCMaxLifetime,
				"providerConfig":  filepath.ToSlash(BConfig.WebConfig.Session.SessionProviderConfig),
				"secure":          BConfig.Listen.EnableHTTPS,
				"enableSetCookie": BConfig.WebConfig.Session.SessionAutoSetCookie,
				"domain":          BConfig.WebConfig.Session.SessionDomain,
				"cookieLifeTime":  BConfig.WebConfig.Session.SessionCookieLifeTime,
			}
			confBytes, err := json.Marshal(conf)
			if err != nil {
				return err
			}
			sessionConfig = string(confBytes)
		}
		if GlobalSessions, err = session.NewManager(BConfig.WebConfig.Session.SessionProvider, sessionConfig); err != nil {
			return err
		}
		go GlobalSessions.GC()
	}
	return nil
}
开发者ID:ysqi,项目名称:beego,代码行数:27,代码来源:hooks.go


示例3: NewSession

func NewSession(config SessionConfig) (Session, error) {
	if config.Driver == "" {
		return nil, nil
	}
	if config.CookieName == "" {
		config.CookieName = "beego_session"
	}
	if config.CookieLifeTime == 0 {
		config.CookieLifeTime = 3600
	}
	if config.GcLifeTime == 0 {
		config.GcLifeTime = 3600
	}
	result, err := json.Marshal(config)
	if err != nil {
		return nil, err
	}

	sessionManager, err := session.NewManager(config.Driver, string(result))
	if err != nil {
		return nil, err
	}
	go sessionManager.GC()

	return &sessionImplement{
		Manager: sessionManager,
		config:  config,
	}, nil
}
开发者ID:fishedee,项目名称:fishgo,代码行数:29,代码来源:util_session.go


示例4: Logout

func (logout *ManageController) Logout() {
	globalSessions, _ = session.NewManager("memory", `{"cookieName":"OpenSess", "enableSetCookie,omitempty": true, "gclifetime":900, "maxLifetime": 0, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 0, "providerConfig": ""}`)
	go globalSessions.GC()

	globalSessions.SessionDestroy(logout.Ctx.ResponseWriter, logout.Ctx.Request)
	logout.Redirect("/login", 302)
}
开发者ID:GeoLyu,项目名称:Gopen,代码行数:7,代码来源:user.go


示例5: registerSession

func registerSession() error {
	if BConfig.WebConfig.Session.SessionOn {
		var err error
		sessionConfig := AppConfig.String("sessionConfig")
		conf := new(session.ManagerConfig)
		if sessionConfig == "" {
			conf.CookieName = BConfig.WebConfig.Session.SessionName
			conf.EnableSetCookie = BConfig.WebConfig.Session.SessionAutoSetCookie
			conf.Gclifetime = BConfig.WebConfig.Session.SessionGCMaxLifetime
			conf.Secure = BConfig.Listen.EnableHTTPS
			conf.CookieLifeTime = BConfig.WebConfig.Session.SessionCookieLifeTime
			conf.ProviderConfig = filepath.ToSlash(BConfig.WebConfig.Session.SessionProviderConfig)
			conf.Domain = BConfig.WebConfig.Session.SessionDomain
			conf.EnableSidInHttpHeader = BConfig.WebConfig.Session.EnableSidInHttpHeader
			conf.SessionNameInHttpHeader = BConfig.WebConfig.Session.SessionNameInHttpHeader
			conf.EnableSidInUrlQuery = BConfig.WebConfig.Session.EnableSidInUrlQuery
		} else {
			if err = json.Unmarshal([]byte(sessionConfig), conf); err != nil {
				return err
			}
		}
		if GlobalSessions, err = session.NewManager(BConfig.WebConfig.Session.SessionProvider, conf); err != nil {
			return err
		}
		go GlobalSessions.GC()
	}
	return nil
}
开发者ID:GrimTheReaper,项目名称:beego,代码行数:28,代码来源:hooks.go


示例6: Run

func Run() {
	if AppConfigPath != path.Join(AppPath, "conf", "app.conf") {
		err := ParseConfig()
		if err != nil {
			if RunMode == "dev" {
				Warn(err)
			}
		}
	}
	if PprofOn {
		BeeApp.Router(`/debug/pprof`, &ProfController{})
		BeeApp.Router(`/debug/pprof/:pp([\w]+)`, &ProfController{})
	}
	if SessionOn {
		GlobalSessions, _ = session.NewManager(SessionProvider, SessionName, SessionGCMaxLifetime, SessionSavePath)
		go GlobalSessions.GC()
	}
	err := BuildTemplate(ViewsPath)
	if err != nil {
		if RunMode == "dev" {
			Warn(err)
		}
	}
	runtime.GOMAXPROCS(runtime.NumCPU())
	registerErrorHander()
	BeeApp.Run()
}
开发者ID:kyx114,项目名称:beego,代码行数:27,代码来源:beego.go


示例7: init

func init() {
	// GlobalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
	GlobalSessions, _ = session.NewManager("file", `{"cookieName":"gosessionid","sessionsavepath":"./sessionpath/", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
	// GlobalSessions, _ = session.NewManager("mysql", `{"cookieName":"gosessionid","sessionsavepath":"./sessionpath/", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": "root:[email protected](localhost:3306)/session?charset=utf8"}`)
	// GlobalSessions, _ = session.NewManager("mysql", `{"cookieName":"gosessionid","sessionsavepath":"./sessionpath/", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": "cdb_outerroot:[email protected](55c354e17de4e.sh.cdb.myqcloud.com:7276)/session?charset=utf8"}`)
	defer GlobalSessions.GC()
}
开发者ID:shaalx,项目名称:bbs,代码行数:7,代码来源:session_init.go


示例8: Run

func Run() {
	//if AppConfigPath not In the conf/app.conf reParse config
	if AppConfigPath != path.Join(AppPath, "conf", "app.conf") {
		err := ParseConfig()
		if err != nil {
			if RunMode == "dev" {
				Warn(err)
			}
		}
	}

	if SessionOn {
		GlobalSessions, _ = session.NewManager(SessionProvider, SessionName, SessionGCMaxLifetime, SessionSavePath, HttpTLS)
		go GlobalSessions.GC()
	}

	err := BuildTemplate(ViewsPath)
	if err != nil {
		if RunMode == "dev" {
			Warn(err)
		}
	}

	middleware.VERSION = VERSION
	middleware.AppName = AppName
	middleware.RegisterErrorHander()

	BeeApp.Run()
}
开发者ID:voicedata,项目名称:beego,代码行数:29,代码来源:beego.go


示例9: init

func init() {
	gothic.Store = sessions.NewFilesystemStore(os.TempDir(), []byte("goth-example"))
	goth.UseProviders(
		twitter.New(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitter/callback"),
		// If you'd like to use authenticate instead of authorize in Twitter provider, use this instead.
		// twitter.NewAuthenticate(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitter/callback"),

		facebook.New(os.Getenv("FACEBOOK_KEY"), os.Getenv("FACEBOOK_SECRET"), "http://localhost:3000/auth/facebook/callback"),
		gplus.New("281140391713-b1dskle4dtsi6nn4ce01tbkpcp3aovs6.apps.googleusercontent.com", "cIM92vsFvLyfhIZASmAo2ZaE", "http://localhost:8080/auth/gplus/callback"),
		github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), "http://localhost:3000/auth/github/callback"),
		spotify.New(os.Getenv("SPOTIFY_KEY"), os.Getenv("SPOTIFY_SECRET"), "http://localhost:3000/auth/spotify/callback"),
		linkedin.New(os.Getenv("LINKEDIN_KEY"), os.Getenv("LINKEDIN_SECRET"), "http://localhost:3000/auth/linkedin/callback"),
		lastfm.New(os.Getenv("LASTFM_KEY"), os.Getenv("LASTFM_SECRET"), "http://localhost:3000/auth/lastfm/callback"),
		twitch.New(os.Getenv("TWITCH_KEY"), os.Getenv("TWITCH_SECRET"), "http://localhost:3000/auth/twitch/callback"),
		dropbox.New(os.Getenv("DROPBOX_KEY"), os.Getenv("DROPBOX_SECRET"), "http://localhost:3000/auth/dropbox/callback"),
		digitalocean.New(os.Getenv("DIGITALOCEAN_KEY"), os.Getenv("DIGITALOCEAN_SECRET"), "http://localhost:3000/auth/digitalocean/callback", "read"),
		bitbucket.New(os.Getenv("BITBUCKET_KEY"), os.Getenv("BITBUCKET_SECRET"), "http://localhost:3000/auth/bitbucket/callback"),
		instagram.New(os.Getenv("INSTAGRAM_KEY"), os.Getenv("INSTAGRAM_SECRET"), "http://localhost:3000/auth/instagram/callback"),
		box.New(os.Getenv("BOX_KEY"), os.Getenv("BOX_SECRET"), "http://localhost:3000/auth/box/callback"),
		salesforce.New(os.Getenv("SALESFORCE_KEY"), os.Getenv("SALESFORCE_SECRET"), "http://localhost:3000/auth/salesforce/callback"),
		amazon.New(os.Getenv("AMAZON_KEY"), os.Getenv("AMAZON_SECRET"), "http://localhost:3000/auth/amazon/callback"),
		yammer.New(os.Getenv("YAMMER_KEY"), os.Getenv("YAMMER_SECRET"), "http://localhost:3000/auth/yammer/callback"),
		onedrive.New(os.Getenv("ONEDRIVE_KEY"), os.Getenv("ONEDRIVE_SECRET"), "http://localhost:3000/auth/onedrive/callback"),
	)

	//set a global session
	globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
	go globalSessions.GC()
}
开发者ID:eraserxp,项目名称:coedit,代码行数:29,代码来源:auth.go


示例10: init

// https://github.com/astaxie/build-web-application-with-golang/blob/master/en/preface.md
func init() {
	// https://github.com/astaxie/beego/blob/master/session/session.go

	// globalSessions, _ = session.NewManager("redis", `{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:6379,100,astaxie"}`)

	// globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
	// secure means force https
	f, err := os.Open("config.json")
	defer f.Close()

	checkError(err, "cannot load log file")

	// https://github.com/creamdog/gonfig
	config, err := gonfig.FromJson(f)
	checkError(err, "Could not parse config from file")
	cfg := make(map[string]interface{})
	err = config.GetAs("credentials/redis_session", &cfg)
	checkError(err, "could not read redis_session configuration")
	fmt.Printf("config is %v\n", cfg)
	s, err := json.Marshal(cfg)
	checkError(err, fmt.Sprintf("Error marshaling struct %v", cfg))
	GlobalSessions, err = session.NewManager("redis", string(s))
	checkError(err, "Error Establishing Redis Session")
	go GlobalSessions.GC()
}
开发者ID:abualsamid,项目名称:tinyblog,代码行数:26,代码来源:auth.go


示例11: init

func init() {
	log.SetLevel(log.DebugLevel)
	// do a deep copy for etree of job config.xml
	JobConfig = etree.NewDocument()
	if err := JobConfig.ReadFromFile(BaseCfg); err != nil {
		log.Errorf(err.Error())
		return
	}
	/*
		// connect mongodb
		MgoDB = getMongoDB()
		if MgoDB == nil {
			return
		}
	*/
	// session uses memory
	GlobalSessions, _ = session.NewManager(
		"memory", `{"cookieName":"sessionId","enableSetCookie":true,"gclifetime":30,"ProviderConfig":"{\"cookieName\":\"sessionId\",\"securityKey\":\"beegocookiehashkey\"}"}`)
	go GlobalSessions.GC()
	JenkinsClient = make(map[string]*gojenkins.Jenkins)
	/*
		for {
			JenkinsClient = getJenkinsClient()
			if JenkinsClient == nil {
				time.Sleep(10)
				continue
			} else {
				break
			}
		}
	*/
}
开发者ID:zhanglianx111,项目名称:lasa,代码行数:32,代码来源:handlers.go


示例12: initBeforeHttpRun

func initBeforeHttpRun() {
	// if AppConfigPath not In the conf/app.conf reParse config
	if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") {
		err := ParseConfig()
		if err != nil && AppConfigPath != filepath.Join(workPath, "conf", "app.conf") {
			// configuration is critical to app, panic here if parse failed
			panic(err)
		}
	}

	// do hooks function
	for _, hk := range hooks {
		err := hk()
		if err != nil {
			panic(err)
		}
	}

	if SessionOn {
		var err error
		sessionConfig := AppConfig.String("sessionConfig")
		if sessionConfig == "" {
			sessionConfig = `{"cookieName":"` + SessionName + `",` +
				`"gclifetime":` + strconv.FormatInt(SessionGCMaxLifetime, 10) + `,` +
				`"providerConfig":"` + SessionSavePath + `",` +
				`"secure":` + strconv.FormatBool(EnableHttpTLS) + `,` +
				`"sessionIDHashFunc":"` + SessionHashFunc + `",` +
				`"sessionIDHashKey":"` + SessionHashKey + `",` +
				`"enableSetCookie":` + strconv.FormatBool(SessionAutoSetCookie) + `,` +
				`"domain":"` + SessionDomain + `",` +
				`"cookieLifeTime":` + strconv.Itoa(SessionCookieLifeTime) + `}`
		}
		GlobalSessions, err = session.NewManager(SessionProvider,
			sessionConfig)
		if err != nil {
			panic(err)
		}
		go GlobalSessions.GC()
	}

	err := BuildTemplate(ViewsPath)
	if err != nil {
		if RunMode == "dev" {
			Warn(err)
		}
	}

	middleware.VERSION = VERSION
	middleware.AppName = AppName
	middleware.RegisterErrorHandler()

	if EnableDocs {
		Get("/docs", serverDocs)
		Get("/docs/*", serverDocs)
	}

	//init mime
	AddAPPStartHook(initMime)
}
开发者ID:6pig9,项目名称:beego,代码行数:59,代码来源:beego.go


示例13: InitSession

func InitSession() *Session {
	if appSession == nil {
		appSession = &Session{}
		appSession.manager, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
		go appSession.manager.GC()
	}
	return appSession
}
开发者ID:artwebs,项目名称:aogo,代码行数:8,代码来源:AppSession.go


示例14: Init

func Init() {
	var err error
	sessionConfig := fmt.Sprintf(`{"cookieName":"gosessionid","gclifetime":%d,"ProviderConfig":"%s"}`,
		conf.Int("session", "GC_LIFETIME"),
		fmt.Sprintf("%s, %d", conf.String("redis", "REDIS_SERVER"), conf.Int("session", "SESSION_LENGTH")),
	)
	sessionManager, err = session.NewManager(conf.String("session", "PROVIDER"), sessionConfig)
	if err != nil {
		panic(err)
	}

	//go sessionManager.GC()
}
开发者ID:xtudouh,项目名称:web,代码行数:13,代码来源:sessions.go


示例15: init

///////////////////////////////////////////////////////
// init function
func init() {
	conf := new(session.ManagerConfig)
	conf.CookieName = "computerspielplatzID"
	conf.EnableSetCookie = true
	conf.Gclifetime = 3600
	conf.Secure = false
	conf.CookieLifeTime = 3600
	conf.ProviderConfig = ""

	globalSessions, _ = session.NewManager("memory", conf)
	go globalSessions.GC()

	SessionXsrfTable.Tokens = make(map[string]SessionXsrfStruct)
}
开发者ID:lafisrap,项目名称:Computer-Spielplatz,代码行数:16,代码来源:controllers.go


示例16: init

func init() {
	GlobalSessions, _ = session.NewManager("memory", `{
												"cookieName":"lte_securityid",
												"enableSetCookie,omitempty": true,
												"gclifetime":3600,
												"maxLifetime": 3600,
												"secure": true,
												"sessionIDHashFunc": "sha1",
												"sessionIDHashKey": "",
												"cookieLifeTime": 3600,
												"providerConfig": ""}`)
	go GlobalSessions.GC()
	beego.SetLogger("file", `{"filename":"logs/server.log"}`)
	beego.SetLevel(beego.LevelDebug)
}
开发者ID:tcdog001,项目名称:szm_lss,代码行数:15,代码来源:main.go


示例17: init

func init() {
	globalSessions, _ = session.NewManager("memory",
		`{
			"cookieName":"gosessionid",
			"enableSetCookie,omitempty": true,
			"gclifetime":3600,
			"maxLifetime": 3600,
			"secure": false,
			"sessionIDHashFunc": "sha1",
			"sessionIDHashKey": "",
			"cookieLifeTime": 3600,
			"providerConfig": ""
		}`)
	go globalSessions.GC()
}
开发者ID:BrianLyeo,项目名称:beegoblogs,代码行数:15,代码来源:loginctl.go


示例18: Run

func Run() {
	if PprofOn {
		BeeApp.Router(`/debug/pprof`, &ProfController{})
		BeeApp.Router(`/debug/pprof/:pp([\w]+)`, &ProfController{})
	}
	if SessionOn {
		GlobalSessions, _ = session.NewManager(SessionProvider, SessionName, SessionGCMaxLifetime, SessionSavePath)
		go GlobalSessions.GC()
	}
	err := BuildTemplate(ViewsPath)
	if err != nil {
		Warn(err)
	}
	BeeApp.Run()
}
开发者ID:blwidow,项目名称:beego,代码行数:15,代码来源:beego.go


示例19: init

func init() {
	// GlobalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
	// GlobalSessions, _ = session.NewManager("file", `{"cookieName":"gosessionid","sessionsavepath":"./sessionpath/", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
	ssn := session.ManagerConfig{}
	ssn.CookieName = "gosessionid"
	ssn.EnableSetCookie = true
	ssn.Gclifetime = 3600
	ssn.EnableSetCookie = true
	ssn.Maxlifetime = 3600

	GlobalSessions, _ = session.NewManager("file", &ssn)
	// GlobalSessions, _ = session.NewManager("mysql", `{"cookieName":"gosessionid","sessionsavepath":"./sessionpath/", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": "root:[email protected](localhost:3306)/session?charset=utf8"}`)
	// GlobalSessions, _ = session.NewManager("mysql", `{"cookieName":"gosessionid","sessionsavepath":"./sessionpath/", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": "goojle:[email protected](121.42.161.248:3306)/gooj?charset=utf8"}`)
	// GlobalSessions, _ = session.NewManager("mysql", `{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"goojle:[email protected](121.42.161.248:3306)/gooj?charset=utf8"}`)
	// GlobalSessions, _ = session.NewManager("mysql", `{"cookieName":"gosessionid","sessionsavepath":"./sessionpath/", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": "goojle:[email protected](121.42.161.248:3306)/gooj?charset=utf8"}`)
	defer GlobalSessions.GC()
}
开发者ID:shaalx,项目名称:gooj,代码行数:17,代码来源:session_init.go


示例20: Login

func (login *ManageController) Login() {
	login.TplNames = "user/login.html"

	globalSessions, _ = session.NewManager("memory", `{"cookieName":"OpenSess", "enableSetCookie,omitempty": true, "gclifetime":900, "maxLifetime": 0, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 0, "providerConfig": ""}`)
	go globalSessions.GC()

	sess, _ := globalSessions.SessionStart(login.Ctx.ResponseWriter, login.Ctx.Request)
	defer sess.SessionRelease(login.Ctx.ResponseWriter)

	login.Data["id"] = sess.Get("id")

	o := orm.NewOrm()
	o.Using("default")

	if login.Ctx.Input.Method() == "POST" {
		var id, password string
		login.Ctx.Input.Bind(&id, "id")
		login.Ctx.Input.Bind(&password, "password")
		user := models.User{}

		pass := fmt.Sprintf("%x", sha512.Sum512([]byte(password)))

		serchUser, err := o.QueryTable("user").Filter("Id", id).All(&user)

		dk := pbkdf2.Key([]byte(pass), []byte(user.Salt), 4096, 64, sha512.New)
		insertPW := fmt.Sprintf("%x", dk)

		if serchUser == 0 || err == orm.ErrNoRows {
			beego.Debug(err)
			login.Data["err"] = true
		} else {
			if insertPW == user.Password {
				// 세션 생성
				sess.Set("is_login", true)
				sess.Set("id", id)
				sess.Set("password", password)

				login.Data["Checking"] = true
				login.Redirect("/login", 302)
			} else {
				login.Data["err"] = true
			}
		}
	}
}
开发者ID:GeoLyu,项目名称:Gopen,代码行数:45,代码来源:user.go



注:本文中的github.com/astaxie/beego/session.NewManager函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang session.Register函数代码示例发布时间:2022-05-24
下一篇:
Golang session.EncodeGob函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap