예제 #1
0
 def on_get(self, req, resp):
     validate_params(req.params, 'user_id')
     response = self.client.LinkToken.create({
         'user': {
             'client_user_id': 'test_user',
         },
         'products': ["transactions"],
         'client_name': "My App",
         'country_codes': ['US'],
         'language': 'en',
     })
     resp.body = response['link_token']
예제 #2
0
    def on_post(self, req, resp):
        if not validate_params(req.params, 'idtoken'):
            raise falcon.HTTPBadRequest(
                "oauth post requires 'idtoken' parameter")

        token = req.params['idtoken'].replace("'", "").replace('"', '')
        # example from https://developers.google.com/identity/sign-in/web/backend-auth
        try:
            session = requests.session()
            cached_session = cachecontrol.CacheControl(session)
            request = google.auth.transport.requests.Request(
                session=cached_session)
            id_info = id_token.verify_oauth2_token(token, request, CLIENT_ID)

            if id_info['iss'] not in [
                    'accounts.google.com', 'https://accounts.google.com'
            ]:
                raise ValueError('Wrong issuer.')

            user_id = id_info['sub']
            user_nickname = id_info['name']
            user_photo = str(id_info['picture']).replace('=s96-c', '')
            session_token = self.db.sign_in_or_create_oauth_user(
                user_id, user_nickname, user_photo)
            resp.status = falcon.HTTP_OK
            resp.body = session_token

        except ValueError:
            raise falcon.HTTPUnauthorized('Token not accepted')
            pass
예제 #3
0
    def on_delete(self, req, resp):
        if not validate_params(req.params, 'session', 'group_id'):
            raise falcon.HTTPBadRequest("groups post requires 'session' and 'group_id' parameters")

        session = req.params['session'].replace("'", "").replace('"', '')
        group_id = req.params['group_id'].replace("'", "").replace('"', '')
        self.db.delete_group(session, group_id)
예제 #4
0
    def on_post(self, req, resp):
        if not validate_params(req.params, 'session', 'group_name'):
            raise falcon.HTTPBadRequest("groups post requires 'session' and 'group_name' parameters")

        session = req.params['session'].replace("'", "").replace('"', '')
        name = req.params['group_name'].replace("'", "").replace('"', '')
        resp.body = self.db.create_new_group(session, name)
예제 #5
0
    def on_get(self, req, resp):
        if not validate_params(req.params, 'session', 'group_id'):
            raise falcon.HTTPBadRequest("groups get requires 'session' and 'group_id' parameters")

        session = req.params['session'].replace("'", "").replace('"', '')
        group_id = req.params['group_id'].replace("'", "").replace('"', '')
        resp.body = json.dumps(self.db.get_group_info(session, group_id), ensure_ascii=True)
예제 #6
0
    def on_get(self, req, resp):
        if not validate_params(req.params, 'session', 'trans_id'):
            raise falcon.HTTPBadRequest(
                "transactions post requires 'session', and 'trans_id' parameters"
            )

        session = req.params['session'].replace("'", "").replace('"', '')
        trans_id = req.params['trans_id'].replace("'", "").replace('"', '')
        resp.body = json.dumps(self.db.get_transaction_info(session, trans_id),
                               ensure_ascii=True)
예제 #7
0
    def on_post(self, req, resp):
        if not validate_params(req.params, 'session', 'group_id', 'amount',
                               'paid', 'description'):
            raise falcon.HTTPBadRequest(
                "transactions post requires 'session', 'group_id', 'amount', 'paid', and 'description' parameters"
            )

        session = req.params['session'].replace("'", "").replace('"', '')
        group_id = req.params['group_id'].replace("'", "").replace('"', '')
        amount = float(req.params['amount'].replace("'", "").replace('"', ''))
        paid = req.params['paid'].replace("'", "").replace('"', '')
        desc = req.params['description'].replace("'", "").replace('"', '')

        if amount > 0:
            self.db.create_transaction(session, group_id, amount, paid, desc)
예제 #8
0
    def on_get(self, req, resp):
        if not validate_params(req.params, 'session'):
            raise falcon.HTTPBadRequest("users get requires 'session' parameter")

        session = req.params['session'].replace("'", "").replace('"', '')
        resp.body = json.dumps(self.db.get_user_info(session), ensure_ascii=True)