PageSourceSearch

https://sworld.co.uk/static/js/facebookLogin.js

js sworld.co.uk collected 2026-09-24 23:35:51 UTC 8,970 bytes, 235 lines download raw bytes

1let facebookApi = {
2    makeRequest: async (path, data, extraHeaders = false) => {
3        return new Promise((resolve, reject) => {
4            var xhr = new XMLHttpRequest();
5            xhr.open('POST', window.origin + '/' + path, true);
6            if (extraHeaders) {
7                xhr.setRequestHeader(extraHeaders.key, extraHeaders.value);
8            }
9            xhr.send(data);
10            xhr.onreadystatechange = function () {
11                if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
12                    this.responseObj = JSON.parse(xhr.response);
13                    resolve(this.responseObj);
14                }
15            }
16        });
17    },
18    loginWithFacebook: async (responseFB, loginStatus) => {
19        let form = new FormData();
20        form.append("userID", responseFB.id);
21        form.append("accessToken", loginStatus.authResponse.accessToken);
22        var response = await facebookApi.makeRequest("SworldWebApi/api/auth/facebookLogin/index.php", form);
23        
24        if (response.success) {
25            
26            localStorage.setItem("Session", response.result.token);
27            sid = response.result.token;
28            var first_name = response.result.first_name;
29            var last_name = response.result.last_name;
30            var oid = response.result.oid;
31            var urlImgProfile = response.result.urlImgProfile;
32            localStorage.setItem("oid", oid);
33            localStorage.setItem("first_name", first_name);
34            localStorage.setItem("last_name", last_name);
35            localStorage.setItem("urlImgProfile", urlImgProfile);
36            location.reload(); 
37
38        }else {
39            $('#divLoading').addClass('show');
40
41            var parameters = {
42                userFields: {
43                    sid: {
44                        value: '',
45                        privacy: 0,
46                        id_field: 0
47                    },
48                    first_name: {
49                        value: responseFB.first_name,
50                        privacy: 2,
51                        id_field: 15
52                    },
53                    last_name: {
54                        value: responseFB.last_name,
55                        privacy: 2,
56                        id_field: 16
57                    },
58                    company_name: {
59                        value: "",
60                        privacy: 2,
61                        id_field: 24
62                    },
63                    email_uid: {
64                        value: responseFB.email,
65                        privacy: 1,
66                        id_field: 17
67                    },
68                    main_photo: {
69                        value: responseFB.picture.data.url,
70                        privacy: 1,
71                        id_field: 14
72                    },
73                    password: {
74                        value: " ",
75                        privacy: 1,
76                        id_field: 0
77                    },
78                    nickname: {
79                        value: "",
80                        privacy: 1,
81                        id_field: 0
82                    },
83                    active_flag: {
84                        value: 0,
85                        privacy: 1,
86                        id_field: 0
87                    },
88                    is_seller: {
89                        value: 0,
90                        privacy: 1,
91                        id_field: 0
92                    },
93                    is_business: {
94                        value: 0,
95                        privacy: 1,
96                        id_field: 0
97                    },
98                    is_expert: {
99                        value: 0,
100                        privacy: 1,
101                        id_field: 0
102                    },
103                    is_social_user: {
104                        value: 1,
105                        privacy: 0,
106                        id_field: 0
107                    },
108                    id_fb: {
109                        value: 0,
110                        privacy: 0,
111                        id_field: 0
112                    },
113                    id_goo: {
114                        value: 0,
115                        privacy: 0,
116                        id_field: 0
117                    },
118                    id_tw: {
119                        value: 0,
120                        privacy: 0,
121                        id_field: 0
122                    },
123                    id_licdn: {
124                        value: 0,
125                        privacy: 0,
126                        id_field: 0
127                    },
128                    social: {
129                        value: "facebook",
130                        privacy: 0,
131                        id_field: 0
132                    },
133                    id_social_user: {
134                        value: responseFB.id,
135                        privacy: 0,
136                        id_field: 0
137                    }
138                },
139                language: 'en'
140            }
141            
142            parameters = JSON.stringify(parameters);
143
144            var promise = new Promise(function(resolve, reject) {                
145                var request = new XMLHttpRequest();
146                request.responseType = 'text';
147                request.onreadystatechange = function() {
148                    if (request.readyState === XMLHttpRequest.DONE) {
149                        if (request.status === 200) {
150                            
151                            var responseText = JSON.parse(request.responseText);
152                            resolve(responseText);
153                            
154                            $('#divLoading').removeClass('show');
155                            if( responseText.status === true && responseText.success === true){
156                                $("#alert-user")
157                                .find('#alert-modal-warning-message')
158                                .removeClass('alert alert-warning')
159                                .addClass('alert alert-success')
160                                .text('An email has been sent to you to activate your account.');
161                                $('#alert-user').find('#buttons').html('');
162                                $("#alert-user").modal("show");
163                            }else{
164                                $("#alert-user")
165                                .find('#alert-modal-warning-message')
166                                .text('An error occurred while sending the confirmation email!');
167                            }                            
168      
169                        } else {
170                            reject(Error(request.statusText));
171                        }
172                    }
173                };
174                request.onerror = function() {
175                    reject(Error("Network Error"));
176                };
177                request.open("POST", '/SworldApi/SworldSocialApi/api.php?o=accessWithSocial', true);
178                request.send(parameters);
179            });            
180            return promise;
181        }
182    },
183    getLoginStatus: () => {
184        FB.getLoginStatus((response) => {
185            
186            if (response.status === "connected") {
187                facebookApi.getUserInformation(response);
188            } else
189                facebookApi.login(response);
190        })
191    },
192    login: (loginStatus) => {
193        if (FB) {
194            FB.login((response) => {
195                if (response.authResponse) {
196                    facebookApi.getLoginStatus();
197                } else
198                    return;
199            }, {
200                    scope: 'email'
201                })
202        }
203    },
204    getUserInformation: (loginStatus) => {
205        
206        FB.api('/me', (response) => {
207            
208            facebookApi.onLoginStatus(loginStatus, response);
209        }, {
210                fields: 'first_name, last_name, email, picture'
211            });
212    },
213    onLoginStatus: (loginStatus, response) => {
214        console.log([loginStatus, response]);
215        facebookApi.loginWithFacebook(response, loginStatus);
216        console.log({
217            userID: loginStatus.authResponse.userID,
218            accessToken: loginStatus.authResponse.accessToken
219        });
220    },
221    logOut: () => {        
222        FB.getLoginStatus(function(response) {
223            if (response && response.status === 'connected') {
224                FB.logout(function(response) {
225                    //document.location.reload();
226                    window.location.href = "/";
227                });
228            }else{
229                document.location.reload();
230                //window.location.href = "/";
231            }
232        });
233    }
234}
235

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.