Пример #1
0
func (s *authService) getUser(authSession goth.Session) (users.User, bool) {
	guser, err := s.provider.FetchUser(authSession)
	if err != nil {
		log.Error(fmt.Sprintf("Error fetching user: %v", err))
		return users.User{}, false
	}

	if guser.RawData["error"] != nil {
		log.Info("User Session Expired")
		return users.User{}, false
	}

	u, found := s.Users.GetByAuthId(guser.UserID)
	if found {
		u.Name = guser.NickName
		u.AvatarUrl = guser.AvatarURL
		u.AccessToken = guser.AccessToken
		u.AccessTokenSecret = guser.AccessTokenSecret
	} else {
		u = users.User{
			Name:              guser.NickName,
			AvatarUrl:         guser.AvatarURL,
			AuthIdentifier:    guser.UserID,
			Uuid:              users.NewId(),
			AccessToken:       guser.AccessToken,
			AccessTokenSecret: guser.AccessTokenSecret,
		}
	}

	s.Users.Save(&u)

	return u, true
}
Пример #2
0
func (suite *IntegrationTestSuite) SetupTest() {
	configProvider := config.NewConfigProvider("testconfig", "./")

	suite.log = logger.Log("integration_test")

	suite.Commands = commands.New()
	suite.Queries = queries.NewClientQueryService()

	systemQueries := queries.NewSystemQueryService().(*queries.SystemQueryService)
	eventsService := events.NewEvents().(*events.EventsService)
	usersService := users.NewUsers().(*users.UsersService)

	d := directory.New()
	d.AddService("configProvider", configProvider)
	d.AddService("gameCalculator", game.NewGameCalculator())
	d.AddService("eventSubscriber", queries.NewQueryBuffer())

	d.AddService("systemQueries", systemQueries)
	d.AddService("events", eventsService)
	d.AddService("users", usersService)

	d.AddService("commands", suite.Commands)
	d.AddService("clientQueries", suite.Queries)

	err := d.Start()
	if err != nil {
		suite.log.Fatalf("Could not start directory: %v", err)
	}

	err = d.Start("eventSubscriber")
	if err != nil {
		msg := fmt.Sprintf("Could not start event subscriber: %v", err)
		log.Error(msg)
		return
	}

	usersService.ResetTestDB()
	eventsService.ResetTestDB()
	systemQueries.Cache.Flush()

	time.Sleep(1 * time.Second)

	white := users.User{
		Uuid:           users.NewId(),
		Name:           "whitePlayer",
		AuthIdentifier: "whiteAuthId",
	}
	usersService.Save(&white)

	black := users.User{
		Uuid:           users.NewId(),
		Name:           "blackPlayer",
		AuthIdentifier: "blackAuthId",
	}
	usersService.Save(&black)

	suite.log.Info("white UUID: %s", white.Uuid)
	suite.log.Info("black UUID: %s", black.Uuid)
	suite.whiteId = white.Uuid
	suite.blackId = black.Uuid
}