Beispiel #1
0
def register_page(request):
    if request.method == 'POST':
        form = forms.RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
                email=form.cleaned_data['email'],
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
            )
            user.is_active = False
            user.save()
            user.userprofile.affiliation = form.cleaned_data['affiliation']
            user.userprofile.save()

            # send notification email to admin to review the account
            current_site = get_current_site(request)
            dashboard.email.email_admin_on_new_user(current_site, user)

            return HttpResponseRedirect(reverse('account-register-success'))
    else:
        form = forms.RegistrationForm()

    ret = {
        'form': form
    }
    return render(request, 'registration/register.html', ret)
Beispiel #2
0
def register_page(request):
    if request.method == 'POST':
        form = forms.RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
                email=form.cleaned_data['email'],
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
            )
            user.is_active = False
            user.save()
            user.userprofile.affiliation = form.cleaned_data['affiliation']
            user.userprofile.save()

            # send notification email to admin to review the account
            subject = "New user registration - %s" % user.username
            current_site = get_current_site(request)
            context = {"username": user.username, "domain": current_site.domain}
            message = loader.render_to_string('registration/email_notify_admin.html', context)
            from_email = settings.NOTIFICATION_EMAIL_FROM
            recipients = [a for a in settings.NOTIFICATION_EMAIL_TO]
            send_mail(subject, message, from_email, recipients, fail_silently=True)

            return HttpResponseRedirect(reverse('social-auth-register-success'))
    else:
        form = forms.RegistrationForm()

    ret = {
        'form': form
    }
    return render(request, 'registration/register.html', ret)
Beispiel #3
0
def show_registration_page(request):
    template = 'account/recruiter_register.html'
    form = forms.RegistrationForm()
    return render(
        request,
        template,
        {
            'form': form,
        },
    )
Beispiel #4
0
    def test_registration_form_adds_custom_user_name_field(self):
        """
        Test that ``RegistrationForm`` adds custom username
        field and does not raise errors

        """

        form = forms.RegistrationForm()

        self.assertTrue(UsernameField() in form.fields)
Beispiel #5
0
    def test_registration_form_subclass_is_valid(self):
        """
        Test that ``RegistrationForm`` subclasses can save

        """
        data = {
            'new_field': 'custom username',
            'email': '*****@*****.**',
            'password1': 'foo',
            'password2': 'foo'
        }

        form = forms.RegistrationForm(data=data)

        self.assertTrue(form.is_valid())
Beispiel #6
0
def signup(request):
    if request.method == 'GET':
        return show_registration_page(request)
    elif request.method == 'POST':
        # TODO need to use https
        form = forms.RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                form.data.get('username'),
                form.data.get('email'),
                form.data.get('password'),
            )
            user.save()

            return render(
                request,
                'landing_pages/index.html',
            )
        else:
            return show_registration_page(request)
Beispiel #7
0
def create_signup_form():
    return forms.RegistrationForm()
Beispiel #8
0
    def test_registration_form(self):
        """
        Test that ``RegistrationForm`` enforces username constraints
        and matching passwords.

        """
        # Create a user so we can verify that duplicate usernames aren't
        # permitted.
        UserModel().objects.create_user('alice', '*****@*****.**', 'secret')
        bad_username_error = (
            'Enter a valid username. This value may contain only letters, '
            'numbers, and @/./+/-/_ characters.')
        if django.VERSION < (1, 10):
            bad_username_error = bad_username_error.replace(
                'numbers,', 'numbers')
        elif six.PY2:
            bad_username_error = bad_username_error.replace(
                'letters', 'English letters')
        invalid_data_dicts = [
            # Non-alphanumeric username.
            {
                'data': {
                    'username': '******',
                    'email': '*****@*****.**',
                    'password1': 'foo',
                    'password2': 'foo'
                },
                'error': ('username', [bad_username_error])
            },
            # Already-existing username.
            {
                'data': {
                    'username': '******',
                    'email': '*****@*****.**',
                    'password1': 'secret',
                    'password2': 'secret'
                },
                'error':
                ('username', ["A user with that username already exists."])
            },
            # Mismatched passwords.
            {
                'data': {
                    'username': '******',
                    'email': '*****@*****.**',
                    'password1': 'foo',
                    'password2': 'bar'
                },
                'error':
                ('password2', ["The two password fields didn't match."])
            },
        ]

        for invalid_dict in invalid_data_dicts:
            form = forms.RegistrationForm(data=invalid_dict['data'])
            self.failIf(form.is_valid())
            self.assertEqual(form.errors[invalid_dict['error'][0]],
                             invalid_dict['error'][1])

        form = forms.RegistrationForm(
            data={
                'username': '******',
                'email': '*****@*****.**',
                'password1': 'foo',
                'password2': 'foo'
            })
        self.failUnless(form.is_valid())