Пример #1
0
def register(request):
    if request.method == 'POST':
        form = UserRegisterForm(request.POST)

        if form.is_valid():
            email = form.cleaned_data.get('email')
            password1 = form.cleaned_data.get('pw1')
            password2 = form.cleaned_data.get('pw2')

            rm = RegisterManagement(email=email, pw1=password1, pw2=password2)
            message = rm.analyze()
            if message[0] == 'error':
                messages.error(request, message[1])
                form = UserRegisterForm(request.POST)
                return render(request, "registration.html", {'form': form})
            else:
                User.objects.create_user(username=email,
                                         email=email,
                                         password=password1)
                messages.success(request, message[1])
                form = UserLoginForm()
                return render(request, "login.html", {'form': form})
    else:
        form = UserRegisterForm()
        return render(request, "registration.html", {'form': form})
Пример #2
0
 def test_success(self):
     data = {'email': '*****@*****.**', 'pw1': 'testtest', 'pw2': 'testtest'}
     rm = RegisterManagement(email=data['email'],
                             pw1=data['pw1'],
                             pw2=data['pw2'])
     r = rm.analyze()
     self.assertEquals(r[0], 'success')
     self.assertEquals(r[1], "Compte créé ! Bienvenue " + data['email'])
Пример #3
0
 def test_no_email(self):
     data = {'email': '', 'pw1': 'testtest', 'pw2': 'testtest'}
     rm = RegisterManagement(email=data['email'],
                             pw1=data['pw1'],
                             pw2=data['pw2'])
     response = rm.analyze()
     self.assertEquals(response[0], 'error')
     self.assertEquals(response[1], "Email invalide")
Пример #4
0
 def test_password_too_short(self):
     data = {'email': '*****@*****.**', 'pw1': 'short', 'pw2': 'short'}
     rm = RegisterManagement(email=data['email'],
                             pw1=data['pw1'],
                             pw2=data['pw2'])
     response = rm.analyze()
     self.assertEquals(response[0], 'error')
     self.assertEquals(response[1], ("Ce mot de passe est trop court, il do"
                                     "it comporter au moins 6 caractères."))
Пример #5
0
 def test_email_already_used(self):
     User.objects.create_user(username='******',
                              email='*****@*****.**',
                              password='******')
     data = {'email': '*****@*****.**', 'pw1': 'testtest', 'pw2': 'testtest'}
     rm = RegisterManagement(email=data['email'],
                             pw1=data['pw1'],
                             pw2=data['pw2'])
     response = rm.analyze()
     self.assertEquals(response[0], 'error')
     self.assertEquals(response[1], 'Cet email est déjà utilisé')
Пример #6
0
 def test_passwords_not_matching(self):
     data = {
         'email': '*****@*****.**',
         'pw1': 'testtest',
         'pw2': 'wrongconfirm'
     }
     rm = RegisterManagement(email=data['email'],
                             pw1=data['pw1'],
                             pw2=data['pw2'])
     resp = rm.analyze()
     self.assertEquals(resp[0], 'error')
     self.assertEquals(resp[1], 'Les mots de passe ne correspondent pas')