Roman Dayneko 11 лет назад
Родитель
Сommit
146e0e73a1
5 измененных файлов с 43 добавлено и 3 удалено
  1. 0 1
      .gitignore
  2. 29 0
      apps/face/priv/static/google_sdk.js
  3. 1 0
      apps/face/priv/templates/index.html
  4. 11 1
      apps/face/src/index.erl
  5. 2 1
      rebar.config

+ 0 - 1
.gitignore

@@ -8,4 +8,3 @@ erl_crash.dump
 deps
 apps/**/ebin/**
 rels/web/devbox
-*.js

+ 29 - 0
apps/face/priv/static/google_sdk.js

@@ -0,0 +1,29 @@
+function plusoneCallback(auth){
+  if(!auth['g-oauth-window']) {
+    console.log('skip autologin');
+  } else if(auth['access_token']){
+    gapi.client.load('oauth2', 'v2', function(){
+      gapi.client.oauth2.userinfo.get().execute(function(oauthResp){
+        gapi.client.load('plus', 'v1', function(){
+          gapi.client.plus.people.get({'userId':'me'}).execute(function(profileResp){
+            if(plusLogin)plusLogin($.extend({}, gapi.auth.getToken(), oauthResp, profileResp, {'g-oauth-window': 'defined'})); }); }); }); });
+  }else if(auth['error']){
+        console.log('error');
+  }
+}
+
+function render(){
+  gapi.signin.render('{{loginbtnid}}', {
+    'callback':'plusoneCallback',
+    'clientid':'{{clientid}}',
+    'cookiepolicy': '{{cookiepolicy}}',
+    'requestvisibleactions':'http://schemas.google.com/AddActivity',
+    'scope':'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email '
+  });
+}
+
+(function() {
+  var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
+  po.src = 'https://apis.google.com/js/client:plusone.js?parsetags=explicit&onload=render';
+  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
+})();

+ 1 - 0
apps/face/priv/templates/index.html

@@ -15,6 +15,7 @@
 <script src='/static/nitrogen/bullet.js' type='text/javascript' charset='utf-8'></script>
 <script src='/static/nitrogen/n2o.js' type='text/javascript' charset='utf-8'></script>
 <script src='/static/nitrogen/bert.js' type='text/javascript' charset='utf-8'></script>
+<script src='/static/google_sdk.js' type='text/javascript' charset='utf-8'></script>
 </script><div id="n2ostatus"></div>
 </body>
 </html>

+ 11 - 1
apps/face/src/index.erl

@@ -4,6 +4,7 @@
 -include_lib("n2o/include/wf.hrl").
 -include("../../server/include/requests.hrl").
 -include("../../server/include/settings.hrl").
+-include_lib("avz/include/avz.hrl").
 -jsmacro([take/2,attach/1,join/1,discard/3,player_info/2,reveal/4]).
 
 join(Game) ->
@@ -56,7 +57,10 @@ main() -> #dtl{file="index", bindings=[{title,<<"N2O">>},{body,body()}]}.
 
 body() ->
     [ #panel{ id=history },
-
+%%      #button{ id = plusloginbtn, body = <<"Login">>},
+      avz:buttons([google]),
+      avz:sdk([google]),
+      #br{},
       #label{ id = player1, body = "Player 1", style = "color=black;"},
       #label{ id = player2, body = "Player 2", style = "color=black;"},
       #label{ id = player3, body = "Player 3", style = "color=black;"},
@@ -226,4 +230,10 @@ event(reveal) ->
             wf:info("error discarded ~p", Discarded)
     end;
 
+
+
+%%event(X) -> avz:event(X).
+
 event(Event)  -> wf:info("Event: ~p", [Event]).
+
+api_event(X,Y,Z) -> avz:api_event(X,Y,Z).

+ 2 - 1
rebar.config

@@ -6,6 +6,7 @@
     {rest,           ".*", {git, "git://github.com/synrc/rest",                "HEAD"}},
     {gproc,          ".*", {git, "git://github.com/uwiger/gproc.git", "HEAD"}},
     {sync,          ".*", {git, "git://github.com/doxtop/sync", "HEAD"}},
-    {n2o_scripts,    ".*", {git, "git://github.com/synrc/n2o_scripts", "HEAD"}}
+    {n2o_scripts,    ".*", {git, "git://github.com/synrc/n2o_scripts", "HEAD"}},
+    {avz,	     ".*", {git, "git://github.com/synrc/avz.git", "HEAD"}}
 ]}.