def get(self):
        send_res = []
        reservations = yield get_reservations()
        past_email = pickle.load(open('./data/emails.pkl', 'rb'))
        for reservation in reservations:
            show_id = reservation['showtime_id']
            show_meta = yield get_showtime(show_id)
            date_str = show_meta['date_str']
            user_id = reservation['user_id']
            user = yield get_user(user_id)
            name = user['name']
            email = user['email']
            if email in past_email:
                continue
            try:
                yield send_reminder(email, name, date_str)
                send_res.append(email)
            except Exception as e:
                print("Exception while sending out emails: {0}".format(e))
                os.makedirs("./data/", exist_ok=True)
            yield gen.sleep(10)
        send_res.extend(past_email)
        with open('./data/emails.pkl', 'wb+') as fd:
            pickle.dump(send_res, fd)

        return self.api_response({'reminder_status': "all sent!"})
    def get(self):
        send_res = []
        reservations = yield get_reservations()
        past_email = pickle.load(open(
            './data/emails.pkl', 'rb'))
        for reservation in reservations:
            show_id = reservation['showtime_id']
            show_meta = yield get_showtime(show_id)
            date_str = show_meta['date_str']
            user_id = reservation['user_id']
            user = yield get_user(user_id)
            name = user['name']
            email = user['email']
            if email in past_email:
                continue
            try:
                yield send_reminder(email, name, date_str)
                send_res.append(email)
            except Exception as e:
                print("Exception while sending out emails: {0}".format(e))
                os.makedirs("./data/", exist_ok=True)
            yield gen.sleep(10)
        send_res.extend(past_email)
        with open('./data/emails.pkl', 'wb+') as fd:
            pickle.dump(send_res, fd)

        return self.api_response({'reminder_status': "all sent!"})
 def get(self):
     showid = self.get_argument('showtime_id')
     shares = self.get_arguments('share')
     passphrase = self.get_argument('passphrase', None)
     if not (bool(shares) ^ bool(passphrase)):
         return self.error(
             400,
             'Either shares or passphrase needs to be provided'
         )
     if not passphrase:
         passphrase = cryptohelper.recover_passphrase(shares)
     privkey_show = yield get_show_privatekey(showid, passphrase)
     show_info = yield get_showtime(showid)
     result = {
         'showid': showid,
         'date': show_info['date'],
         'users': [],
     }
     users = yield get_user_keypair_from_showid(showid)
     for user in users:
         user_id = user['id']
         user_blob = yield get_user(user_id)
         user_privkey_pem = cryptohelper.decrypt_blob(
             privkey_show,
             user['enc_private_key']
         )
         meta = dict(showid=showid, **user_blob)
         cur_result = {
             'id': user_id,
             'meta': meta,
             'publickey': user['public_key'],
             'privatekey': user_privkey_pem,
         }
         result['users'].append(cur_result)
     return self.api_response(result)
    def change_showtime(self, showtime_id, reservation, confirmation_code):
        showtime = yield get_showtime(showtime_id)
        if showtime is None:
            return self.error(404, "Showtime not found!")

        if not (yield self.isShowTimeAvailable(showtime, True)):
            return self.error(400, "Ticket is not available any more.")

        yield change_reservation_showtime(reservation['id'], showtime_id)

        yield confirm_ticket_reservation(reservation['id'], confirmation_code,
                                         True)
    def change_showtime(self, showtime_id, reservation, confirmation_code):
        showtime = yield get_showtime(showtime_id)
        if showtime is None:
            return self.error(404, "Showtime not found!")

        if not (yield self.isShowTimeAvailable(showtime, True)):
            return self.error(400, "Ticket is not available any more.")

        yield change_reservation_showtime(
            reservation['id'], showtime_id)

        yield confirm_ticket_reservation(
            reservation['id'], confirmation_code, True)
 def get(self):
     showid = self.get_argument('showtime_id')
     shares = self.get_arguments('share')
     passphrase = self.get_argument('passphrase', None)
     if not (bool(shares) ^ bool(passphrase)):
         return self.error(
             400,
             'Either shares or passphrase needs to be provided'
         )
     if not passphrase:
         passphrase = cryptohelper.recover_passphrase(shares)
     privkey_show = yield get_show_privatekey(showid, passphrase)
     show_info = yield get_showtime(showid)
     result = {
         'showid': showid,
         'date': show_info['date'],
         'users': [],
     }
     users = yield get_user_keypair_from_showid(showid)
     for user in users:
         user_id = user['id']
         user_blob = yield get_user(user_id)
         user_privkey_pem = cryptohelper.decrypt_blob(
             privkey_show,
             user['enc_private_key']
         )
         meta = dict(showid=showid, **user_blob)
         cur_result = {
             'id': user_id,
             'meta': meta,
             'publickey': user['public_key'],
             'privatekey': user_privkey_pem,
             'services': {},
         }
         user_privkey = cryptohelper.import_key(user_privkey_pem)
         access_tokens = yield get_user_tokens(user_id)
         if access_tokens is not None:
             for key, value in access_tokens.items():
                 if not isinstance(value, bytes):
                     continue
                 cur_result['services'][key] = cryptohelper.decrypt_blob(
                     user_privkey,
                     value
                 )
         else:
             cur_result['services'] = {}
         result['users'].append(cur_result)
     return self.api_response(result)
    def post(self):
        showtime_id = self.get_argument('showtime_id', None)
        count = int(self.get_argument('count', 1))

        if showtime_id is None:
            return self.error(400, "Must provide 'showtime_id' to proceed.")

        # Verify that such a show exists.
        showtime = yield get_showtime(showtime_id)
        if showtime is None:
            return self.error(404, "Show time not found.")

        promotion_keys = yield [create_promotion_key(showtime_id)
                                for _ in range(count)]

        self.api_response({'promotion_keys': promotion_keys}, 201)
