BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / accountSystem.js

accountSystem.js

Accountsystem, textinput
timfa Tim Falken · pushed by timfa · 8 years ago
d4106eb9 History
accountSystem.js 1.8 KiB Download Raw
1var AccountSystem =
2{
3 findByFullName: function(name)
4 {
5 var url = "http://timfalken.com/account/?action=find&query=" + name;
6
7 this.getJSON(url, function(status, response)
8 {
9 context = context || this;
10
11 callback && callback.call(this, response);
12 })
13 },
14
15 loadUserImage: function(user, callback, context)
16 {
17 var avatarImage = new image(user.avatar + ".png");
18
19 timingUtil.delay(100, function()
20 {
21 context = context || this;
22
23 callback && callback.call(this, avatarImage);
24 }, this);
25 },
26
27 login: function(email, password, callback, context)
28 {
29 var url = "http://timfalken.com/account/?action=login&email=" + email + "&password=" + btoa(password);
30 this.getJSON(url, function(status, response)
31 {
32 context = context || this;
33
34 callback && callback.call(this, response);
35 })
36 },
37
38 setData: function(email, password, data, callback, context)
39 {
40 var url = "http://timfalken.com/account/?action=updatedata&key=emVybzIxMTI=&email=" + email + "&password=" + btoa(password) + "&newdata=" + btoa(JSON.stringify(data));
41 this.getJSON(url, function(status, response)
42 {
43 context = context || this;
44
45 callback && callback.call(this, response);
46 })
47 },
48
49 getJSON: function(url, callback) {
50 var xhr = new XMLHttpRequest();
51 xhr.open('GET', url, true);
52 xhr.responseType = 'json';
53 xhr.onload = function() {
54 var status = xhr.status;
55 if (status === 200) {
56 callback(null, xhr.response);
57 } else {
58 callback(status, xhr.response);
59 }
60 };
61 xhr.send();
62 }
63}