def initial_login(request): """ Initial login view shown when the user still needs to enter more details about thir account. """ if request.user.is_authenticated(): if request.method == 'POST': form = InitialLogin(request.user, request.POST) if form.is_valid(): new_password = form.cleaned_data['password1'] email = form.cleaned_data['email'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] request.user.set_password(new_password) request.user.email = email request.user.first_name = first_name request.user.last_name = last_name request.user.force_enterDetails = False # No longer force details to be entered request.user.save() return HttpResponseRedirect('/') else: form = InitialLogin(request.user) return render(request, 'initial_login.html', {'form': form}) else: return HttpResponseRedirect('login/')
def test_missing_new_password(self): form = InitialLogin(self.user, data={ 'first_name': FORENAME, 'last_name': SURNAME, 'email': EMAIL, 'old_password': PASSWORD, 'password2': "ValidPassword" }) self.assertFalse(form.is_valid())
def test_passwords_identical(self): form = InitialLogin(self.user, data={ 'first_name': FORENAME, 'last_name': SURNAME, 'email': EMAIL, 'old_password': PASSWORD, 'password1': PASSWORD, 'password2': PASSWORD }) self.assertFalse(form.is_valid())
def test_current_password_incorrect(self): form = InitialLogin(self.user, data={ 'first_name': FORENAME, 'last_name': SURNAME, 'email': EMAIL, 'old_password': PASSWORD, 'password1': "ValidPassword", 'password2': "ValidPassword" }) self.assertTrue(form.is_valid())
def test_empty_current_password(self): form = InitialLogin(self.user, data={ 'first_name': FORENAME, 'last_name': SURNAME, 'email': EMAIL, 'old_password': '', 'password1': "ValidPassword", 'password2': "ValidPassword" }) self.assertFalse(form.is_valid())
def test_valid(self): new_passsword = 'ValidPassword' form = InitialLogin(self.user, data={ 'first_name': FORENAME, 'last_name': SURNAME, 'email': EMAIL, 'old_password': PASSWORD, 'password1': new_passsword, 'password2': new_passsword }) self.assertTrue(form.is_valid())
def test_register_existing_email(self): new_passsword = 'adminadmin' form = InitialLogin(self.user, data={ 'first_name': FORENAME, 'last_name': SURNAME, 'email': "*****@*****.**", 'old_password': PASSWORD, 'password1': new_passsword, 'password2': new_passsword }) self.assertTrue(form.is_valid())