contract CrowdsaleFront is Ownable{
    //Crowdsale public provider;
    using SafeMath for uint256;
    mapping (address => uint256) internal userAmounts;
    mapping (address => uint256) internal rewardPayed;
    BwinCommons internal commons;
    function setCommons(address _addr) public onlyOwner {
        commons = BwinCommons(_addr);
    }
    // fallback function can be used to buy tokens
    function () public payable {
        buyTokens(msg.sender, 0, 999);
    }

    // low level token purchase function
    function buyTokens(address beneficiary, address _parent, uint256 _top) public payable returns(bool){
      bool ret;
      uint256 tokens;
      (ret, tokens) = Crowdsale(commons.get("Crowdsale")).buyTokens.value(msg.value)(beneficiary, beneficiary, _parent, _top);
      userAmounts[beneficiary] = userAmounts[beneficiary].add(tokens);
      require(ret);
    }

    function getTokensFromBuy(address _addr) public view returns (uint256){
      return userAmounts[_addr];
    }
    function rewardPayedOf(address _user) public view returns (uint256) {
      return rewardPayed[_user];
    }
    function rewardPay(address _user, uint256 amount) public {
      require(msg.sender == commons.get("Crowdsale"));
      rewardPayed[_user] = rewardPayed[_user].add(amount);
    }

    // @return true if crowdsale event has ended
    function hasEnded() public view returns (bool){
        return Crowdsale(commons.get("Crowdsale")).hasEnded();
    }

}
function buyTokens(address beneficiary, address _parent, uint256 _top) public payable returns(bool){
  bool ret;
  uint256 tokens;
  (ret, tokens) = Crowdsale(commons.get("Crowdsale")).buyTokens.value(msg.value)(beneficiary, beneficiary, _parent, _top);
  userAmounts[beneficiary] = userAmounts[beneficiary].add(tokens);
  require(ret);
}

// low level token purchase function