def get(self, *args, **kwargs): if app_settings.LOGOUT_ON_GET: return self.post(*args, **kwargs) if not self.request.user.is_authenticated: response = redirect(self.get_redirect_url()) return _ajax_response(self.request, response) if self.request.user.is_authenticated: self.logout() ctx = self.get_context_data() response = self.render_to_response(ctx) return _ajax_response(self.request, response)
def post(self, request, *args, **kwargs): form_class = self.get_form_class() form = self.get_form(form_class) if form.is_valid(): response = self.form_valid(form) return _ajax_response(self.request, response, form=form) else: return JsonResponse({'errors': form.errors})
def post(self, *args, **kwargs): url = self.get_redirect_url() if self.request.user.is_authenticated: logout_user = self.request.user db_logger.info(f'Successfully logged out user - {logout_user}') self.logout() response = redirect(url) return _ajax_response(self.request, response)
def post(self, request, *args, **kwargs): form_class = self.get_form_class() form = self.get_form(form_class) if form.is_valid(): response = self.form_valid(form) return _ajax_response(self.request, response, form=form) else: response = self.form_invalid(form) #TODO json return HttpResponse(response.context_data['form'].errors.items()[0][1])
def post(self, request, *args, **kwargs): res = None if "action_add" in request.POST: res = super(EmailView, self).post(request, *args, **kwargs) elif request.POST.get("email"): if "action_send" in request.POST: res = self._action_send(request) elif "action_remove" in request.POST: res = self._action_remove(request) elif "action_primary" in request.POST: res = self._action_primary(request) res = res or HttpResponseRedirect(reverse('accounts:settings')) # Given that we bypassed AjaxCapableProcessFormViewMixin, # we'll have to call invoke it manually... res = _ajax_response(request, res) else: # No email address selected res = HttpResponseRedirect(reverse('accounts:settings')) res = _ajax_response(request, res) return res
def post(self, request, *args, **kwargs): res = None if "action_add" in request.POST: res = super(EmailView, self).post(request, *args, **kwargs) elif request.POST.get("email"): if "action_send" in request.POST: res = self._action_send(request) elif "action_remove" in request.POST: res = self._action_remove(request) elif "action_primary" in request.POST: res = self._action_primary(request) res = res or HttpResponseRedirect( reverse('userprofile:profile-email')) # Given that we bypassed AjaxCapableProcessFormViewMixin, # we'll have to call invoke it manually... res = _ajax_response(request, res) return res
def dispatch(self, request, uidb36, key, **kwargs): self.request = request self.key = key if self.key == INTERNAL_RESET_URL_KEY: self.key = self.request.session.get(INTERNAL_RESET_SESSION_KEY, "") # (Ab)using forms here to be able to handle errors in XHR #890 token_form = UserTokenForm(data={ "uidb36": uidb36, "key": self.key }) if token_form.is_valid(): self.reset_user = token_form.reset_user # In the event someone clicks on a password reset link # for one account while logged into another account, # logout of the currently logged in account. if (self.request.user.is_authenticated and self.request.user.pk != self.reset_user.pk): self.logout() self.request.session[INTERNAL_RESET_SESSION_KEY] = self.key self.request.session['reset_user_id'] = self.reset_user.id form = SetPasswordForm() return render(request, 'account/password_set.html', {"form": form}) else: token_form = UserTokenForm(data={ "uidb36": uidb36, "key": self.key }) if token_form.is_valid(): # Store the key in the session and redirect to the # password reset form at a URL without the key. That # avoids the possibility of leaking the key in the # HTTP Referer header. self.request.session[INTERNAL_RESET_SESSION_KEY] = self.key redirect_url = self.request.path.replace( self.key, INTERNAL_RESET_URL_KEY) return redirect(redirect_url) self.reset_user = None response = self.render_to_response( self.get_context_data(token_fail=True)) return _ajax_response(self.request, response, form=token_form)
def user_settings_view_new(request): profile_updated = False # if this is a POST request we need to process the form data if 'edit_profile' in request.POST: # create a form instance and populate it with data from the request: edit_profile_form = EditProfileForm(data=request.POST, user=request.user) # check whether it's valid: if edit_profile_form.is_valid(): edit_profile_form.save(request) messages.success(request, "You've successfully updated your profile.") profile_updated = True # if a GET (or any other method) we'll create a blank form else: edit_profile_form = EditProfileForm(user=request.user) if 'edit_active_card' in request.POST: try: stripe_token = request.POST.get('stripe_token') customer, created = Customer.get_or_create( subscriber=subscriber_request_callback(request)) update_active_card(customer, stripe_token) except stripe.StripeError as e: # add form error here return _ajax_response( request, JsonResponse({'error': e.args[0]}, status=500)) messages.success(request, 'Your account card has been changed successfully.') profile_updated = True if 'change_email' in request.POST: change_email_form = ChangeEmailForm(data=request.POST, user=request.user) if change_email_form.is_valid(): change_email_form.save(request) messages.success( request, 'Your email address has been changed successfully.') profile_updated = True else: change_email_form = ChangeEmailForm(user=request.user) if 'change_password' in request.POST: change_password_form = ChangePasswordForm(data=request.POST, user=request.user) if change_password_form.is_valid(): change_password_form.save() messages.success(request, 'Your password has been changed successfully.') profile_updated = True else: change_password_form = ChangePasswordForm(user=request.user) # if this is a POST request we need to process the form data if 'artist_info' in request.POST: # create a form instance and populate it with data from the request: artist_info_form = ArtistInfoForm(data=request.POST, instance=request.user) # check whether it's valid: if artist_info_form.is_valid(): artist_info_form.save(request) messages.success(request, "You've successfully updated your profile.") profile_updated = True else: assert False, artist_info_form.errors # if a GET (or any other method) we'll create a blank form else: artist_info_form = ArtistInfoForm(instance=request.user) if 'billing_info' in request.POST: billing_address_form = BillingAddressForm(None, request.user, request.POST) if billing_address_form.is_valid(): billing_address_form.save() profile_updated = True else: billing_address_form = BillingAddressForm(None, request.user, None) if profile_updated: return HttpResponseRedirect('/accounts/settings/') plan = None period_end = {} period_end['date'] = None customer_detail = None customer_charges = None user_archive_access_until = None monthly_pledge_in_dollars = None cancel_at = None billing_address = None show_email_confirmation = False try: customer = request.user.customer except: customer = None user_archive_access_until = None if request.user.has_archive_access: user_archive_access_until = request.user.get_archive_access_expiry_date( ) if customer and customer.has_active_subscription(): plan_id = request.user.customer.current_subscription.plan try: plan = stripe.Plan.retrieve(id=plan_id) except stripe.error.InvalidRequestError: plan = None customer_charges = request.user.get_donations().order_by('-date') charges_value = 0 for charge in customer_charges: if charge.amount: charges_value = charges_value + charge.amount artist_info_form = ArtistInfoForm(instance=request.user) customer_detail = CustomerDetail.get(id=request.user.customer.stripe_id) if customer_detail and customer_detail.subscription: monthly_pledge_in_dollars = customer_detail.subscription.plan.amount / 100 if customer_detail and customer_detail.subscription: period_end["date"] = datetime.fromtimestamp( customer_detail.subscription.current_period_end).strftime( "%d/%m/%y") period_end["due"] = datetime.fromtimestamp( customer_detail.subscription.current_period_end) <= datetime.now() if customer_detail and customer_detail.subscription and customer_detail.subscriptions.data: cancel_at = customer_detail.subscriptions.data[0][ 'cancel_at_period_end'] else: cancel_at = False try: billing_address = request.user.addresses.get( is_default_for_billing=True) except UserAddress.DoesNotExist: try: billing_address = request.user.addresses.first() except UserAddress.DoesNotExist: billing_address = UserAddress() return render( request, 'account/user_settings_new.html', { 'STRIPE_PUBLIC_KEY': settings.STRIPE_PUBLIC_KEY, 'change_email_form': change_email_form, 'change_profile_form': edit_profile_form, 'change_password_form': change_password_form, 'current_user': request.user, 'artist_info_form': artist_info_form, 'plan': plan, 'donations': request.user.get_donations() or None, 'customer_detail': customer_detail or '', 'customer_charges': customer_charges or '', 'charges_value': request.user.get_donation_amount or '0', 'period_end': period_end, 'user_archive_access_until': user_archive_access_until or 'unverified account', 'monthly_pledge_in_dollars': monthly_pledge_in_dollars or 'no', 'cancelled': cancel_at or '', 'donate_url': reverse('donate'), 'billing_address': billing_address or '', 'show_email_confirmation_dialog': show_email_confirmation })
def post(self, request, *args, **kwargs): self.set_attributes() self.set_artist() self.set_product() self.set_event() self.set_billing_address() if self.existing_cc: stripe_customer = self.request.user.customer.stripe_customer self.stripe_token = stripe_customer.get('default_source') if self.amount: self.amount = int(self.amount) if self.stripe_token: try: # If no reference returned, then the user is subscribing to a plan # Donation will come through the webhook instead. reference = self.execute_stripe_payment() if reference: self.create_donation(payment_source='Stripe Foundation', reference=reference) url = reverse('become_supporter_complete') + \ "?flow_type=" + self.flow_type if self.product_id: url += '&product_id=' + self.product_id if self.event_id: url += '&event_id=' + self.event_id url += '&event_slug=' + self.event_slug if self.artist_id: url += '&artist_id=' + self.artist_id return _ajax_response(self.request, redirect(url)) except stripe.StripeError as e: # add form error here print e return JsonResponse({'error': str(e)}) elif self.bitcoin: self.execute_bitcoin_payment() url = reverse('supporter_pending') + \ "?pending_payment_type=bitcoin" if self.product_id: url += '&product_id=' + self.product_id if self.event_id: url += '&event_id=' + self.event_id url += '&event_slug=' + self.event_slug if self.artist_id: url += '&artist_id=' + self.artist_id return _ajax_response(self.request, redirect(url)) elif self.check: self.execute_check_payment() url = reverse('supporter_pending') + \ "?pending_payment_type=check" if self.product_id: url += '&product_id=' + self.product_id if self.event_id: url += '&event_id=' + self.event_id url += '&event_slug=' + self.event_slug return _ajax_response(self.request, redirect(url)) else: try: payment_execute_url = self.request.build_absolute_uri( reverse('supporter_paypal_execute')) payment_cancel_url = self.request.build_absolute_uri( reverse('become_supporter')) item = { 'name': 'One Time Donation', 'price': self.amount, "sku": "N/A", 'currency': 'USD', 'quantity': 1 } item_list = [] self.handle_paypal_payment('USD', item_list, donation=True, execute_uri=payment_execute_url, cancel_uri=payment_cancel_url) except RedirectRequiredAjax as e: self.create_donation(payment_source='PayPal Foundation', reference=e.reference, confirmed=False) return JsonResponse({'payment_url': e.url})
def post(self, *args, **kwargs): url = self.get_redirect_url() if self.request.user.is_authenticated: self.logout() response = redirect(url) return _ajax_response(self.request, response)