Exemple #1
0
 def generate_access_key(self):
     """Generates a random key for accessing the request when it is private."""
     key = utils.generate_key(24)
     self.access_key = key
     self.save()
     logger.info('New access key generated for %s', self)
     return key
Exemple #2
0
def _make_user(request, data):
    """
    Create a new user from just their full name and email and return the user.
    - create a password from a random string of letters and numbers
    - log the user in to their new account
    """
    full_name = data['full_name']
    email = data['email']
    password = generate_key(12)
    # register a new user
    user = miniregister(full_name, email, password)
    # log the new user in
    user = authenticate(username=user.username, password=password)
    login(request, user)
    # return the user
    return user
Exemple #3
0
 def post(self, request, **kwargs):
     """
     First we validate the payment form, so we don't charge someone's card by accident.
     Next, we charge their card. Finally, use the validated payment form to create and
     return a CrowdfundRequestPayment object.
     """
     token = request.POST.get('stripe_token')
     email = request.POST.get('stripe_email')
     payment_form = CrowdfundPaymentForm(request.POST)
     if payment_form.is_valid() and token:
         amount = payment_form.cleaned_data['stripe_amount']
         # If there is no user but the show and full_name fields are filled in,
         # create the user with our "miniregistration" functionality and then log them in
         user = request.user if request.user.is_authenticated() else None
         registered = False
         show = payment_form.cleaned_data['show']
         full_name = payment_form.cleaned_data['full_name']
         if user is None and show and full_name:
             password = generate_key(12)
             user = miniregister(full_name, email, password)
             registered = True
         try:
             crowdfund = payment_form.cleaned_data['crowdfund']
             crowdfund.make_payment(token, email, amount, show, user)
         except (
             stripe.InvalidRequestError,
             stripe.CardError,
             stripe.APIConnectionError,
             stripe.AuthenticationError
         ) as payment_error:
             logging.warn(payment_error)
             return self.return_error(request, payment_error)
         if request.is_ajax():
             data = {
                 'authenticated': user.is_authenticated() if user else False,
                 'registered': registered
             }
             return JsonResponse(data, status=200)
         else:
             messages.success(request, 'Thank you for your contribution!')
             return redirect(self.get_redirect_url())
     return self.return_error(request)
Exemple #4
0
 def generate_confirmation_key(self):
     """Generate random key used for validating the email address"""
     key = generate_key(24)
     self.confirmation_key = key
     self.save()
     return key
Exemple #5
0
 def generate_sharing_code(self):
     """Generate a new sharing code, save it to the request, and then return a URL."""
     self.sharing_code = generate_key(12)
     self.save()
     return self.sharing_code