Просмотр исходного кода

Merge pull request #9 from fycth/master

Facebook cover image, adapting to KVS user record changes, upgrading FB API
Namdak Tonpa 10 лет назад
Родитель
Сommit
5c60949264
6 измененных файлов с 9 добавлено и 10 удалено
  1. 3 3
      priv/facebook_sdk.dtl
  2. 1 1
      rebar.config
  3. 2 3
      src/facebook.erl
  4. 1 1
      src/github.erl
  5. 1 1
      src/google.erl
  6. 1 1
      src/twitter.erl

+ 3 - 3
priv/facebook_sdk.dtl

@@ -7,7 +7,7 @@ window.fbAsyncInit = function() {
       var inIframe= top!=self;
   //    setFbIframe(inIframe);
       if(inIframe && response.status == 'connected' && fbLogin)
-        FB.api("/me?fields=id,username,first_name,last_name,email,birthday", function(response){ fbLogin(response);});
+        FB.api("/me?fields=id,first_name,last_name,email,birthday,cover", function(response){ fbLogin(response);});
   //  }
   });
 };
@@ -15,9 +15,9 @@ window.fbAsyncInit = function() {
 function fb_login(){
   FB.getLoginStatus(function(response){
     if(response.status == 'connected'){
-      if(fbLogin) FB.api("/me?fields=id,username,first_name,last_name,email,birthday", function(response){fbLogin(response);});
+      if(fbLogin) FB.api("/me?fields=id,first_name,last_name,email,birthday,cover", function(response){fbLogin(response);});
     } else FB.login(function(r){
-        if(r.authResponse && fbLogin) FB.api("/me?fields=id,username,first_name,last_name,email,birthday", function(response){fbLogin(response);});
+        if(r.authResponse && fbLogin) FB.api("/me?fields=id,first_name,last_name,email,birthday,cover", function(response){fbLogin(response);});
       }, {scope: 'email,user_birthday'});
   });
 }

+ 1 - 1
rebar.config

@@ -1,7 +1,7 @@
 {deps_dir, ["deps"]}.
 {deps, [
     {n2o,           ".*", {git, "git://github.com/5HT/n2o", {tag,"2.1"}}},
-    {kvs,           ".*", {git, "git://github.com/synrc/kvs", {tag,"2.1"}}},
+    {kvs,           ".*", {git, "git://github.com/synrc/kvs", {tag,"master"}}},
     {erlydtl,       ".*", {git, "git://github.com/evanmiller/erlydtl.git", {tag,"0.8.0"}}}
 ]}.
 {erlydtl_opts, [

+ 2 - 3
src/facebook.erl

@@ -15,17 +15,16 @@ api_event(fbLogin, Args, _Term)-> JSArgs = n2o_json:decode(Args), avz:login(face
 
 registration_data(Props, facebook, Ori)->
     Id = proplists:get_value(<<"id">>, Props),
-    UserName = binary_to_list(proplists:get_value(<<"username">>, Props)),
     BirthDay = case proplists:get_value(<<"birthday">>, Props) of
         undefined -> {1, 1, 1970};
         BD -> list_to_tuple([list_to_integer(X) || X <- string:tokens(binary_to_list(BD), "/")]) end,
     error_logger:info_msg("User Ori: ~p",[Ori]),
     error_logger:info_msg("Props: ~p",[Props]),
-    Id = proplists:get_value(<<"id">>, Props),
     Email = email_prop(Props, facebook),
+    [UserName|_] = string:tokens(binary_to_list(Email),"@"), Cover = case proplists:get_value(<<"cover">>,Props) of undefined -> ""; P -> case proplists:get_value(<<"source">>,P#struct.lst) of undefined -> ""; C -> binary_to_list(C) end end,
     Ori#user{   id = Email,
                 display_name = UserName,
-                avatar = "https://graph.facebook.com/" ++ UserName ++ "/picture",
+                images = [{fb_avatar,"https://graph.facebook.com/" ++ binary_to_list(Id) ++ "/picture"},{fb_cover,Cover}|Ori#user.images],
                 email = Email,
                 names = proplists:get_value(<<"first_name">>, Props),
                 surnames = proplists:get_value(<<"last_name">>, Props),

+ 1 - 1
src/github.erl

@@ -54,7 +54,7 @@ registration_data(Props, github, Ori) ->
     Ori#user{   id= Email,
                 username = binary_to_list(proplists:get_value(<<"login">>, Props)),
                 display_name = Name,
-                avatar = proplists:get_value(<<"avatar_url">>, Props),
+                images = [{gh_avatar,proplists:get_value(<<"avatar_url">>, Props)}|Ori#user.images],
                 email = Email,
                 names  = Name,
                 surnames = [],

+ 1 - 1
src/google.erl

@@ -19,7 +19,7 @@ registration_data(Props, google, Ori)->
     Email = proplists:get_value(<<"email">>,Props),
     Ori#user{   id = Email,
                 display_name = proplists:get_value(<<"displayName">>, Props),
-                avatar = Image,
+                images = [{google_avatar,Image}|Ori#user.images],
                 email = Email,
                 names = GivenName,
                 surnames = FamilyName,

+ 1 - 1
src/twitter.erl

@@ -16,7 +16,7 @@ registration_data(Props, twitter, Ori)->
     Ori#user{   id = Email,
                 username = re:replace(UserName, "\\.", "_", [{return, list}]),
                 display_name = proplists:get_value(<<"screen_name">>, Props),
-                avatar = proplists:get_value(<<"profile_image_url">>, Props),
+                images = [{tw_avatar,proplists:get_value(<<"profile_image_url">>, Props)}|Ori#user.images],
                 names = proplists:get_value(<<"name">>, Props),
                 email = Email,
                 surnames = [],