BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / accountSystem.js

accountSystem.js

register in accountsystem
timfa Tim Falken · pushed by timfa · 8 years ago
fc1fe3aa History
accountSystem.js 2.2 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 register: function(name, email, password, callback, context)
39 {
40 var url = "http://timfalken.com/account/?action=register&username=" + name + "&email=" + email + "&password=" + btoa(password);
41 this.getJSON(url, function(status, response)
42 {
43 context = context || this;
44
45 callback && callback.call(this, response);
46 })
47 },
48
49 setData: function(email, password, data, callback, context)
50 {
51 var url = "http://timfalken.com/account/?action=updatedata&key=emVybzIxMTI=&email=" + email + "&password=" + btoa(password) + "&newdata=" + btoa(JSON.stringify(data));
52 this.getJSON(url, function(status, response)
53 {
54 context = context || this;
55
56 callback && callback.call(this, response);
57 })
58 },
59
60 getJSON: function(url, callback) {
61 var xhr = new XMLHttpRequest();
62 xhr.open('GET', url, true);
63 xhr.responseType = 'json';
64 xhr.onload = function() {
65 var status = xhr.status;
66 if (status === 200) {
67 callback(null, xhr.response);
68 } else {
69 callback(status, xhr.response);
70 }
71 };
72 xhr.send();
73 }
74}