Ejemplo n.º 1
0
func (this *sqlAccountRepository) GetAccountByUserId(userId string) (*entities.Account, error) {
	const SQL = "SELECT userid, password, roles FROM account WHERE userId=?"
	result := entities.Account{}
	var roles string
	err := this.tx.QueryRow(SQL, userId).
		Scan(&result.UserId,
		&result.Password,
		&roles)

	result.Roles = strings.Split(roles, ",")

	if err != nil {
		log.Error("sqlAccountRepository.GetAccountByUserId - Errror while retrieving account: " + err.Error())
		return nil, err
	}

	return &result, nil
}
Ejemplo n.º 2
0
func createTestAccount(settings configuration.SettingsProvider) {
	log.Info("Creating test account for test")
	dbProvider := NewSingletonDbProvider(settings)
	uowFactory := NewSqlUnitOfWorkFactory(dbProvider)
	uow, _ := uowFactory.CreateUnitOfWork(nil)
	accountRepository := uow.GetAccountRepository()

	existingAccount, _ := accountRepository.GetAccountByUserId("*****@*****.**")

	if existingAccount == nil {
		pw, _ := bcrypt.GenerateFromPassword([]byte("Ab12345!"), 14)
		newAccount := new(entities.Account)
		newAccount.UserId = "*****@*****.**"
		newAccount.Roles = []string{"user, admin"}
		newAccount.Password = pw
		accountRepository.CreateAccount(newAccount)
	}

	_ = uow.Commit()
}