def run(self, user_id): UserSubscription.trim_user_read_stories(user_id) UserSubscription.verify_feeds_scheduled(user_id) Profile.count_all_feed_subscribers_for_user(user_id) # UserSubscription.refresh_stale_feeds(user_id) try: ss = MSocialServices.objects.get(user_id=user_id) except MSocialServices.DoesNotExist: logging.debug(" ---> ~FRCleaning up user, can't find social_services for user_id: ~SB%s" % user_id) return ss.sync_twitter_photo()
def save(self, profile_callback=None): username = self.cleaned_data["username"] password = self.cleaned_data["password"] email = self.cleaned_data.get("email", None) if email: email_exists = User.objects.filter(email__iexact=email).count() if email_exists: raise forms.ValidationError(_(u"Someone is already using that email address.")) exists = User.objects.filter(username__iexact=username).count() if exists: user_auth = authenticate(username=username, password=password) if not user_auth: raise forms.ValidationError(_(u"Someone is already using that username.")) else: return user_auth if not password: password = username new_user = User(username=username) new_user.set_password(password) new_user.is_active = False new_user.email = email new_user.save() new_user = authenticate(username=username, password=password) new_profile = Profile(user=new_user) new_profile.save() MActivity.new_signup(user_id=new_user.pk) RNewUserQueue.add_user(new_user.pk) if new_user.email: EmailNewUser.delay(user_id=new_user.pk) if getattr(settings, "AUTO_PREMIUM_NEW_USERS", False): new_user.profile.activate_premium() elif getattr(settings, "AUTO_ENABLE_NEW_USERS", False): new_user.profile.activate_free() return new_user
def get_auth_token(self, request): profile = Profile.from_user(request.user) agave_tokens = profile.tokens.filter(app__provider='agave') # 403 if the user has no token if not agave_tokens.exists(): raise PermissionDenied( 'You must first authenticate against Agave.') assert agave_tokens.count() == 1 token = agave_tokens.get() # Renew if token has expired if token.expires_at < timezone.now(): profile.renew_tokens() return profile.tokens.filter(app__provider='agave').get().token return token.token
def stripe_checkout(request): stripe.api_key = settings.STRIPE_SECRET domain = Site.objects.get_current().domain plan = request.POST['plan'] if plan == "change_stripe": checkout_session = stripe.billing_portal.Session.create( customer=request.user.profile.stripe_id, return_url="http://%s%s?next=payments" % (domain, reverse('index')), ) return HttpResponseRedirect(checkout_session.url, status=303) price = Profile.plan_to_stripe_price(plan) session_dict = { "line_items": [ { 'price': price, 'quantity': 1, }, ], "mode": 'subscription', "metadata": { "newsblur_user_id": request.user.pk }, "success_url": "http://%s%s" % (domain, reverse('stripe-return')), "cancel_url": "http://%s%s" % (domain, reverse('index')), } if request.user.profile.stripe_id: session_dict['customer'] = request.user.profile.stripe_id else: session_dict["customer_email"] = request.user.email checkout_session = stripe.checkout.Session.create(**session_dict) logging.user(request, "~BM~FBLoading Stripe checkout") return HttpResponseRedirect(checkout_session.url, status=303)
def run(self, **kwargs): logging.debug(" ---> Finding spammers...") Profile.clear_dead_spammers(confirm=True)
def ReimportStripeHistory(): logging.debug(" ---> Reimporting Stripe history...") Profile.reimport_stripe_history(limit=10, days=1)
def CleanSpam(): logging.debug(" ---> Finding spammers...") Profile.clear_dead_spammers(confirm=True)
def run(self, **kwargs): logging.debug(" ---> Reimporting Stripe history...") Profile.reimport_stripe_history(limit=10, days=1)
def handle(self, *args, **options): limit = options.get('limit') days = int(options.get('days')) starting_after = options.get('start') Profile.reimport_stripe_history(limit, days, starting_after)