def get(self): """ Logged in users not allowed here. """ if self.get_current_user(): return self.redirect("/") if options.disable_signups: return self.write("Sorry! Signups Are Closed.") # voucher key key_value = self.get_argument('key', '') promotions = Promotion.active() # Amazon's ELB will set this header to inform us what scheme is in use # Fallback to checking Tornado's protocol if it is absent using_https = self.request.headers.get( "X-Forwarded-Proto", self.request.protocol) == "https" #recaptcha hot fix captcha_string = captcha.displayhtml(options.recaptcha_public_key, use_ssl=using_https) return self.render("account/create.html", name="", email="", key=key_value, promotions=promotions, recaptcha=captcha_string)
def get(self): """ Logged in users not allowed here. """ if self.get_current_user(): return self.redirect("/") if options.disable_signups: return self.write("Sorry! Signups Are Closed.") # voucher key key_value = self.get_argument('key', '') promotions = Promotion.active() # If we're using mltshp-cdn.com, we know that we can use # https; if something else is configured, check the # X-Forwarded-Proto header and fallback to the protocol # of the request using_https = options.cdn_ssl_host == "mltshp-cdn.com" or \ self.request.headers.get("X-Forwarded-Proto", self.request.protocol) == "https" #recaptcha hot fix if options.recaptcha_public_key: captcha_string = captcha.displayhtml(options.recaptcha_public_key, use_ssl=using_https) else: captcha_string = "" return self.render("account/create.html", name="", email="", key=key_value, promotions=promotions, recaptcha=captcha_string)
def get(self): current_user = self.get_current_user_object() if current_user.is_paid: return self.redirect("/account/settings") promotions = Promotion.active() return self.render('account/subscribe.html', promotions=promotions)
def get(self): user = self.get_current_user_object() payments = [] if user.is_paid: payments = PaymentLog.last_payments(count=3, user_id=user.id) already_requested = self.get_secure_cookie("image_request") promotions = Promotion.active() return self.render("account/settings.html", user=user, payments=payments, already_requested=already_requested, promotions=promotions)
def post(self): key_value = self.get_argument('key', '') voucher = is_valid_voucher_key(key_value) user = self.get_current_user_object() if voucher is not None: if not voucher.claimed_by_user_id: voucher.apply_to_user(user) return self.redirect("/account/settings") promotions = Promotion.active() self.add_error('key', 'Invalid discount code') return self.render("account/redeem.html", key=key_value, promotions=promotions)
def post(self): user = self.get_current_user_object() email = self.get_argument('email', None) disable_notifications = self.get_argument('disable_notifications', 0) show_naked_people = self.get_argument('show_naked_people', 0) show_stats = self.get_argument('show_stats', 0) disable_autoplay = self.get_argument('disable_autoplay', 0) if email != user.email and email != None: user.update_email(email) user.invalidate_email() if disable_notifications: user.disable_notifications = 1 else: user.disable_notifications = 0 if show_naked_people: user.show_naked_people = 1 else: user.show_naked_people = 0 if show_stats: user.show_stats = 1 else: user.show_stats = 0 if disable_autoplay: user.disable_autoplay = 1 else: user.disable_autoplay = 0 if user.save(): return self.redirect("/account/settings") promotions = Promotion.active() self.add_errors(user.errors) return self.render("account/settings.html", user=user, errors=self._errors, promotions=promotions)
def get(self): """ Logged out users not allowed here. """ # voucher key key_value = self.get_argument('key', '') user = self.get_current_user_object() if user is None: if key_value != '': query = "?" + urlencode({"key": key_value}) return self.redirect("/create-account%s" % query) if user.is_paid: # pro users can't redeem return self.redirect("/account/settings") promotions = Promotion.active() return self.render("account/redeem.html", key=key_value, promotions=promotions)
def get(self): user = self.get_current_user_object() payments = [] if user.is_paid: payments = PaymentLog.last_payments(count=3, user_id=user.id) already_requested = self.get_secure_cookie("image_request") cancel_flag = "canceled" in (user.stripe_plan_id or "") migrated_flag = self.get_argument('migrated', 0) promotions = Promotion.active() has_data_to_migrate = not MigrationState.has_migrated(user.id) return self.render("account/settings.html", user=user, payments=payments, already_requested=already_requested, promotions=promotions, plan_name=plan_name(user.stripe_plan_id), has_data_to_migrate=has_data_to_migrate, migrated_flag=migrated_flag, cancel_flag=cancel_flag)
def post(self): if options.disable_signups: return name_value = self.get_argument('name', '') email_value = self.get_argument('email', '') key_value = self.get_argument('key', '') has_errors = False voucher = None if key_value != '': voucher = is_valid_voucher_key(key_value) if voucher is None: has_errors = True self.add_error('key', 'Invalid discount code') new_user = User(name=name_value, email=email_value, email_confirmed=0) new_user.set_and_confirm_password( self.get_argument('password', ""), self.get_argument('password_again', "")) skip_recaptcha = self.get_argument('_skip_recaptcha_test_only', False) if not options.recaptcha_private_key: skip_recaptcha = True #recaptcha hotfix if not skip_recaptcha: response = captcha.submit( self.get_argument('recaptcha_challenge_field'), self.get_argument('recaptcha_response_field'), options.recaptcha_private_key, self.request.remote_ip) if not response.is_valid: has_errors = True self.add_error('recaptcha', 'Invalid captcha') if not has_errors: try: # create form asserts the user agress to terms of use new_user.tou_agreed = 1 if new_user.save(): if options.postmark_api_key: # i'd like to NOT invalidate_email in the # case of using a voucher, but the person # may use a different email for MLTSHP than # they used for receiving their voucher, so... new_user.invalidate_email() else: # we have no way to send a verification # email, so we're gonna trust 'em new_user.email_confirmed = 1 new_user.save() query_str = '' if voucher is not None: voucher.apply_to_user(new_user) query_str = '?vid=%s' % str(voucher.id) self.log_user_in(new_user) if new_user.email_confirmed: return self.redirect('/') else: return self.redirect('/confirm-account%s' % query_str) except torndb.IntegrityError: #This is a rare edge case, so we handle it lazily -- IK. pass has_errors = True self.add_errors(new_user.errors) #recaptcha hot fix captcha_string = captcha.displayhtml(options.recaptcha_public_key) promotions = Promotion.active() return self.render("account/create.html", name=name_value, email=email_value, key=key_value, recaptcha=captcha_string, promotions=promotions)
def get(self): user = self.get_current_user_object() payments = [] if user.is_paid: payments = [] if user.stripe_customer_id: customer_id = user.stripe_customer_id charges = stripe.Charge.list(limit=5, customer=customer_id) for charge in charges.data: payments.append({ "transaction_amount": "USD %0.2f" % (charge.amount / 100.0, ), "refund_amount": charge.refunded and "USD %0.2f" % (charge.amount_refunded / 100.0, ) or "", "created_at": datetime.datetime.fromtimestamp(charge.created), "status": "charged", "is_pending": charge.status == "pending", "is_failed": charge.status == "failed", "is_success": charge.status == "succeeded", "is_refund": charge.refunded, }) else: log = PaymentLog.last_payments(count=5, user_id=user.id) for payment in log: payments.append({ "transaction_amount": payment.transaction_amount, "refund_amount": "", "created_at": payment.created_at, "status": payment.status, "is_pending": False, "is_success": True, "is_failed": False, "is_refund": False, }) already_requested = self.get_secure_cookie("image_request") cancel_flag = "canceled" in (user.stripe_plan_id or "") updated_flag = self.get_argument("update", "") == "1" migrated_flag = self.get_argument("migrated", 0) past_due = False source_card_type = None source_last_4 = None source_expiration = None promotions = Promotion.active() has_data_to_migrate = not MigrationState.has_migrated(user.id) if user.stripe_customer_id: customer = None try: customer = stripe.Customer.retrieve(user.stripe_customer_id) except stripe.error.InvalidRequestError: pass if customer and not hasattr(customer, 'deleted'): if customer.subscriptions.total_count >= 1: subscriptions = [ sub for sub in customer.subscriptions.data if sub.plan.id == user.stripe_plan_id ] if subscriptions: subscription = subscriptions[0] past_due = subscription.status == "past_due" if customer.sources.total_count > 0: if customer.sources.data[0].object == "card": card = customer.sources.data[0] elif customer.sources.data[0].object == "source": card = customer.sources.data[0].card source_card_type = card.brand source_last_4 = card.last4 source_expiration = "%d/%d" % (card.exp_month, card.exp_year) return self.render("account/settings.html", user=user, payments=payments, already_requested=already_requested, promotions=promotions, plan_name=plan_name(user.stripe_plan_id), past_due=past_due, stripe_public_key=options.stripe_public_key, source_card_type=source_card_type, source_last_4=source_last_4, source_expiration=source_expiration, has_data_to_migrate=has_data_to_migrate, updated_flag=updated_flag, migrated_flag=migrated_flag, cancel_flag=cancel_flag)
def post(self): if options.disable_signups: return name_value = self.get_argument('name', '') email_value = self.get_argument('email', '') key_value = self.get_argument('key', '') has_errors = False voucher = None if key_value != '': voucher = is_valid_voucher_key(key_value) if voucher is None: has_errors = True self.add_error('key', 'Invalid discount code') new_user = User(name=name_value, email=email_value, email_confirmed=0) new_user.set_and_confirm_password( self.get_argument('password', ""), self.get_argument('password_again', "")) skip_recaptcha = self.get_argument('_skip_recaptcha_test_only', False) if not options.recaptcha_secret_key: skip_recaptcha = True # recaptcha validation, when configured if not skip_recaptcha: response = requests.post( "https://www.google.com/recaptcha/api/siteverify", params={ "secret": options.recaptcha_secret_key, "response": self.get_argument("recaptcha_token"), }) try: result = response.json() if not result["success"] or result["score"] < 0.5: has_errors = True self.add_error("recaptcha", "Invalid captcha") except ValueError: has_errors = True self.add_error("recaptcha", "Invalid captcha") if not has_errors: try: # create form asserts the user agress to terms of use new_user.tou_agreed = 1 if new_user.save(): if options.postmark_api_key: # i'd like to NOT invalidate_email in the # case of using a voucher, but the person # may use a different email for MLTSHP than # they used for receiving their voucher, so... new_user.invalidate_email() else: # we have no way to send a verification # email, so we're gonna trust 'em new_user.email_confirmed = 1 new_user.save() query_str = '' if voucher is not None: voucher.apply_to_user(new_user) query_str = '?vid=%s' % str(voucher.id) self.log_user_in(new_user) if new_user.email_confirmed: return self.redirect('/') else: return self.redirect('/confirm-account%s' % query_str) except torndb.IntegrityError: #This is a rare edge case, so we handle it lazily -- IK. pass has_errors = True self.add_errors(new_user.errors) promotions = Promotion.active() return self.render("account/create.html", name=name_value, email=email_value, key=key_value, recaptcha_site_key=options.recaptcha_site_key, promotions=promotions)
def test_active_promotion_list(self): promotions = Promotion.active() self.assertEqual(len(promotions), 1) self.assertEqual(promotions[0].id, self.promotion.id)