コード例 #1
0
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()
}
コード例 #2
0
ファイル: hooks.go プロジェクト: ysqi/beego
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
}
コード例 #3
0
ファイル: util_session.go プロジェクト: fishedee/fishgo
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
}
コード例 #4
0
ファイル: user.go プロジェクト: GeoLyu/Gopen
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)
}
コード例 #5
0
ファイル: hooks.go プロジェクト: GrimTheReaper/beego
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
}
コード例 #6
0
ファイル: beego.go プロジェクト: kyx114/beego
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()
}
コード例 #7
0
ファイル: session_init.go プロジェクト: shaalx/bbs
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:1234@tcp(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:root1234@tcp(55c354e17de4e.sh.cdb.myqcloud.com:7276)/session?charset=utf8"}`)
	defer GlobalSessions.GC()
}
コード例 #8
0
ファイル: beego.go プロジェクト: voicedata/beego
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()
}
コード例 #9
0
ファイル: auth.go プロジェクト: eraserxp/coedit
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()
}
コード例 #10
0
ファイル: auth.go プロジェクト: abualsamid/tinyblog
// 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()
}
コード例 #11
0
ファイル: handlers.go プロジェクト: zhanglianx111/lasa
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
			}
		}
	*/
}
コード例 #12
0
ファイル: beego.go プロジェクト: 6pig9/beego
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)
}
コード例 #13
0
ファイル: AppSession.go プロジェクト: artwebs/aogo
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
}
コード例 #14
0
ファイル: sessions.go プロジェクト: xtudouh/web
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()
}
コード例 #15
0
///////////////////////////////////////////////////////
// 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)
}
コード例 #16
0
ファイル: main.go プロジェクト: tcdog001/szm_lss
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)
}
コード例 #17
0
ファイル: loginctl.go プロジェクト: BrianLyeo/beegoblogs
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()
}
コード例 #18
0
ファイル: beego.go プロジェクト: blwidow/beego
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()
}
コード例 #19
0
ファイル: session_init.go プロジェクト: shaalx/gooj
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:1234@tcp(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:Goojle1234@tcp(121.42.161.248:3306)/gooj?charset=utf8"}`)
	// GlobalSessions, _ = session.NewManager("mysql", `{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"goojle:Goojle1234@tcp(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:Goojle1234@tcp(121.42.161.248:3306)/gooj?charset=utf8"}`)
	defer GlobalSessions.GC()
}
コード例 #20
0
ファイル: user.go プロジェクト: GeoLyu/Gopen
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
			}
		}
	}
}
コード例 #21
0
ファイル: beego.go プロジェクト: slene/beego
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 {
			// configuration is critical to app, panic here if parse failed
			panic(err)
		}
	}

	//init mime
	initMime()

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

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

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

	if EnableAdmin {
		go BeeAdminApp.Run()
	}

	BeeApp.Run()
}
コード例 #22
0
func main() {
	tracelog.Start(tracelog.LevelTrace)

	// Init mongo
	tracelog.Started("main", "Initializing Mongo")
	err := mongo.Startup(helper.MainGoRoutine)
	if err != nil {
		tracelog.CompletedError(err, helper.MainGoRoutine, "initApp")
		os.Exit(1)
	}

	// Load message strings
	localize.Init("en-US")
	beego.BConfig.WebConfig.Session.SessionOn = true
	globalSessions, _ = session.NewManager("redis", `{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:6379"}`)
	go globalSessions.GC()
	beego.Run()

	tracelog.Completed(helper.MainGoRoutine, "Website Shutdown")
	tracelog.Stop()
}
コード例 #23
0
ファイル: main.go プロジェクト: kameleon83/raspDlna
func main() {
	globalSessions, _ = session.NewManager("memory",
		`{"cookieName":"gosessionid",
						"enableSetCookie,omitempty": true,
						"gclifetime":3600,
						"maxLifetime": 3600,
						"secure": false,
						"sessionIDHashFunc": "sha1",
						"sessionIDHashKey": "",
						"cookieLifeTime": 3600,
						 "providerConfig": ""}
						`)
	go globalSessions.GC()

	if beego.SessionOn != true {
		beego.SessionOn = true
		beego.SessionName = "raspDlna"
		beego.SessionProvider = "file"
		beego.SessionSavePath = "./tmp"
	}

	beego.Run()
}
コード例 #24
0
ファイル: main.go プロジェクト: gitter-badger/notedown
func main() {

	if _, err := parser.Parse(); err != nil {
		panic(err)
		os.Exit(1)
	}

	if len(opts.Verbose) >= 1 {
		fmt.Printf("Mongo Uri: %s\n", opts.MongoUri)
		fmt.Printf("Mongo User: %s\n", opts.MongoUser)
		fmt.Printf("Mongo Password: %s\n", opts.MongoPassword)
	}

	GlobalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid","gclifetime":3600}`)
	go GlobalSessions.GC()

	repo.Init(MongoProperties{opts.MongoUri, opts.MongoUser, opts.MongoPassword})
	rtr := NewRouter()
	n := negroni.Classic()
	n.UseHandler(rtr)

	log.Fatal(http.ListenAndServe(":8080", n))
}
コード例 #25
0
ファイル: route.go プロジェクト: varding/beginner
func Run() {
	var err1 error
	globalSessions, err1 = session.NewManager("file", `{"cookieName":"sid","gclifetime":3600,"ProviderConfig":"./tmp"}`)
	if err1 != nil {
		log4go.Error("session manager init failed")
	}

	go globalSessions.GC()

	server = &http.Server{
		Addr:         "127.0.0.1:9090",
		Handler:      http.HandlerFunc(http_handler),
		ReadTimeout:  time.Minute,
		WriteTimeout: time.Minute,
	}

	//https://github.com/revel/revel/blob/master/server.go
	listener, err := net.Listen("tcp", "127.0.0.1:9090")
	if err != nil {
		log4go.Critical("Failed to listen:", err)
	}
	log4go.Info("server running :9090")
	log4go.Critical("Failed to serve:", server.Serve(listener))
}
コード例 #26
0
func init() {
	var err error
	globalSessions, err = session.NewManager("memory", `{"cookieName":"gosessionid","gclifetime":3600}`)
	checkErr(err)
}
コード例 #27
0
ファイル: main.go プロジェクト: arthur-o9ht/GoChat
func init() {
	globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid","gclifetime":3600}`)
	go globalSessions.GC()
}
コード例 #28
0
ファイル: routes.go プロジェクト: dnamenon/webshop
func init() {
	globalSessions, _ = session.NewManager("file", `{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"./auth"}`)
	go globalSessions.GC()

}
コード例 #29
0
ファイル: server.go プロジェクト: 8legd/hugocms
func ListenAndServe(addr string, auth Auth, dbType DatabaseType) {
	var db *gorm.DB
	var err error

	if dbType == DB_MySQL {
		dbConn := fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)", auth.UserName, auth.Password)
		db, err = gorm.Open("mysql", dbConn+"/hugocms_"+auth.UserName+"?charset=utf8&parseTime=True&loc=Local")
	} else {
		db, err = gorm.Open("sqlite3", "hugocms_"+auth.UserName+".db")
	}

	if err != nil {
		handleError(err)
	}
	db.LogMode(true)

	// to reset to an empty database drop the settings table
	if !db.HasTable(&models.Settings{}) {
		for _, table := range hugocms_qor.Tables {
			if err := db.DropTableIfExists(table).Error; err != nil {
				handleError(err)
			}
		}
	}

	for _, table := range hugocms_qor.Tables {
		if err := db.AutoMigrate(table).Error; err != nil {
			handleError(err)
		}
	}

	// Because this is a singleton a single record must already exist in the database (there is no create through QOR admin just update)
	db.FirstOrCreate(&models.Settings{})

	siteName := fmt.Sprintf("%s - Hugo CMS", auth.UserName)
	if err := setupConfig(addr, siteName, db, auth); err != nil {
		handleError(err)
	}

	// Add session support - used by Auth
	sessionLifetime := 3600 // session lifetime in seconds
	SessionManager, err = session.NewManager("memory", fmt.Sprintf(`{"cookieName":"gosessionid","gclifetime":%d}`, sessionLifetime))
	if err != nil {
		handleError(err)
	}
	go SessionManager.GC()

	// Create Hugo's content directory if it doesnt exist
	// TODO read content dir from config
	if _, err := os.Stat("./content"); os.IsNotExist(err) {
		err = os.MkdirAll("./content", os.ModePerm)
	}

	mux := http.NewServeMux()

	mux.Handle("/", http.FileServer(http.Dir("public")))

	adm := hugocms_qor.SetupAdmin()

	adm.MountTo("/admin", mux)
	adm.GetRouter().Post("/auth", func(ctx *admin.Context) {
		// we will only hit this on succesful login - redirect to admin dashboard
		w := ctx.Writer
		r := ctx.Request
		http.Redirect(w, r, "/admin", http.StatusFound)
	})
	adm.GetRouter().Get("/logout", func(ctx *admin.Context) {
		w := ctx.Writer
		r := ctx.Request
		sess, err := SessionManager.SessionStart(w, r)
		if err != nil {
			handleError(err)
		}
		defer sess.SessionRelease(w)
		sess.Delete("User")
		http.Redirect(w, r, "/login", http.StatusFound)
	})

	// NOTE: `system` is where QOR admin will upload files e.g. images - we map this to Hugo's static dir along with our other static assets
	// TODO read static dir from config
	// TODO read static assets list from config
	for _, path := range []string{"system", "css", "fonts", "images", "js", "login"} {
		mux.Handle(fmt.Sprintf("/%s/", path), http.FileServer(http.Dir("static")))
	}

	if err := http.ListenAndServe(config.QOR.Addr, mux); err != nil {
		handleError(err)
	}

	// to re-generate site delete `config.json`
	if _, err := os.Stat("config.json"); os.IsNotExist(err) {
		hugocms_qor.CallSave(adm)
	}

	fmt.Printf("Listening on: %s\n", config.QOR.Addr)
}
コード例 #30
0
ファイル: ecbg.go プロジェクト: eaciit/ecbg
func init() {
	if SessionMgr == nil {
		SessionMgr, _ = session.NewManager("memory", `{"cookieName":"ecsessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
		go SessionMgr.GC()
	}
}