forked from andi-bute/captcha-meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (52 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var visualCaptcha = null;
var VisualCaptcha = function(session) {
this.session = session;
}
VisualCaptcha.prototype.start = function(howmany) {
// After initializing visualCaptcha, we only need to generate new options
if ( ! visualCaptcha ) {
visualCaptcha = Npm.require( 'visualcaptcha' )( this.session );
}
visualCaptcha.generate( howmany );
return JSON.stringify(visualCaptcha.getFrontendData());
}
VisualCaptcha.prototype.getAudio = function(res, type) {
// It's not impossible this method is called before visualCaptcha is initialized, so we have to send a 404
if ( ! visualCaptcha ) {
return { error: true, errorCode: 404, errorMsg: 'Not Found' };
} else {
return visualCaptcha.getAudio( res, type);
}
}
VisualCaptcha.prototype.getImage = function(index, retina, response) {
var isRetina = false;
// It's not impossible this method is called before visualCaptcha is initialized, so we have to send a 404
if ( ! visualCaptcha ) {
return { error: true, errorCode: 404, errorMsg: 'Not Found' };
} else {
// Default is non-retina
if ( retina ) {
isRetina = true;
}
return visualCaptcha.getImage( index, response, isRetina);
}
}
VisualCaptcha.prototype.generate = function(num) {
return visualCaptcha.generate(num);
}
VisualCaptcha.prototype.getImageOptions = function() {
return visualCaptcha.getImageOptions();
}
VisualCaptcha.prototype.getValidImageOption = function() {
return visualCaptcha.getValidImageOptions();
}
VisualCaptcha.prototype.validateImage = function(sentOption) {
return visualCaptcha.validateImage(sentOption)
}
VisualCaptcha.prototype.validateAudio = function(opt) {
return visualCaptcha.validateAudio(opt);
}
VisualCaptcha.prototype.getFrontendData = function() {
return visualCaptcha.getFrontendData();
}
Meteor.VisualCaptcha = VisualCaptcha;