예제 #1
0
// CreatePlayerAccount creates the account if it does not already exists.
func CreatePlayerAccount(account *models.PlayerAccount) (*models.PlayerAccount, error) {
	if err := account.ValidateAndCryptPassword(); err != nil {
		return nil, err
	}
	err := c(accountCollectionName).Insert(account)
	if err != nil && err.(*mgo.LastError).Code == 11000 {
		fmt.Println(err)
		return nil, fmt.Errorf(`login [%s] already taken`, account.Login)
	}
	refreshToken, accessToken, err := tokauth.Register(account.Login)
	if err != nil {
		return nil, err
	}
	account.AccessToken = accessToken
	account.RefreshToken = refreshToken
	return account, nil
}
예제 #2
0
// RefresPlayerAccount refreshes the token of the account.
func RefresPlayerAccount(account *models.PlayerAccount) (*models.PlayerAccount, error) {
	accessToken, err := tokauth.RefreshAndGetClient(account.RefreshToken, account)
	account.AccessToken = accessToken
	return account, err
}