function generateContract(uint256 templateId,uint256 orderid) public returns(address){

        
        contractTemplate storage ct = contractTemplateAddresses[templateId];
        if(ct.contractGeneratorAddress!=0x0){
            address contractTemplateAddress = ct.contractGeneratorAddress;
            string templateName = ct.templateName;
            require(block.timestamp >= ct.startTime);
            require(block.timestamp <= ct.endTime);
            
            Generatable generator = Generatable(contractTemplateAddress);
            address target = generator.generate(ct.token,msg.sender,ct.cycle);
            
            userContract[] storage userContracts = userContractsMap[msg.sender];
            userContracts.push(userContract(templateId,orderid,target,1,now,now.add(uint256(1 days))));
            ContractCreated(msg.sender,templateId,orderid,target);
            return target;
        }else{
            revert();
        }
    }