-
-
Save javatlacati/65416b30651ac41789fe to your computer and use it in GitHub Desktop.
Dukescript simple accesible captcha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dew.demo.clickcaptcha; | |
import net.java.html.json.Model; | |
import net.java.html.json.Property; | |
import net.java.html.json.Function; | |
import net.java.html.json.ComputedProperty; | |
@Model(targetId="", className="Captcha", properties={ | |
@Property(name = "clicks", type=int.class), | |
@Property(name = "clicksEfectuados", type=int.class), | |
@Property(name = "image", type=String.class), | |
@Property(name = "alt", type=String.class) | |
}) | |
final class ClickCaptcha { | |
@Function static void increaseCounter(Captcha datamodel){ | |
datamodel.setClicksEfectuados(datamodel.getClicksEfectuados()+1); | |
} | |
@Function static void send(Captcha datamodel){ | |
if(datamodel.getClicksEfectuados() == datamodel.getClicks()){ | |
datamodel.setImage("http://findicons.com/files/icons/684/vistoon/256/check.png"); | |
datamodel.setAlt("Captcha exitoso"); | |
}else{ | |
datamodel.setImage("https://cdn3.iconfinder.com/data/icons/musthave/256/Delete.png"); | |
datamodel.setAlt("Captcha fallido reintente por favor"); | |
} | |
} | |
@Function static void retry(Captcha datamodel){ | |
datamodel.setClicksEfectuados(0); | |
datamodel.setClicks((int)(1+Math.round(Math.random()*21))); | |
datamodel.setImage(""); | |
datamodel.setAlt(""); | |
} | |
private String numberToString(int number){ | |
return ""; | |
} | |
@ComputedProperty static String instructions(int clicks, int clicksEfectuados) { | |
return "De click "+clicks+" veces exactamente para acceder. Usted ha dado "+clicksEfectuados+" clicks"; | |
} | |
public static void main(String... args) { | |
int result = (int)(1+Math.round(Math.random()*21)); | |
Captcha datamodel = new Captcha(result,0,"",""); | |
datamodel.applyBindings(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button class="btn" id="button" data-bind="text: instructions, click:increaseCounter"></button><br> | |
<button class="btn" id="send" data-bind="click:send">Acceder</button> | |
<img data-bind="attr: {'src' : $root.image, 'alt': $root.alt, 'height':20, 'width': 20}"></img> | |
<button class="btn" id="retry" data-bind="click:retry">Reintentar</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment