Exemplo n.º 1
0
def register(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('select-course'))

    context = {}
    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            new_user = User.objects.create_user(
                username=request.POST['username'],
                email=request.POST['email'],
                password=request.POST['password'],
                first_name=request.POST['first_name'],
                last_name=request.POST['last_name'],
                is_active=False)
            # TODO: Email activation of user

            init_activation(new_user)

            context['args'] = '{}'
            context['app_name'] = 'login'
            return render(request, 'base.html', context=context)

        else:
            context['args'] = '{' + form.d2r_friendly_errors(
            ) + form.safe_data() + '}'
            context['app_name'] = 'register'
            return render(request, 'base.html', context=context)

    else:
        context['app_name'] = 'register'
        context['args'] = '{}'
        return render(request, 'base.html', context=context)
Exemplo n.º 2
0
 def setUp(self):
     self.user_form = UserForm(
         {'username': '******',
          'first_name': 'Firstname',
          'last_name': 'Lastnamesonson the Third',
          'email': '*****@*****.**',
          'password': '******',
          'confirm_password': '******'}
     )
Exemplo n.º 3
0
 def setUp(self):
     self.user_form = UserForm(
         {'username': '******',
          'first_name': 'asd',
          'last_name': 'sad',
          'email': '*****@*****.**',
          'password': '******',
          'confirm_password': '******'}
     )
Exemplo n.º 4
0
 def setUp(self):
     self.user_form = UserForm(
         {'username': '',
          'first_name': '',
          'last_name': '',
          'email': '',
          'password': '',
          'confirm_password': ''}
     )
Exemplo n.º 5
0
class BadUserRegistrationTestCase4(TestCase):
    def setUp(self):
        self.user_form = UserForm(
            {'username': '******',
             'first_name': 'asd',
             'last_name': 'sad',
             'email': '*****@*****.**',
             'password': '******',
             'confirm_password': '******'}
        )
    
    def testReject(self):
        self.assertNotEqual(self.user_form.d2r_friendly_errors(),'')
        self.assertFalse(self.user_form.is_valid())
Exemplo n.º 6
0
class UserRegistrationTestCase(TestCase):
    def setUp(self):
        self.user_form = UserForm(
            {'username': '******',
             'first_name': 'Firstname',
             'last_name': 'Lastnamesonson the Third',
             'email': '*****@*****.**',
             'password': '******',
             'confirm_password': '******'}
        )

    def _test_form_is_valid(self):
        self.assertTrue(self.user_form.is_valid())

    def _test_form_can_create_user(self):
        User.objects.create_user(
            username=self.user_form.cleaned_data['username'],
            first_name=self.user_form.cleaned_data['first_name'],
            last_name=self.user_form.cleaned_data['last_name'],
            email=self.user_form.cleaned_data['email'],
            password=self.user_form.cleaned_data['password'],
            is_active=False
        )
        self.assertEqual(User.objects.count(), 1)

    def _test_user_not_yet_activated(self):
        user = User.objects.get(username='******')
        self.assertFalse(user.is_active)

    def _test_activation_function_creates_activation_object(self):
        user = User.objects.get(username='******')
        init_activation(user)
        self.assertEqual(UserActivation.objects.count(), 1)

    def _test_activation_works(self):
        user = User.objects.get(username='******')
        user_activation = UserActivation.objects.get(user=user)
        activate(None, user_activation.activation_key)
        user = User.objects.get(username='******')
        self.assertTrue(user.is_active)

    def test_activation(self):
        self._test_form_is_valid()
        self.user_form.safe_data()
        self._test_form_can_create_user()
        self._test_user_not_yet_activated()
        self._test_activation_function_creates_activation_object()
        self._test_activation_works()
Exemplo n.º 7
0
 def setUp(self):
     User.objects.create_user(
         username='******',
         first_name='Alice',
         last_name='Seleznyova',
         email='*****@*****.**',
         password='******',
         is_active=False
     )
     self.user_form = UserForm(
         {'username': '******',
          'first_name': 'Alice',
          'last_name': 'Seleznyova',
          'email': '*****@*****.**',
          'password': '******',
          'confirm_password': '******'}
     )
Exemplo n.º 8
0
class BadUserRegistrationTestCase5(TestCase):
    def setUp(self):
        User.objects.create_user(
            username='******',
            first_name='Alice',
            last_name='Seleznyova',
            email='*****@*****.**',
            password='******',
            is_active=False
        )
        self.user_form = UserForm(
            {'username': '******',
             'first_name': 'Alice',
             'last_name': 'Seleznyova',
             'email': '*****@*****.**',
             'password': '******',
             'confirm_password': '******'}
        )
    
    def testReject(self):
        self.assertNotEqual(self.user_form.d2r_friendly_errors(),'')
        self.assertFalse(self.user_form.is_valid())