1-
21# -*- coding: utf-8 -*-
32#
43# Python-regex.com : Regular expression as in Kodos3 but for the web
1817# along with this program; if not, write to the Free Software
1918# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2019
21- import json
2220import binascii
21+ import json
2322import os
2423
25- from tornado .web import authenticated , HTTPError
2624from tornado .auth import GoogleOAuth2Mixin , TwitterMixin , FacebookGraphMixin
2725from tornado .gen import coroutine
26+ from tornado .web import authenticated , HTTPError
2827
29- from tornadoext .requesthandler import RequestHandler
30- from tornadoext .oauth import GithubMixin , LinkedInMixin
31-
32- from App .models .user import UserModel
3328from App .models .preference import Config
29+ from App .models .user import UserModel
30+ from tornadoext .oauth import GithubMixin , LinkedInMixin
31+ from tornadoext .requesthandler import RequestHandler
3432
3533
3634class LoginHandler (RequestHandler ):
@@ -59,6 +57,7 @@ class LogoutHandler(RequestHandler):
5957 """
6058 Disconnect the user and go to the main page
6159 """
60+
6261 @authenticated
6362 def get (self ):
6463 self .add_flash_message (0 , "You are now disconnected." )
@@ -70,6 +69,7 @@ class GoogleOAuth2Handler(RequestHandler, GoogleOAuth2Mixin):
7069 """
7170 Connect with Google account
7271 """
72+
7373 @coroutine
7474 def get (self , * args , ** kwargs ):
7575 redirect_uri = "%s://%s" % (self .request .protocol , "python-regex.com/auth/google/" )
@@ -84,7 +84,7 @@ def get(self, *args, **kwargs):
8484 redirect_uri = redirect_uri ,
8585 code = self .get_argument ('code' )
8686 )
87-
87+
8888 access_token = str (user ['access_token' ])
8989 http_client = self .get_auth_http_client ()
9090 response = yield http_client .fetch ('https://www.googleapis.com/oauth2/v1/userinfo?access_token={}'
@@ -118,6 +118,7 @@ class TwitterOAuth2Handler(RequestHandler, TwitterMixin):
118118 """
119119 Connect with Twitter account
120120 """
121+
121122 @coroutine
122123 def get (self , * args , ** kwargs ):
123124 if self .get_argument ("oauth_token" , None ):
@@ -157,10 +158,12 @@ def get(self):
157158 extra_params = {"scope" : "read_stream,offline_access" }
158159 )
159160
161+
160162class LinkedInOAuth2Handler (RequestHandler , LinkedInMixin ):
161163 """
162164 Connect with LinkedIn API
163165 """
166+
164167 @coroutine
165168 def get (self , * args , ** kwargs ):
166169 config = Config ()
@@ -203,11 +206,11 @@ def get(self, *args, **kwargs):
203206 print (user_data )
204207
205208
206-
207209class GithubOAuth2Handler (RequestHandler , GithubMixin ):
208210 """
209211 Connect with GitHub API
210212 """
213+
211214 @coroutine
212215 def get (self , * args , ** kwargs ):
213216 redirect_uri = '/auth/github/'
@@ -232,4 +235,4 @@ def get(self, *args, **kwargs):
232235 )
233236
234237 def _on_login (self , user ):
235- print (user )
238+ print (user )
0 commit comments