Ejemplo n.º 1
0
 def is_valid(self):
     ''' Validate form.
     Return True if Django validates the form, the username obeys the parameters, and passwords match.
     Return False otherwise.
     '''
     if not super(ProfileRequestForm, self).is_valid():
         return False
     validity = True
     if self.cleaned_data['password'] != self.cleaned_data['confirm_password']:
         form_add_error(self, 'password', "Passwords don't match.")
         form_add_error(self, 'confirm_password', "Passwords don't match.")
         validity = False
     return validity
Ejemplo n.º 2
0
 def is_valid(self):
     ''' Validate form.
     Return True if Django validates the form, the username obeys the parameters, and passwords match.
     Return False otherwise.
     '''
     if not super(ProfileRequestForm, self).is_valid():
         return False
     validity = True
     if self.cleaned_data['password'] != self.cleaned_data[
             'confirm_password']:
         form_add_error(self, 'password', "Passwords don't match.")
         form_add_error(self, 'confirm_password', "Passwords don't match.")
         validity = False
     return validity
Ejemplo n.º 3
0
 def is_valid(self):
     ''' Validate form.
     Return True if the form is valid by Django's requirements and the username obeys the parameters.
     Return False otherwise.
     '''
     if not super(ModifyProfileRequestForm, self).is_valid():
         return False
     first_name = self.cleaned_data["first_name"]
     last_name = self.cleaned_data["last_name"]
     if User.objects.filter(first_name=first_name, last_name=last_name).count():
         non_field_error = "A profile for {0} {1} already exists with username {2}." \
           .format(first_name, last_name,
                   User.objects.get(first_name=first_name,
                                    last_name=last_name).username)
         form_add_error(self, '__all__', non_field_error)
         return False
     return True
Ejemplo n.º 4
0
 def is_valid(self):
     ''' Validate form.
     Return True if the form is valid by Django's requirements and the username obeys the parameters.
     Return False otherwise.
     '''
     if not super(ModifyProfileRequestForm, self).is_valid():
         return False
     first_name = self.cleaned_data["first_name"]
     last_name = self.cleaned_data["last_name"]
     if User.objects.filter(first_name=first_name,
                            last_name=last_name).count():
         non_field_error = "A profile for {0} {1} already exists with username {2}." \
           .format(first_name, last_name,
                   User.objects.get(first_name=first_name,
                                    last_name=last_name).username)
         form_add_error(self, '__all__', non_field_error)
         return False
     return True
Ejemplo n.º 5
0
def request_profile_view(request):
    ''' The page to request a user profile on the site. '''
    page_name = "Profile Request Page"
    redirect_to = request.REQUEST.get('next', reverse('homepage'))
    if request.user.is_authenticated() and request.user.username != ANONYMOUS_USERNAME:
        return HttpResponseRedirect(redirect_to)
    form = ProfileRequestForm(
        request.POST or None,
        )
    if form.is_valid():
        username = form.cleaned_data['username']
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        email = form.cleaned_data['email']
        if User.objects.filter(username=username).count():
            reset_url = request.build_absolute_uri(reverse('reset_pw'))
            form_add_error(form, 'username',
                           MESSAGES["USERNAME_TAKEN"].format(username=username))
            messages.add_message(request, messages.INFO,
                                 MESSAGES['RESET_MESSAGE'].format(reset_url=reset_url))
        elif User.objects.filter(email=email).count():
            reset_url = request.build_absolute_uri(reverse('reset_pw'))
            messages.add_message(request, messages.INFO,
                                 MESSAGES['RESET_MESSAGE'].format(reset_url=reset_url))
            form_add_error(form, "email", MESSAGES["EMAIL_TAKEN"])
        elif ProfileRequest.objects.filter(first_name=first_name, last_name=last_name).count():
            form_add_error(
                form, '__all__',
                MESSAGES["PROFILE_TAKEN"].format(first_name=first_name,
                                                 last_name=last_name))
        elif User.objects.filter(first_name=first_name, last_name=last_name).count():
            reset_url = request.build_absolute_uri(reverse('reset_pw'))
            messages.add_message(request, messages.INFO, MESSAGES['PROFILE_REQUEST_RESET'].format(reset_url=reset_url))
        else:
            form.save()
            messages.add_message(request, messages.SUCCESS, MESSAGES['PROFILE_SUBMITTED'])
            if settings.SEND_EMAILS and (email not in settings.EMAIL_BLACKLIST):
                submission_subject = SUBMISSION_SUBJECT.format(house=settings.HOUSE_NAME)
                submission_email = SUBMISSION_EMAIL.format(house=settings.HOUSE_NAME, full_name=first_name + " " + last_name, admin_name=settings.ADMINS[0][0],
                    admin_email=settings.ADMINS[0][1])
                try:
                    send_mail(submission_subject, submission_email, settings.EMAIL_HOST_USER, [email], fail_silently=False)
                    # Add logging here
                except SMTPException:
                    pass # Add logging here
            return HttpResponseRedirect(redirect_to)
    return render(request, 'request_profile.html', {
        'form': form,
        'page_name': page_name,
        'oauth_providers': _get_oauth_providers(),
        'redirect_to': redirect_to,
        })
Ejemplo n.º 6
0
def request_profile_view(request):
    """ The page to request a user profile on the site. """
    page_name = "Profile Request Page"
    redirect_to = request.GET.get("next", reverse("homepage"))
    if request.user.is_authenticated() and request.user.username != ANONYMOUS_USERNAME:
        return HttpResponseRedirect(redirect_to)
    form = ProfileRequestForm(request.POST or None)
    if form.is_valid():
        username = form.cleaned_data["username"]
        first_name = form.cleaned_data["first_name"]
        last_name = form.cleaned_data["last_name"]
        email = form.cleaned_data["email"]
        if User.objects.filter(username=username).count():
            reset_url = request.build_absolute_uri(reverse("reset_pw"))
            form_add_error(form, "username", MESSAGES["USERNAME_TAKEN"].format(username=username))
            messages.add_message(request, messages.INFO, MESSAGES["RESET_MESSAGE"].format(reset_url=reset_url))
        elif User.objects.filter(email=email).count():
            reset_url = request.build_absolute_uri(reverse("reset_pw"))
            messages.add_message(request, messages.INFO, MESSAGES["RESET_MESSAGE"].format(reset_url=reset_url))
            form_add_error(form, "email", MESSAGES["EMAIL_TAKEN"])
        elif ProfileRequest.objects.filter(first_name=first_name, last_name=last_name).count():
            form_add_error(
                form, "__all__", MESSAGES["PROFILE_TAKEN"].format(first_name=first_name, last_name=last_name)
            )
        elif User.objects.filter(first_name=first_name, last_name=last_name).count():
            reset_url = request.build_absolute_uri(reverse("reset_pw"))
            messages.add_message(request, messages.INFO, MESSAGES["PROFILE_REQUEST_RESET"].format(reset_url=reset_url))
        else:
            form.save()
            messages.add_message(request, messages.SUCCESS, MESSAGES["PROFILE_SUBMITTED"])
            if settings.SEND_EMAILS and (email not in settings.EMAIL_BLACKLIST):
                submission_subject = SUBMISSION_SUBJECT.format(house=settings.HOUSE_NAME)
                submission_email = SUBMISSION_EMAIL.format(
                    house=settings.HOUSE_NAME,
                    full_name=first_name + " " + last_name,
                    admin_name=settings.ADMINS[0][0],
                    admin_email=settings.ADMINS[0][1],
                )
                try:
                    send_mail(
                        submission_subject, submission_email, settings.EMAIL_HOST_USER, [email], fail_silently=False
                    )
                    # Add logging here
                except SMTPException:
                    pass  # Add logging here
            return HttpResponseRedirect(redirect_to)
    return render(
        request,
        "request_profile.html",
        {"form": form, "page_name": page_name, "oauth_providers": _get_oauth_providers(), "redirect_to": redirect_to},
    )
Ejemplo n.º 7
0
 def is_valid(self):
     ''' Validate form.
     Return True if Django validates the form, the username obeys the parameters, and passwords match.
     Return False otherwise.
     '''
     if not super(AddUserForm, self).is_valid():
         return False
     first_name = self.cleaned_data['first_name']
     last_name = self.cleaned_data['last_name']
     if User.objects.filter(first_name=first_name, last_name=last_name).count():
         non_field_error = "A profile for {0} {1} already exists with username {2}." \
           .format(first_name, last_name,
                   User.objects.get(first_name=first_name, last_name=last_name).username)
         form_add_error(self, '__all__', non_field_error)
         return False
     if self.cleaned_data['user_password'] != self.cleaned_data['confirm_password']:
         form_add_error(self, 'user_password', "Passwords don't match.")
         form_add_error(self, 'confirm_password', "Passwords don't match.")
         return False
     return True
Ejemplo n.º 8
0
 def is_valid(self):
     ''' Validate form.
     Return True if Django validates the form, the username obeys the parameters, and passwords match.
     Return False otherwise.
     '''
     if not super(AddUserForm, self).is_valid():
         return False
     first_name = self.cleaned_data['first_name']
     last_name = self.cleaned_data['last_name']
     if User.objects.filter(first_name=first_name,
                            last_name=last_name).count():
         non_field_error = "A profile for {0} {1} already exists with username {2}." \
           .format(first_name, last_name,
                   User.objects.get(first_name=first_name, last_name=last_name).username)
         form_add_error(self, '__all__', non_field_error)
         return False
     if self.cleaned_data['user_password'] != self.cleaned_data[
             'confirm_password']:
         form_add_error(self, 'user_password', "Passwords don't match.")
         form_add_error(self, 'confirm_password', "Passwords don't match.")
         return False
     return True
Ejemplo n.º 9
0
def request_profile_view(request):
    ''' The page to request a user profile on the site. '''
    page_name = "Profile Request Page"
    redirect_to = request.GET.get('next', reverse('homepage'))
    if request.user.is_authenticated(
    ) and request.user.username != ANONYMOUS_USERNAME:
        return HttpResponseRedirect(redirect_to)
    form = ProfileRequestForm(request.POST or None, )
    if form.is_valid():
        username = form.cleaned_data['username']
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        email = form.cleaned_data['email']
        if User.objects.filter(username=username).count():
            reset_url = request.build_absolute_uri(reverse('reset_pw'))
            form_add_error(
                form, 'username',
                MESSAGES["USERNAME_TAKEN"].format(username=username))
            messages.add_message(
                request, messages.INFO,
                MESSAGES['RESET_MESSAGE'].format(reset_url=reset_url))
        elif User.objects.filter(email=email).count():
            reset_url = request.build_absolute_uri(reverse('reset_pw'))
            messages.add_message(
                request, messages.INFO,
                MESSAGES['RESET_MESSAGE'].format(reset_url=reset_url))
            form_add_error(form, "email", MESSAGES["EMAIL_TAKEN"])
        elif ProfileRequest.objects.filter(first_name=first_name,
                                           last_name=last_name).count():
            form_add_error(
                form, '__all__',
                MESSAGES["PROFILE_TAKEN"].format(first_name=first_name,
                                                 last_name=last_name))
        elif User.objects.filter(first_name=first_name,
                                 last_name=last_name).count():
            reset_url = request.build_absolute_uri(reverse('reset_pw'))
            messages.add_message(
                request, messages.INFO,
                MESSAGES['PROFILE_REQUEST_RESET'].format(reset_url=reset_url))
        else:
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 MESSAGES['PROFILE_SUBMITTED'])
            if settings.SEND_EMAILS and (email
                                         not in settings.EMAIL_BLACKLIST):
                submission_subject = SUBMISSION_SUBJECT.format(
                    house=settings.HOUSE_NAME)
                submission_email = SUBMISSION_EMAIL.format(
                    house=settings.HOUSE_NAME,
                    full_name=first_name + " " + last_name,
                    admin_name=settings.ADMINS[0][0],
                    admin_email=settings.ADMINS[0][1])
                try:
                    send_mail(submission_subject,
                              submission_email,
                              settings.EMAIL_HOST_USER, [email],
                              fail_silently=False)
                    # Add logging here
                except SMTPException:
                    pass  # Add logging here
            return HttpResponseRedirect(redirect_to)
    return render(
        request, 'request_profile.html', {
            'form': form,
            'page_name': page_name,
            'oauth_providers': _get_oauth_providers(),
            'redirect_to': redirect_to,
        })