Advertisement
AndrewHaxalot

fb_login.js

Jan 17th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function refresh_page() {
  2.     window.location.reload()
  3. }
  4. function facebook_login() {
  5.     FB.getLoginStatus(function(response) {
  6.         if (response.status === 'connected') {
  7.             var uid = response.authResponse.userID;
  8.             var sex = '';
  9.             var pseudo = '';
  10.             var birthday_date = '';
  11.             var city = '';
  12.             var website = '';
  13.             var mail = '';
  14.             var query = FB.Data.query('SELECT uid,first_name,last_name,birthday,birthday_date,sex,current_location,username,is_blocked,email,website FROM user WHERE uid=' + uid);
  15.             query.wait(function(result) {
  16.                 var user = result[0];
  17.                 if (user.is_blocked == false) {
  18.                     if (user.uid != null) {
  19.                         uid = String(user.uid)
  20.                     }
  21.                     if (user.sex != null) {
  22.                         sex = String(user.sex)
  23.                     }
  24.                     if (user.username != null) {
  25.                         pseudo = String(user.username)
  26.                     } else {
  27.                         pseudo = String(user.first_name.toLowerCase().substr(0, 1) + user.last_name.toLowerCase())
  28.                     }
  29.                     if (user.birthday_date != null) {
  30.                         birthday_date = String(user.birthday_date)
  31.                     }
  32.                     if (user.current_location != null) {
  33.                         city = String(user.current_location.city)
  34.                     }
  35.                     if (user.website != null) {
  36.                         website = String(user.website)
  37.                     }
  38.                     if (user.email != null && (user.email).match('@proxymail.facebook.com') == null) {
  39.                         mail = String(user.email)
  40.                     }
  41.                     document.location = 'facebook_connect.forum?uid=' + uid + '&sex=' + sex + '&pseudo=' + pseudo + '&birthday_date=' + birthday_date + '&city=' + city + '&website=' + website + '&mail=' + mail
  42.                 } else {
  43.                     FB.logout()
  44.                 }
  45.             })
  46.         }
  47.     })
  48. }
  49. function facebook_link() {
  50.     FB.getLoginStatus(function(response) {
  51.         if (response.status === 'connected') {
  52.             $.ajax({type: "post",url: "ajax_upd_uid.forum",data: "uid=" + response.authResponse.userID,success: function(msg) {
  53.                     refresh_page()
  54.                 }})
  55.         }
  56.     })
  57. }
  58. function facebook_fill_data(fb_data) {
  59.     if (fb_data['gender'] != '') {
  60.         if (fb_data['gender'] == 'male' || fb_data['gender'] == 'homme') {
  61.             $('input[name=profile_field_16_-7][value="1"]').attr('checked', true)
  62.         }
  63.         if (fb_data['gender'] == 'female' || fb_data['gender'] == 'femme') {
  64.             $('input[name=profile_field_16_-7][value="2"]').attr('checked', true)
  65.         }
  66.     }
  67.     $('#profile_field_4_-12_2 option[value="' + Number(fb_data['b_day']) + '"]').attr("selected", "selected");
  68.     $('#profile_field_4_-12_1 option[value="' + Number(fb_data['b_month']) + '"]').attr("selected", "selected");
  69.     $('#profile_field_4_-12_0').val(fb_data['b_year']);
  70.     if (fb_data['city'] != '') {
  71.         $('#profile_field_13_-11').val(fb_data['city'])
  72.     }
  73.     if (fb_data['website'] != '') {
  74.         $('#profile_field_3_-10').val(fb_data['website'])
  75.     }
  76. }
  77. function facebook_register_login() {
  78.     FB.getLoginStatus(function(response) {
  79.         if (response.status === 'connected') {
  80.             var query = FB.Data.query('SELECT uid,first_name,last_name,birthday_date,sex,current_location,username,is_blocked,email,website FROM user WHERE uid=' + response.authResponse.userID);
  81.             query.wait(function(result) {
  82.                 var user = result[0];
  83.                 if (user.is_blocked == false) {
  84.                     if (user.uid != null) {
  85.                         $('#fb_uid').val(user.uid)
  86.                     }
  87.                     if (user.sex == 'male' || user.sex == 'homme') {
  88.                         $('input[name=profile_field_16_-7][value="1"]').attr('checked', true)
  89.                     }
  90.                     if (user.sex == 'female' || user.sex == 'femme') {
  91.                         $('input[name=profile_field_16_-7][value="2"]').attr('checked', true)
  92.                     }
  93.                     var pseudo = (user.username != null) ? user.username : user.first_name.toLowerCase().substr(0, 1) + user.last_name.toLowerCase();
  94.                     $('#username_reg').val(pseudo);
  95.                     if (user.birthday_date != null) {
  96.                         var birthday = (user.birthday_date).split('/');
  97.                         $('#profile_field_4_-12_2 option[value="' + Number(birthday[1]) + '"]').attr("selected", "selected");
  98.                         $('#profile_field_4_-12_1 option[value="' + Number(birthday[0]) + '"]').attr("selected", "selected");
  99.                         $('#profile_field_4_-12_0').val(birthday[2])
  100.                     }
  101.                     if (user.current_location != null) {
  102.                         $('#profile_field_13_-11').val(user.current_location.city)
  103.                     }
  104.                     if (user.website != null) {
  105.                         $('#profile_field_3_-10').val(user.website)
  106.                     }
  107.                     if ((user.email).match('@proxymail.facebook.com') == null) {
  108.                         $('#email').val(user.email)
  109.                     }
  110.                 } else {
  111.                     FB.logout()
  112.                 }
  113.             })
  114.         }
  115.     })
  116. }
  117. $(document).ready(function() {
  118.     $('a#logout').click(function() {
  119.         FB.logout(function(response) {
  120.         })
  121.     })
  122. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement