Esempio n. 1
0
    def get(self):
        user = users.get_current_user()
        template = JINJA_ENV.get_template('index.html')
        template_values = {
            'username': user.email(),
            'logout_link': users.create_logout_url('/'),
        }

        msg = self.request.get('msg')

        if msg in alert_messages:
            alert_values = {
                'alert_display': 'block',
                'alert_type': alert_messages[msg][1],
                'alert_msg': alert_messages[msg][0],
            }
            template_values = dict(template_values.items() +
                                   alert_values.items())

        else:
            # Show warning if not authenticated with dropbox yet
            otaku = Otaku.query(Otaku.userid == user.user_id()).get()
            if not (otaku and otaku.access_token):
                msg = 'please_setup'
                alert_values = {
                    'alert_display': 'block',
                    'alert_type': alert_messages[msg][1],
                    'alert_msg': alert_messages[msg][0],
                }
                template_values = dict(template_values.items() +
                                       alert_values.items())

        self.response.write(template.render(template_values))
Esempio n. 2
0
    def get(self):
        # User is guaranteed to have logged in via Google thanks to app.yaml
        # rules
        user = users.get_current_user()

        # Try to get existing user. If not found, this is a brand new user
        query = Otaku.query(Otaku.userid == user.user_id())
        otaku = query.get()
        if otaku is None:
            otaku = Otaku()
            otaku.userid = user.user_id()
            otaku.put()

        # This token will be used for subsequent REST API requests - some sort
        # of sessionID, I guess...
        apiToken = pyhash(otaku.userid, str(datetime.datetime.now()))

        template_values = {
            'apiToken': apiToken,
            'username': user.nickname(),
            'userId': user.user_id(),
            'dropboxed': str(otaku.dropbox_access_token is not None).lower(),
        }
        path = os.path.join(os.path.dirname(__file__) +
                            '/../templates/', 'index.html')
        self.response.out.write(template.render(path, template_values))

        # Update current token to check in REST API backend
        otaku.api_token = apiToken
        otaku.put()
Esempio n. 3
0
    def wrapped(handler):
        token = handler.request.headers.get('Pytoken')
        if token is None:
            return  # no token? GTFO!
        userid = handler.request.headers.get('Userid')

        # Check token against datastore
        otaku = Otaku.query(Otaku.userid == userid,
                            Otaku.api_token == token).get()
        if otaku is not None:
            handler.dbx_token = otaku.dropbox_access_token
            func(handler)