Exemple #1
0
def about_contact(request):
  if request.user.is_anonymous():
    initial=None
  else:
    initial = {'full_name':request.user.get_full_name(), 'email':request.user.email}
  form = ContactForm(request.POST or None, initial=initial)

  if form.is_valid():
    senderemail = form.cleaned_data['email']
    send_template_email(request,
      template_prefix='contact_email',
      to=settings.GENERIC_CONTACT_EMAIL,
      reply_to=[senderemail],
      extra_context={
        'sendername': form.cleaned_data['full_name'],
        'senderemail': senderemail,
        'message': form.cleaned_data['message'],
      }
    )

    messages.success(request, "Your email has been sent successfully.")
    return redirect(about_contact)

  context = {
    "form": form,
  }
  return render(request, "about_contact.html", context)
Exemple #2
0
def about_contact(request):
    if request.user.is_anonymous():
        initial = None
    else:
        initial = {
            'full_name': request.user.get_full_name(),
            'email': request.user.email
        }
    form = ContactForm(request.POST or None, initial=initial)

    if form.is_valid():
        senderemail = form.cleaned_data['email']
        send_template_email(request,
                            template_prefix='contact_email',
                            to=settings.GENERIC_CONTACT_EMAIL,
                            reply_to=[senderemail],
                            extra_context={
                                'sendername': form.cleaned_data['full_name'],
                                'senderemail': senderemail,
                                'message': form.cleaned_data['message'],
                            })

        messages.success(request, "Your email has been sent successfully.")
        return redirect(about_contact)

    context = {
        "form": form,
    }
    return render(request, "about_contact.html", context)
Exemple #3
0
    def register(self, form):
        # Create a new Member instance
        if hasattr(form, 'save'):
            # FYI: This skips our custom MemberManager
            new_user_instance = form.save()
        else:
            # This will pass the data to the create_user function in our custom MemberManager
            new_user_instance = Member.objects.create_user(**form.cleaned_data)

        # Create a RegistrationProfile instance for that user with a one-time activation key
        registration_profile = RegistrationProfile.objects.create_profile(
            new_user_instance)

        # Send the mail ourselves, so we have control over the templates used
        # We also use a different template name (instead of activation_email.html), so
        #   send_template_email won't inadvertently pull in the original template
        if self.send_email:
            send_template_email(
                self.request,
                template_prefix='registration/registration_complete_email',
                to=[new_user_instance.email],
                extra_context={
                    'user': new_user_instance,
                    'activation_key': registration_profile.activation_key,
                    'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
                })

        # Send the signal that a user has been registered
        signals.user_registered.send(sender=self.__class__,
                                     user=new_user_instance,
                                     request=self.request)
        return new_user_instance
Exemple #4
0
  def register(self, form):
    # Create a new Member instance
    if hasattr(form, 'save'):
      # FYI: This skips our custom MemberManager
      new_user_instance = form.save()
    else:
      # This will pass the data to the create_user function in our custom MemberManager
      new_user_instance = Member.objects.create_user(**form.cleaned_data)

    # Create a RegistrationProfile instance for that user with a one-time activation key
    registration_profile = RegistrationProfile.objects.create_profile(new_user_instance)

    # Send the mail ourselves, so we have control over the templates used
    # We also use a different template name (instead of activation_email.html), so
    #   send_template_email won't inadvertently pull in the original template
    if self.send_email:
      send_template_email(self.request,
        template_prefix='registration/registration_complete_email',
        to=[new_user_instance.email],
        extra_context={
          'user': new_user_instance,
          'activation_key': registration_profile.activation_key,
          'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
        }
      )

    # Send the signal that a user has been registered
    signals.user_registered.send(sender=self.__class__,
                   user=new_user_instance,
                   request=self.request)
    return new_user_instance
Exemple #5
0
def userprofile(request):
  member = request.user
  if request.method == 'POST':
    # User posted changes; populate the form from those changes instead,
    #   but still bind to the member instance
    form = MemberForm(request.POST, request.FILES, instance=member)

    if form.is_valid():
      if 'email' in form.changed_data:
        oldemail = form.initial['email']
        newemail = form.cleaned_data['email']

        # Don't let the user change the email yet. The new one must be confirmed.
        changerequest = PendingEmailChange.objects.create_pendingemail(member)
        confirmation_key = changerequest.confirmation_key
        form.instance.email = oldemail
        form.instance.email_pending = newemail

        # Save the Member instance
        form.instance.save()

        # Notify the old email address of the change
        send_template_email(request,
          template_prefix='changeofemail_old_email',
          to=[oldemail],
          extra_context={'user': member}
        )

        # Send activation link to new email address
        send_template_email(request,
          template_prefix='changeofemail_new_email',
          to=[newemail],
          extra_context={
            'user': member,
            'expiration_days': settings.PENDINGEMAIL_CONFIRMATION_DAYS,
            'confirmation_key': confirmation_key,
          }
        )

        # Add a message to the user
        messages.success(request, "Changes made successfully.")
        messages.warning(request, "Email change is pending activation (see below).")

      else:  # 'email' is not in form.changed_data
        # Save the Member instance
        form.instance.save()

        # Add a message to the user
        messages.success(request, "Changes made successfully.")

      # Everything looks good, so redirect the user to their updated profile page
      return redirect(userprofile)

    else:  # form.is_valid() failed
      # Validation errors on the form, so show the errors instead of redirecting
      messages.error(request, "Changes not applied. Please correct the errors hilighted below.")

  else:  # request.method is GET
    # Initial load of the form; populate from the existing Member instance
    form = MemberForm(instance=member)

  # Lookup all memberships, except if they expired more than 180 days ago
  context = {
    'form': form,
    'membershiplist': Membership.objects.filter(member = member.id,
                        paid_until_date__gte = (datetime.today() - timedelta(days=180)))
  }
  return render(request, "userprofile.html", context)
Exemple #6
0
def userprofile(request):
    member = request.user
    if request.method == 'POST':
        # User posted changes; populate the form from those changes instead,
        #   but still bind to the member instance
        form = MemberForm(request.POST, request.FILES, instance=member)

        if form.is_valid():
            if 'email' in form.changed_data:
                oldemail = form.initial['email']
                newemail = form.cleaned_data['email']

                # Don't let the user change the email yet. The new one must be confirmed.
                changerequest = PendingEmailChange.objects.create_pendingemail(
                    member)
                confirmation_key = changerequest.confirmation_key
                form.instance.email = oldemail
                form.instance.email_pending = newemail

                # Save the Member instance
                form.instance.save()

                # Notify the old email address of the change
                send_template_email(request,
                                    template_prefix='changeofemail_old_email',
                                    to=[oldemail],
                                    extra_context={'user': member})

                # Send activation link to new email address
                send_template_email(
                    request,
                    template_prefix='changeofemail_new_email',
                    to=[newemail],
                    extra_context={
                        'user': member,
                        'expiration_days':
                        settings.PENDINGEMAIL_CONFIRMATION_DAYS,
                        'confirmation_key': confirmation_key,
                    })

                # Add a message to the user
                messages.success(request, "Changes made successfully.")
                messages.warning(
                    request, "Email change is pending activation (see below).")

            else:  # 'email' is not in form.changed_data
                # Save the Member instance
                form.instance.save()

                # Add a message to the user
                messages.success(request, "Changes made successfully.")

            # Everything looks good, so redirect the user to their updated profile page
            return redirect(userprofile)

        else:  # form.is_valid() failed
            # Validation errors on the form, so show the errors instead of redirecting
            messages.error(
                request,
                "Changes not applied. Please correct the errors hilighted below."
            )

    else:  # request.method is GET
        # Initial load of the form; populate from the existing Member instance
        form = MemberForm(instance=member)

    # Lookup all memberships, except if they expired more than 180 days ago
    context = {
        'form':
        form,
        'membershiplist':
        Membership.objects.filter(member=member.id,
                                  paid_until_date__gte=(datetime.today() -
                                                        timedelta(days=180)))
    }
    return render(request, "userprofile.html", context)