Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CaptchaService.js « services « scripts « ngax « webroot « Server « Duplicati - github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 413b1ae956d00e217e42dcf51acddd026a8ef69b (plain)
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
backupApp.service('CaptchaService', function(DialogService, AppService, AppUtils, gettextCatalog) {
	this.active = null;
	var self = this;

    this.Authorize = function(title, message, target, callback) {

    	var cb = self.active = {
    		'message': message,
    		'target': target,
    		'callback': callback,
    		'attempts': 0,
    		'hasfailed': false,
    		'verifying': false
    	};

    	self.attemptSolve = function() {
    		if (cb.attempts >= 3) {
    			cb.attempts = 0;
    			cb.token = null;
    		}

	    	DialogService.htmlDialog(title, 'templates/captcha.html', [gettextCatalog.getString('Cancel'), gettextCatalog.getString('OK')], function(btn) {
	    		if (btn != 1) {
	    			self.active = null;
	    			return;
	    		}

				cb.attempts += 1;
				cb.verifying = true;
				

				DialogService.dialog(gettextCatalog.getString('Verifying answer'), gettextCatalog.getString('Verifying ...'), [], function() {}, function() {

		    		AppService.post('/captcha/' + encodeURIComponent(cb.token), {'answer': cb.answer, 'target': cb.target}).then(function(resp) {
		    			DialogService.dismissCurrent();
		    			self.active = null;
		    			cb.callback(cb.token, cb.answer);
		    		}, function(err) {

		    			DialogService.dismissCurrent();
						cb.verifying = false;
						cb.hasfailed = true;
						if (err.status == 400)
							self.attemptSolve();
						else
							AppUtils.connectionError(err);
		    		});

		    	});
	    	});
    	};

    	self.attemptSolve();
    };
});