Beispiel #1
0
 def post(self, request, *args, **kwargs):
     form = forms.RegisterSponsorForm(request.POST)
     if form.is_valid():
         email = form.cleaned_data['email']
         name = form.cleaned_data['name']
         n_max = form.cleaned_data['n_max']
         password = ''.join(
             random.choice(string.ascii_uppercase + string.digits)
             for _ in range(10))
         if models.User.objects.filter(email=email).first() is not None:
             messages.error(request,
                            'An account with this email already exists')
         else:
             user = models.User.objects.create_sponsor(email=email,
                                                       password=password,
                                                       name=name,
                                                       n_max=n_max)
             msg = tokens.generate_sponsor_link_email(user, request)
             msg.send()
             messages.success(request,
                              "Sponsor link email successfully sent")
             return HttpResponseRedirect(reverse('sponsor_user_list'))
     context = self.get_context_data()
     context.update({'form': form})
     return TemplateResponse(request, self.template_name, context)
Beispiel #2
0
 def get_context_data(self, *args, **kwargs):
     context = super(SponsorRegister, self).get_context_data(**kwargs)
     form = forms.RegisterSponsorForm()
     context.update({'form': form})
     return context