-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.py
107 lines (92 loc) · 3.19 KB
/
auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import datetime
import urllib,json
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import users
from google.appengine.api import mail
from google.appengine.api import taskqueue
from database import Icon
import tool;
class MainPage(webapp.RequestHandler):
def get(self):
self.error(404);
class Login(webapp.RequestHandler):
def get(self):
ENV=tool.readHeader(self.request);
user=ENV.CurrentUser;
if user:
#check and create icon user automaticly
self.checkAndCreateIconAutomatic();
self.response.out.write("Login Success")
else:
if self.request.get('check'):
self.response.out.write("Not yet Login")
else:
url = users.create_login_url(self.request.uri)
self.redirect(url);
def checkAndCreateIconAutomatic(self):
ENV=tool.readHeader(self.request);
user=ENV.CurrentUser;
keyName='ucon://user/'+user.email();
userIcon=db.get(db.Key.from_path('Icon',keyName ));
if not userIcon:
userIcon=Icon(key_name=keyName);
userIcon.thumb="http://wwwcdn.net/ev/assets/images/vectors/afbig/user-symbol-blue-clip-art.jpg";
userIcon.type='user';
#generate content;
contentDict={
'photoURL' :userIcon.thumb ,
'facetimeID' : user.email(),
'email' : user.email(),
'home' : keyName+'/public/home',
'inbox' : keyName+'/private/inbox',
'item' : keyName+'/private/item',
};
userIcon.whereCreated=ENV.CityLatLong;
userIcon.whereModified=ENV.CityLatLong;
itemBarPlaceName=keyName+'/private/item';
## need: add task (makecopy of toolset icon to user item bar)
#camera app, upload-photo app
contentDict['toolset']=["ucon://toolset/camera","ucon://toolset/upload-photo"];
taskqueue.add(url='/icon/'
,params={'keyName':'ucon://place/'+contentDict.get('home'), 'thumb':"http://theparentplace.files.wordpress.com/2012/04/home1.png", 'type': 'place', 'tag':'home' ,
'content': json.dumps({
"placeName": contentDict.get('home'),
"title": user.email() + " - Home",
"backgroundPhotoURL": "",
"photoURL": userIcon.thumb
})
}
,queue_name='fastAndSecure');
# taskqueue.add(url='/action/'
# ,params={'place':itemBarPlaceName, 'type': 'makecopy', 'tag':'toolset' , 'content': json.dumps({"iconID":"ucon://toolset/camera","isKeyName":True}) }
# ,queue_name='fastAndSecure');
# #upload photo app
# taskqueue.add(url='/action/'
# ,params={'place':itemBarPlaceName, 'type': 'makecopy', 'tag':'toolset' , 'content': json.dumps({"iconID":"ucon://toolset/upload-photo","isKeyName":True}) }
# ,queue_name='fastAndSecure');
userIcon.content = json.dumps(contentDict);
userIcon.put();
class Logout(webapp.RequestHandler):
def get(self):
ENV=tool.readHeader(self.request);
user=ENV.CurrentUser;
if not user:
self.response.out.write("Logout Success")
else:
url = users.create_logout_url(self.request.uri)
self.redirect(url);
#def main():
app = webapp.WSGIApplication([
('/auth/[^/]*', MainPage),
('/auth/login/[^/]*', Login),
('/auth/logout/[^/]*', Logout),
], debug=True)
# util.run_wsgi_app(application)
#
#
#if __name__ == '__main__':
# main()