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 put(self):
        ticket_type = self.get_argument("type", "normal")
        showtime_id = self.get_argument("showtime_id", None)
        user_id = self.get_secure_cookie("user_id", None)

        if user_id is None:
            return self.error(403, "Must include the user cookie")

        # Now grab the reservation
        reservation = yield get_reservation_for_user(user_id)
        if reservation is None:
            return self.error(403, "There is no reservation for this account.")

        confirmation_code = str(uuid.uuid1())
        if ticket_type == "shitty":
            # Confirm a shitty ticket_type
            if reservation['showtime_id'] == showtime_id:
                yield confirm_ticket_reservation(
                    reservation['id'], confirmation_code, True)
            else:
                yield self.change_showtime(showtime_id, reservation,
                                           confirmation_code)
        else:
            # TODO: check the access_tokens, make sure we have enough.
            yield confirm_ticket_reservation(
                reservation['id'], confirmation_code, False)
        user = yield get_user(user_id)
        yield send_confirmation(user['email'], user['name'], confirmation_code)
        self.clear_cookie('user_id')
        self.api_response({'confirmation_code': confirmation_code})
    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 put(self):
        ticket_type = self.get_argument("type", "normal")
        showtime_id = self.get_argument("showtime_id", None)
        user_id = self.get_secure_cookie("user_id", None)

        if user_id is None:
            return self.error(403, "Must include the user cookie")

        # Now grab the reservation
        reservation = yield get_reservation_for_user(user_id)
        if reservation is None:
            return self.error(403, "There is no reservation for this account.")

        confirmation_code = str(uuid.uuid1())
        if ticket_type == "shitty":
            # Confirm a shitty ticket_type
            if reservation['showtime_id'] == showtime_id:
                yield confirm_ticket_reservation(reservation['id'],
                                                 confirmation_code, True)
            else:
                yield self.change_showtime(showtime_id, reservation,
                                           confirmation_code)
        else:
            # TODO: check the access_tokens, make sure we have enough.
            yield confirm_ticket_reservation(reservation['id'],
                                             confirmation_code, False)
        user = yield get_user(user_id)
        yield send_confirmation(user['email'], user['name'], confirmation_code)
        self.clear_cookie('user_id')
        self.api_response({'confirmation_code': confirmation_code})
 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 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)