Commits

Anonymous committed b1b50b4

fixed channel api

  • Participants
  • Parent commits d26223b

Comments (0)

Files changed (7)

-application: ekkli-maps
+application: ekkli-coop
 version: 1
 runtime: python27
 api_version: 1

File common/middleware.py

+from google.appengine.api import channel
+
+
+class TokenMiddleWare(object):
+    def process_request(self, request):
+
+    #        patterns = ['_ah/','favicon.ico']
+    #        for p in patterns:
+    #            if p in request.path:
+    #                return None
+
+        if not request.is_ajax():
+            client_id = request.session.session_key
+            token = channel.create_channel(client_id)
+            request.token=token
+
+        return None

File common/services.py

 
 def connected(request):
 
-    client_id = request.POST['from']
-    obj = UserChannel.objects.get(client_id=client_id)
+    client_id = request.session.session_key
+
+    if request.user.is_authenticated():
+        obj, created = UserChannel.objects.get_or_create(user = request.user, defaults={'client_id' :client_id})
+    else:
+        obj, created = UserChannel.objects.get_or_create(client_id = client_id, defaults={})
+
+    obj.page_url = request.path
+    obj.client_id=client_id
     obj.connected = True
+
     obj.save()
 
-    logging.info('%s was connected' % request.POST['from'])
+    logging.info('client_id:%s %s' % (client_id,obj.user.username))
+
     check_online_users_event()
+
     return HttpResponse("i'm connected")
 
 def disconnected(request):

File googleappsauth/views.py

 Created by Axel Schlüter on 2009-12
 Copyright (c) 2009, 2010 HUDORA GmbH. All rights reserved.
 """
+import logging
 
 import types
 
 
         # jetzt bauen wir uns die URL fuer den Callback zusammen, unter
         # dem wir von Google aufgerufen werden moechten nach dem Login
-        callback_url = request.build_absolute_uri(reverse(callback))
+        #callback_url = request.build_absolute_uri(reverse(callback))
+        callback_url= 'http://%s%s' %( settings.CURRENT_SITE,reverse(callback))
         request.session['callback_url'] = callback_url
 
     # wenn wir mehr als eine Apps-Domain konfiguriert haben und noch 
     # inkl. Login-Domain enthalten hat) nicht zu brechen fangen wir hier moegliche 
     # Typfehler (eben wenn der Parameter kein passendes '%s' enthaelt) ab.
     openid_endpoint = _google_openid_endpoint
+    logging.info("endpoint1 %s" % openid_endpoint)
+    logging.info("domain %s" % login_domain)
     try:
         openid_endpoint = openid_endpoint % login_domain
     except TypeError:
 
     # und schliesslich konstruieren wir darauf die Google-OpenID-
     # Endpoint-URL, auf die wir dann den Benutzer umleiten
+    logging.info("endpoint2 %s" % openid_endpoint)
     url = googleappsauth.openid.build_login_url(
             openid_endpoint, _google_openid_realm,
             callback_url, _oauth_consumer_key, _google_api_scope)
+
     return HttpResponseRedirect(url)
 
 
 
 SECRET_KEY = '=r-$b*8hglm+858&dns,dna,dmnas,dand,mnsa,d-&6-3d3vfc4((7yd0dbrakhvi'
 
-CURRENT_SITE = 'ekkli-maps.appspot.com/'
+CURRENT_SITE = 'ekkli-maps.appspot.com'
 DEFAULT_FROM_EMAIL='voskoboynikvlad@googlemail.com'
 
 INSTALLED_APPS = (
 MIDDLEWARE_CLASSES = (
     # This loads the index definitions, so it has to come first
     'autoload.middleware.AutoloadMiddleware',
-
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'privatebeta.middleware.PrivateBetaMiddleware',
     'googleappsauth.middleware.GoogleAuthMiddleware',
+    'common.middleware.TokenMiddleWare',
     )
 
 PRIVATEBETA_ENABLE_BETA=False
     'django.contrib.auth.context_processors.auth',
     'django.core.context_processors.request',
     'django.core.context_processors.media',
-    'common.context_processors.token',
 )
 
 AUTHENTICATION_BACKENDS = (
 
 # marketplace configuration
 LOGIN_REDIRECT_URL = '/'
-GOOGLE_APPS_DOMAIN = 'example.com'
-GOOGLE_APPS_CONSUMER_KEY = 'example.com'
-GOOGLE_APPS_CONSUMER_SECRET = '*sekret*'
+GOOGLE_APPS_DOMAIN ='cloudlockplus.com'  #'ekkli-maps.appspot.com'
+GOOGLE_APPS_CONSUMER_KEY = '253718231002.apps.googleusercontent.com'
+GOOGLE_APPS_CONSUMER_SECRET = 'O6ULPOvumXvZtYkHJ-V8S5LR'
 # domain where your application is running
-GOOGLE_OPENID_REALM = 'http://ekkli-coop.appspot.com/'
-AUTH_PROTECTED_AREAS = ['/admin']
+GOOGLE_OPENID_REALM = 'http://ekkli-maps.appspot.com/'
+GOOGLE_OPENID_ENDPOINT = 'https://www.google.com/a/%s/o8/ud?be=o8' % GOOGLE_APPS_DOMAIN
+AUTH_PROTECTED_AREAS = ['/']

File templates/map.html

         var socket = channel.open();
         onOpened = function() {
             var connected = true;
+            var payload = {'type':'join'};
+            $.ajax({
+                type: "POST",
+                url:'{% url client_connected %}',
+                data: payload,
+                dataType:'json',
+                success:function(data){
+                    json = data;
+                    if(data.resultStatus == 'OK'){
+                    }
+                    else{
+                        $('#error_msg').html(data.localMessage);
+                    }
+
+                }
+            });
         };
         socket.onopen = onOpened;
 
 urlpatterns = patterns('',
     (r'^admin/', include(admin.site.urls)),
     (r'^api/', include('maps.api.urls')),
-    (r'^_ah/channel/connected/', 'common.services.connected'),
+#    (r'^_ah/channel/connected/', 'common.services.connected'),
+    url(r'^channel/connected/', 'common.services.connected',name='client_connected'),
     (r'^_ah/channel/disconnected/', 'common.services.disconnected'),
     #(r'^_ah/warmup$', 'djangoappengine.views.warmup'),
     (r'test$', 'django.views.generic.simple.direct_to_template',
     (r'^schedule_date_task/', 'common.views.schedule_date_task'),
     (r'', include('upload.urls')),
     (r'^invites/', include('privatebeta.urls')),
-    (r'^/_ah/login_required/', 'googleappsauth.views.callback'),
+    (r'^_ah/login_required/', 'googleappsauth.views.callback'),
 
 )