def get(self): if self.get_argument('email', None): # pull user from database user = yield get_user_from_email( self.get_argument('email', None)) if user is not None: token = str(uuid.uuid1()) yield create_deauth_request(id=token, user_id=user['id']) link = "{0}/auth/deauth?token={1}".format( self.application.settings['base_url'], token ) yield send_deauthorization(user['email'], user['name'], link) else: return self.error( 404, "User is either already deleted or not in DB" ) return self.redirect("{0}/leave2".format( self.application.settings['base_url']) ) elif (self.get_argument('token', None)): # pop the request request = yield pop_deauth_request( self.get_argument('token', None)) if request is not None: yield delete_user_data(user_id=request['user_id']) return self.redirect("{0}/fullcancel".format( self.application.settings['base_url']) ) else: return self.error(404, "Token not found.") else: return self.error(400, "Insufficient params.")
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)
def get(self): if self.get_argument('email', None): # pull user from database user = yield get_user_from_email( self.get_argument('email', None)) if user is not None: token = str(uuid.uuid1()) self._ioloop.add_callback(create_deauth_request, id=token, user_id=user['id']) link = "{0}/deauth?token={1}".format( self.application.settings['base_url'], token ) send_deauthorization(user['email'], user['name'], link) else: raise web.HTTPError( 404, 'User is either already deleted or not in DB') elif (self.get_argument('token', None)): # pop the request request = yield pop_deauth_request( self.get_argument('token', None)) if request is not None: self._ioloop.add_callback( delete_user_data, id=request['user_id'] ) return self.redirect("{0}/leave#final".format( self.application.settings['base_url']) ) else: raise web.HTTPError( 404, 'Not found.') else: # return error raise web.HTTPError( 400, 'Insufficient params.')