Beispiel #8
0
    def post(self):
        showtime_id = self.get_argument('showtime_id', None)
        count = int(self.get_argument('count', 1))

        if showtime_id is None:
            return self.error(400, "Must provide 'showtime_id' to proceed.")

        # Verify that such a show exists.
        showtime = yield get_showtime(showtime_id)
        if showtime is None:
            return self.error(404, "Show time not found.")

        promotion_keys = yield [
            create_promotion_key(showtime_id) for _ in range(count)
        ]

        self.api_response({'promotion_keys': promotion_keys}, 201)
    def post(self):
        name = self.get_argument("name", None)
        email = self.get_argument("email", None)
        showtime_id = self.get_argument("showtime_id", None)
        promo_code = self.get_argument('promotion_key', None)

        # Validate user and email entries
        if name is None or email is None:
            return self.error(
                403,
                "Must provide valid username and email address to continue"
            )

        # Validate the show time
        if showtime_id is None:
            return self.error(400, "Must provide 'showtime_id' to proceed.")

        showtime = yield get_showtime(showtime_id)
        if showtime is None:
            return self.error(404, "Could not find the selected showtime.")

        if not (yield self.canBookTicketForShowtime(showtime, promo_code)):
            return self.error(400, "This showtime is sold out.")

        # Grab or create a user
        user = yield get_user_from_email(email)
        if user is not None:
            user_id = user['id']
            self.set_secure_cookie("user_id", user_id)
            # check for any previous confirmed booking
            reservation = yield get_reservation_for_user(user_id)
            if reservation is not None and\
                    reservation['confirmation_code'] != "":
                return self.error(
                    403,
                    "Sorry, you already have a ticket for the show."
                )
        else:
            user_id = yield user_insert(name, email, showtime_id)
            self.set_secure_cookie("user_id", user_id)

        # Create a reservation: note that all previous unconfirmed reservations
        # will be lost
        yield create_ticket_reservation(showtime["id"], user_id)
    def post(self):
        name = self.get_argument("name", None)
        email = self.get_argument("email", None)
        showtime_id = self.get_argument("showtime_id", None)

        # Validate the show time
        if showtime_id is None:
            return self.error(403, "Must provide showtime_id to proceed.")

        showtime = yield get_showtime(showtime_id)
        if showtime is None:
            return self.error(404, "Could not find the selected showtime.")

        if not (yield self.isShowTimeAvailable(showtime)):
            return self.error(404, "The showtime is sold out.")

        # Validate user and email entries
        if name is None or email is None:
            return self.error(
                403,
                "Must provide valid username and email address to continue"
            )

        # Grab or create a user
        user = yield get_user_from_email(email)
        if user is not None:
            user_id = user['id']
            self.set_secure_cookie("user_id", user_id)
            # check for any previous confirmed booking
            reservation = yield get_reservation_for_user(user_id)
            if reservation is not None and reservation.confirmation_code != "":
                return self.error(
                    403,
                    "Sorry, you already have a ticket for the show."
                )
        else:
            user_id = yield user_insert(name, email, showtime_id)
            self.set_secure_cookie("user_id", user_id)

        # Create a reservation: note that all previous unconfirmed reservations
        # will be lost
        yield create_ticket_reservation(showtime["id"], user_id)