예제 #1
0
func LoginHandler(w http.ResponseWriter, r *http.Request) {
	if url, err := openid.RedirectURL("http://steamcommunity.com/openid",
		config.HTTPAddress()+"/openidcallback",
		config.Constants.OpenIDRealm); err == nil {
		http.Redirect(w, r, url, 303)
	} else {
		logrus.Debug(err.Error())
	}
}
예제 #2
0
func LoginCallbackHandler(w http.ResponseWriter, r *http.Request) {
	regex := regexp.MustCompile(`http://steamcommunity.com/openid/id/(\d+)`)

	fullURL := config.HTTPAddress() + r.URL.String()
	idURL, err := openid.Verify(fullURL, discoveryCache, nonceStore)
	if err != nil {
		logrus.Warning("%s", err.Error())
		return
	}

	parts := regex.FindStringSubmatch(idURL)
	if len(parts) != 2 {
		http.Error(w, "Steam Authentication failed, please try again.", 500)
		return
	}

	steamid := parts[1]

	if config.Constants.SteamIDWhitelist != "" &&
		!controllerhelpers.IsSteamIDWhitelisted(steamid) {
		//Use a more user-friendly message later
		http.Error(w, "Sorry, you're not in the closed alpha.", 403)
		return
	}
	err = setSession(w, r, steamid)
	if err != nil {
		session, _ := controllerhelpers.GetSessionHTTP(r)
		session.Options = &sessions.Options{MaxAge: -1}
		session.Save(r, w)

		logrus.Error(err.Error())
		http.Error(w, "Internal Server Error.", 500)
		return
	}
	http.Redirect(w, r, config.Constants.LoginRedirectPath, 303)
}
예제 #3
0
파일: main.go 프로젝트: gpittarelli/Helen
func main() {
	helpers.InitLogger()

	flag.Parse()
	if *flagGen {
		key := securecookie.GenerateRandomKey(64)
		if len(key) == 0 {
			logrus.Fatal("Couldn't generate random key")
		}

		base64Key := base64.StdEncoding.EncodeToString(key)
		fmt.Println(base64Key)
		return
	}

	config.SetupConstants()
	go rpc.StartRPC()

	if config.Constants.ProfilerEnable {
		address := "localhost:" + config.Constants.ProfilerPort
		go func() {
			graceful.Run(address, 1*time.Second, nil)
		}()
		logrus.Info("Running Profiler at %s", address)
	}

	pid := &pid.Instance{}
	if pid.Create() == nil {
		defer pid.Remove()
	}

	authority.RegisterTypes()
	helpers.InitAuthorization()
	database.Init()
	migrations.Do()
	stores.SetupStores()
	models.InitializeLobbySettings("./lobbySettingsData.json")

	models.ConnectRPC()
	models.DeleteUnusedServerRecords()
	go models.Ping()

	chelpers.InitGeoIPDB()
	if config.Constants.SteamIDWhitelist != "" {
		go chelpers.WhitelistListener()
	}
	// lobby := models.NewLobby("cp_badlands", 10, "a", "a", 1)

	mux := http.NewServeMux()
	routes.SetupHTTP(mux)
	socket.RegisterHandlers()

	if val := os.Getenv("DEPLOYMENT_ENV"); strings.ToLower(val) != "production" {
		// init static FileServer
		// TODO be careful to set this to correct location when deploying
		mux.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, r.URL.Path[1:])
		})
	}
	corsHandler := cors.New(cors.Options{
		AllowedOrigins:   config.AllowedCorsOrigins,
		AllowCredentials: true,
	}).Handler(context.ClearHandler(mux))

	// start the server
	logrus.Info("Serving on", config.HTTPAddress())
	graceful.Run(config.Constants.Address, 1*time.Second, corsHandler)
}