Commit 10a74303 authored by zjubfd's avatar zjubfd
Browse files

updae recapcha

No related merge requests found
Showing with 35 additions and 16 deletions
+35 -16
......@@ -110,7 +110,7 @@ func main() {
for i := 0; i < *tiersFlag; i++ {
// Calculate the amount for the next tier and format it
amount := float64(*payoutFlag) * math.Pow(2.5, float64(i))
amounts[i] = fmt.Sprintf("%s BNBs", strconv.FormatFloat(amount, 'f', -1, 64))
amounts[i] = fmt.Sprintf("0.%s BNBs", strconv.FormatFloat(amount, 'f', -1, 64))
if amount == 1 {
amounts[i] = strings.TrimSuffix(amounts[i], "s")
}
......@@ -458,7 +458,7 @@ func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) {
form.Add("secret", *captchaSecret)
form.Add("response", msg.Captcha)
res, err := http.PostForm("https://www.google.com/recaptcha/api/siteverify", form)
res, err := http.PostForm("https://hcaptcha.com/siteverify", form)
if err != nil {
if err = sendError(conn, err); err != nil {
log.Warn("Failed to send captcha post error to client", "err", err)
......@@ -547,7 +547,7 @@ func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) {
var tx *types.Transaction
if msg.Symbol == "BNB" {
// User wasn't funded recently, create the funding transaction
amount := new(big.Int).Mul(big.NewInt(int64(*payoutFlag)), ether)
amount := new(big.Int).Div(new(big.Int).Mul(big.NewInt(int64(*payoutFlag)), ether), big.NewInt(10))
amount = new(big.Int).Mul(amount, new(big.Int).Exp(big.NewInt(5), big.NewInt(int64(msg.Tier)), nil))
amount = new(big.Int).Div(amount, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(msg.Tier)), nil))
......
......@@ -39,7 +39,9 @@
</head>
<body>
<div class="vertical-center">
<div id="recaptcha_element"></div>
<div id="contendBody" class="vertical-center">
<div class="container">
<div class="row" style="margin-bottom: 16px;">
<div class="col-lg-12">
......@@ -52,18 +54,18 @@
<input id="url" name="url" type="text" class="form-control" placeholder="Input your Binance Smart Chain address...">
<span class="input-group-btn">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Give me BNB <i class="fa fa-caret-down" aria-hidden="true"></i></button>
<ul class="dropdown-menu dropdown-menu-right">{{range $idx, $amount := .Amounts}}
<li><a style="text-align: center;" onclick="tier={{$idx}};symbol='BNB'; {{if $.Recaptcha}}grecaptcha.execute(){{else}}submit({{$idx}}){{end}}">{{$amount}}</a></li>{{end}}
<ul class="dropdown-menu dropdown-menu-right">
{{range $idx, $amount := .Amounts}}
<li ><a style="text-align: center;" onclick="tier={{$idx}};symbol='BNB';submit()">{{$amount}}</a></li>{{end}}
</ul>
</span>
<span class="input-group-btn">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Peggy tokens<i class="fa fa-caret-down" aria-hidden="true"></i></button>
<ul class="dropdown-menu dropdown-menu-right"> {{range $symbol, $bep2eInfo := .Bep2eInfos}}
<li><a style="text-align: center;" onclick="symbol={{$symbol}}; {{if $.Recaptcha}}grecaptcha.execute(){{else}}submitBep2e({{$symbol}}){{end}}">{{$bep2eInfo.AmountStr}} {{$symbol}}</a></li>{{end}}
<li><a style="text-align: center;" onclick="symbol={{$symbol}}; submit()">{{$bep2eInfo.AmountStr}} {{$symbol}}</a></li>{{end}}
</ul>
</span>
</div>{{if .Recaptcha}}
<div class="g-recaptcha" data-sitekey="{{.Recaptcha}}" data-callback="submit" data-size="invisible"></div>{{end}}
</div>
</div>
</div>
<div class="row" style="margin-top: 32px;">
......@@ -88,7 +90,7 @@
<h3>How does this work?</h3>
<p><a href="https://testnet.bscscan.com/address/0x6ce8dA28E2f864420840cF74474eFf5fD80E65B8">BTC</a>,<a href="https://testnet.bscscan.com/address/0xd66c6B4F0be8CE5b39D52E0Fd1344c389929B378">ETH</a>,<a href="https://testnet.bscscan.com/address/0xa83575490D7df4E2F47b7D38ef351a2722cA45b9">XRP</a>,<a href="https://testnet.bscscan.com/address/0xed24fc36d5ee211ea25a80239fb8c4cfd80f12ee">BUSD</a>,<a href="https://testnet.bscscan.com/address/0x337610d27c682E347C9cD60BD4b3b107C9d34dDd">USDT</a>,<a href="https://testnet.bscscan.com/address/0x64544969ed7EBf5f083679233325356EbE738930">USDC</a>,<a href="https://testnet.bscscan.com/address/0xEC5dCb5Dbf4B114C9d0F65BcCAb49EC54F6A0867">DAI</a> are issued as BEP20 token.</p>
<p> Click to get detail about <a href="https://github.com/binance-chain/BEPs/blob/master/BEP20.md">BEP20</a>.</p>
{{if .Recaptcha}}<em>The faucet is running invisible reCaptcha protection against bots.</em>{{end}}
{{if .Recaptcha}}<em>The faucet is running reCaptcha protection against bots.</em>{{end}}
</div>
</div>
</div>
......@@ -101,6 +103,7 @@
var tier = 0;
var symbol="";
var requests = [];
var captcha;
// Define a function that creates closures to drop old requests
var dropper = function(hash) {
......@@ -113,10 +116,25 @@
}
}
};
document.getElementById("contendBody").style.display = "none";
var recaptchaCallback = function() {
hcaptcha.render('recaptcha_element', {
'sitekey' : '{{.Recaptcha}}',
'callback' : assignCallback,
});
};
var assignCallback = function(gcaptcha) {
document.getElementById("contendBody").style.display = "block";
document.getElementById("recaptcha_element").style.display = "none";
captcha = gcaptcha;
};
// Define the function that submits a gist url to the server
var submit = function({{if .Recaptcha}}captcha{{end}}) {
var submit = function() {
server.send(JSON.stringify({url: $("#url")[0].value, symbol: symbol, tier: tier{{if .Recaptcha}}, captcha: captcha{{end}}}));{{if .Recaptcha}}
grecaptcha.reset();{{end}}
hcaptcha.reset();{{end}}
};
// Define a method to reconnect upon server loss
var reconnect = function() {
......@@ -223,6 +241,7 @@
// Establish a websocket connection to the API server
reconnect();
</script>{{if .Recaptcha}}
<script src="https://www.google.com/recaptcha/api.js" async defer></script>{{end}}
<script src="https://js.hcaptcha.com/1/api.js?onload=recaptchaCallback&render=explicit"
async defer></script>{{end}}
</body>
</html>
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment