Beispiel #1
0
def signup_view(request, instance=None):
    Profileform = forms.SignUpForm(
        request.POST or None, request.FILES or None, instance=instance)
    Basicform = forms.BasicForm(
        request.POST or None, request.FILES or None, instance=instance)
    if request.method == 'POST':
        if Profileform.is_valid() and Basicform.is_valid():
            user = Basicform.save(commit=False)
            profile = Profileform.save(commit=False)
            user.first_name = profile.First_name
            user.last_name = profile.Last_name
            user.email = profile.Email_address
            user.set_password(user.password)
            user.save()
            profile.user = user

            # if 'profile_pic' in request.FILES:
            #     profile.profile_pic = request.FILES['profile_pic']
            # else:
            #     profile.profile_pic = 'profile_pic/default-user.jpg'

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
            else:
                profile.profile_pic = 'profile_pic/default-user.jpg'

            profile.save()

            messages.success(request, 'Account has been created.')
            return redirect('articles:homepage')
            # messages.success(request, 'Account has been created.')
            return redirect('users:searchbyauthor',author=user.username)
            # return redirect('users:activate_account',user=user,profile=profile)
            # messages.success(request, 'Account has been created.')
            return redirect('users:searchbyauthor',author=user.username)
            # return redirect('users:activate_account',user=user,profile=profile)
        else:
            messages.error(request, 'Failed to Create User')
            Profileform = forms.SignUpForm(
                request.POST or None, request.FILES or None, instance=instance)
            Basicform = forms.BasicForm(
                request.POST or None, request.FILES or None, instance=instance)
    else:

        messages.error(request, 'Failed to Create User')
        Profileform = forms.SignUpForm(
            request.POST or None, request.FILES or None, instance=instance)
        Basicform = forms.BasicForm(
            request.POST or None, request.FILES or None, instance=instance)

    context = {
        'profileform': Profileform,
        'basicform': Basicform,
        'title': 'Sign Up',
    }
    return render(request, 'signup.html', context)
Beispiel #2
0
def update(request, req_user=None):
    user = request.user
    if user.username != req_user:
        return redirect('users:searchbyauthor',author=user.username)
    profile = SiteUser.objects.filter(user=user).first()
    Profileform = forms.SignUpForm(
        request.POST or None, request.FILES or None, instance=profile)
    Basicform = forms.BasicForm(
        request.POST or None, request.FILES or None, instance=user)
    if request.method == 'POST':
        if Profileform.is_valid() and Basicform.is_valid():
            user = Basicform.save(commit=False)
            profile = Profileform.save(commit=False)
            user.first_name = profile.First_name
            user.last_name = profile.Last_name
            user.email = profile.Email_address
            user.set_password(user.password)
            user.save()

            profile.user = user

            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']
            else:
                profile.profile_pic = 'profile_pic/default-user.jpg'

            profile.save()

            messages.success(request, 'Account has been updated.')
            return redirect('users:searchbyauthor',author=request.user)
        else:
            messages.error(request, 'Failed to Update Details')
            Profileform = forms.SignUpForm(
                request.POST or None, request.FILES or None, instance=profile)
            Basicform = forms.BasicForm(
                request.POST or None, request.FILES or None, instance=user)
    else:

        messages.error(request, 'Failed to Update Details')
        Profileform = forms.SignUpForm(
            request.POST or None, request.FILES or None, instance=profile)
        Basicform = forms.BasicForm(
            request.POST or None, request.FILES or None, instance=user)

    context = {
        'profileform': Profileform,
        'basicform': Basicform,
        'title': 'Update',
    }
    return render(request, 'update.html', context)
Beispiel #3
0
 def test_signup_form_already_used_email_invalid(self):
     form = forms.SignUpForm(
         data={
             "email": self.test_user.username,
             "password": self.password,
             "confirm_password": self.password,
         })
     self.assertFalse(form.is_valid())
Beispiel #4
0
 def test_signup_form_invalid_confirm_password(self):
     form = forms.SignUpForm(
         data={
             "email": self.email,
             "password": self.password,
             "confirm_password": self.password + "!",
         })
     self.assertFalse(form.is_valid())
Beispiel #5
0
 def test_signup_form_without_name_valid(self):
     form = forms.SignUpForm(
         data={
             "email": self.email,
             "password": self.password,
             "confirm_password": self.password,
         })
     self.assertTrue(form.is_valid())
    def test_valid_form(self):
        form = forms.SignUpForm({
            'username': '******',
            'password1': 'fromstatefarm',
            'password2': 'fromstatefarm'
        })

        assert form.is_valid()

        user = form.save(commit=False)
        assert user.username == 'jake'
    def test_blank_form(self):
        form = forms.SignUpForm({})
        assert not form.is_valid()

        expected_form_errors = {
            'username': ['This field is required.'],
            'password1': ['This field is required.'],
            'password2': ['This field is required.']
        }

        assert form.errors == expected_form_errors