예제 #1
0
 def test_sets_username_to_email(self):
     data = {
         "email": "*****@*****.**",
         "first_name": "Foo",
         "last_name": "Bar",
         "password1": "abcdef456",
         "password2": "abcdef456",
     }
     form = SignUpForm(data=data)
     self.assertTrue(form.is_valid())
     user = form.save()
     self.assertEqual(user, User.objects.first())
     self.assertEqual(user.username, user.email)
     self.assertEqual(user.email, data["email"])
예제 #2
0
def signup(request):
    try:
        if request.method == 'POST':
            form = SignUpForm(request.POST)
            if form.is_valid():
                form.save()
                username = form.cleaned_data.get('username')
                raw_password = form.cleaned_data.get('password1')
                usn = form.cleaned_data.get('usn')
                name = form.cleaned_data.get('first_name')
                Register.objects.create(name=name,
                                        usn=str(usn).upper(),
                                        pk=username)
                user = authenticate(username=username, password=raw_password)
                auth_login(request, user)
                User.objects.filter(username=username).update(email=username)
                return render(request, 'dashboard.html', {
                    "user": request.user.get_full_name(),
                    "test_name": test_name
                })
        else:
            form = SignUpForm()
        return render(request, 'signup.html', {'form': form})
    except Exception as e:
        return render(request, "error.html", {"user": "******"})
예제 #3
0
    def test_email_uniqueness(self):
        """
        Test that the case insensitive validator for email was configured correctly
        """
        User.objects.create_user(username="******",
                                 email="*****@*****.**",
                                 password="******")
        data = {
            "email": "*****@*****.**",
            "first_name": "Foo",
            "last_name": "Bar",
            "password1": "abcdef456",
            "password2": "abcdef456",
        }

        form = SignUpForm(data=data)
        self.assertFalse(form.is_valid())
        self.assertIn("This email is unavailable", form.errors["email"])
예제 #4
0
 def test_fields_required(self):
     form = SignUpForm()
     for field in (
             User.get_email_field_name(),
             "first_name",
             "last_name",
             "password1",
             "password2",
     ):
         self.assertTrue(form.fields[field].required)
예제 #5
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()

            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            message = render_to_string(
                'prabhav/registration/account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            from_email = [settings.EMAIL_HOST_USER]
            to_email = [user.email]
            send_mail(subject=subject,
                      from_email=from_email,
                      recipient_list=to_email,
                      message=message,
                      fail_silently=False)

            return redirect('account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'prabhav/registration/signup.html', {'form': form})
예제 #6
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False

            user.save()
            current_site = get_current_site(request)

            message = render_to_string(
                'registration/account_activation_email.html', {
                    'user':
                    user,
                    'domain':
                    current_site.domain,
                    'uid':
                    urlsafe_base64_encode(force_bytes(
                        user.pk)).decode("utf-8"),
                    'token':
                    account_activation_token.make_token(user),
                })

            subject = 'Activate Your MySite Account'
            user.email_user(subject, message)

            return render(request, 'registration/account_activation_sent.html',
                          {'user': user})
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
예제 #7
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('temp_homepage')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
    def post(self, request, *args, **kwargs):
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = "Activate Your Skagit BMC Account"
            email_context = {
                "user": user,
                "protocol": request.scheme,
                "domain": current_site.domain,
                "uid": urlsafe_base64_encode(force_bytes(user.pk)),
                "token": account_activation_token.make_token(user),
            }
            text_message = render_to_string(
                "registration/account_activation_email.txt", email_context)
            html_message = render_to_string(
                "registration/account_activation_email.html", email_context)
            user.email_user(subject, text_message, html_message=html_message)
            return redirect("account_activation_sent")

        else:
            return render(request, "registration/signup.html", {"form": form})
예제 #9
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user)
            return redirect(to='/board')
    else:
        form = SignUpForm()
    return render(request, 'registration.html', {'form': form})
예제 #10
0
 def test_has_email_validators(self):
     """
     Test that the necessary validators for email have been added.
     """
     form = SignUpForm()
     email_validators = form.fields["email"].validators
     self.assertTrue(
         any(
             isinstance(v, validators.HTML5EmailValidator)
             for v in email_validators))
     self.assertTrue(
         validators.validate_confusables_email in email_validators)
     self.assertTrue(
         any(
             isinstance(v, validators.CaseInsensitiveUnique)
             for v in email_validators))
예제 #11
0
def register(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)

            guest_group = Group.objects.get(name='Guest')
            guest_group.user_set.add(user)
            login(request, user)
            return redirect('post_list')
    else:
        form = SignUpForm()
    return render(request, 'guest/register.html', {'form': form})
예제 #12
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            username = form.cleaned_data.get('username')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            auth_login(request, user)
            return redirect('welcome')
    else:
        form = SignUpForm()
    return render(request, 'index.html', {'form': form})
예제 #13
0
def signup(request):
    # POST requests are usually used for submissions
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        # call the form’s is_valid() method
        if form.is_valid():
            # If is_valid() is True, we’ll be able to find all the validated form data in its cleaned_data attribute
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            # redirect to the page where the user can see that his signing up was successful
            # in the urls.py has to be specified where to find the template that should be shown under:
            return redirect('/registration/done')
    else:
        form = SignUpForm()
        # folder where the signup.html template can be found
    return render(request, 'registration/signup.html', {'form': form})
예제 #14
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()  # load the profile instance created by the signal
            user.profile.phone = form.cleaned_data.get('phone')
            user.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'signup.html', {'form': form})
예제 #15
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db(
            )  # load the profile instance created by the signal
            # user.customers.pseudo = form.cleaned_data.get('pseudo')
            user.save()
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            return redirect('registration:profile')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
예제 #16
0
def signup(request):
    """Create a new unactivated user in the db for a potential new user."""
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            # This is needed to force the user to rely on the email
            # confirmation. Otherwise, the user can log in without the
            # confirmation email.
            user.is_active = False
            # user_name = f"{user.first_name}_{user.last_name}"
            # Creates new user object in the database.
            user.save()

            # Load the profile instance created by the signal
            # Needed to save the profile details of the user.
            user.refresh_from_db()
            # Save again, to save the new changes made to the user's profile
            user.save()

            # Without this the user will not belong to any group.
            # Newly signed up users can only be customers. Otherwise, they have
            # to have an account created to them by the admin/staff manually.
            group = Group.objects.get(name="Inquirers")
            group.user_set.add(user)

            current_site = get_current_site(request)
            subject = 'Activate Your Questions & Answers Account'
            message = render_to_string('account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
                'token': account_activation_token.make_token(user),
            })
            user.email_user(subject, message)

            return redirect("account_activation_sent")
    else:
        form = SignUpForm()

    return render(request, 'signup.html', {'form': form})
 def get(self, request, *args, **kwargs):
     form = SignUpForm()
     return render(request, "registration/signup.html", {"form": form})