<commit_before>"""
google login handler
"""
__author__ = 'davidl'
import tornado
from tornado.options import options
from tornado.auth import GoogleOAuth2Mixin
from tornado.web import RequestHandler
from bson.json_util import dumps, loads
import logging


class GoogleOAuth2LoginHandler(RequestHandler,
                               GoogleOAuth2Mixin):
    @tornado.gen.coroutine
    def get(self):
        logging.info(options.site_domain)
        logging.info('GoogleOAuth2LoginHandler - get')
        #self.write(dumps({'msg':'GoogleOAuth2LoginHandler.get'}))
        #return
        google_oauth2_redirect_uri = '{}api/auth/google'.format(options.site_domain)
        if self.get_argument('code', False):
            logging.info('probably call by google')
            user = yield self.get_authenticated_user(
                google_oauth2_redirect_uri,
                code=self.get_argument('code'))
            # Save the user with e.g. set_secure_cookie
            logging.info(str(user))
            self.write(dumps(user))
            """
            TODO:
            if user is a new user - save it to the database
            else - save last login
            set_secure_cookie
            see if something like
            self.get_argument('email'), is working
            """

        else:
            logging.info('GoogleOAuth2LoginHandler - redirect')
            yield self.authorize_redirect(
                google_oauth2_redirect_uri,
                client_id=self.settings['google_oauth']['key'],
                scope=['profile', 'email'],
                response_type='code',
                extra_params={'approval_prompt': 'auto'})<commit_msg>logging to solve google<commit_after>"""
google login handler
"""
__author__ = 'davidl'
import tornado
from tornado.options import options
from tornado.auth import GoogleOAuth2Mixin
from tornado.web import RequestHandler
from bson.json_util import dumps, loads
import logging


class GoogleOAuth2LoginHandler(RequestHandler,
                               GoogleOAuth2Mixin):
    @tornado.gen.coroutine
    def get(self):
        logging.info(options.site_domain)
        logging.info('GoogleOAuth2LoginHandler - get')
        #self.write(dumps({'msg':'GoogleOAuth2LoginHandler.get'}))
        #return
        google_oauth2_redirect_uri = '{}api/auth/google'.format(options.site_domain)
        if self.get_argument('code', False):
            logging.info( self.get_argument('email', False))
            logging.info('probably call by google')
            user = yield self.get_authenticated_user(
                google_oauth2_redirect_uri,
                code=self.get_argument('code'))
            # Save the user with e.g. set_secure_cookie
            #logging.info(str(user))
            #self.write(dumps(user))
            """
            TODO:
            if user is a new user - save it to the database
            else - save last login
            set_secure_cookie
            see if something like
            self.get_argument('email'), is working
            """

        else:
            logging.info('GoogleOAuth2LoginHandler - redirect')
            yield self.authorize_redirect(
                google_oauth2_redirect_uri,
                client_id=self.settings['google_oauth']['key'],
                scope=['profile', 'email'],
                response_type='code',
                extra_params={'approval_prompt': 'auto'})
{'fraction_non_alphanumeric': 0.09483513276918587, 'fraction_numerical': 0.005252407353370295, 'mean_word_length': 2.1888372093023256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7169', 'n_tokens_mistral': 936, 'n_tokens_neox': 907, 'n_words': 197}