def signup(request): if request.user.is_authenticated(): if not request.user.needs_update: return redirect('user_profile', username=request.user.username) if request.method == 'GET': user_form = ColabSetUsernameForm() lists_form = ListsForm() return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) user_form = ColabSetUsernameForm(request.POST) lists_form = ListsForm(request.POST) user_email = user_form.data.get('email', '') existent_user = User.objects.filter(email=user_email).first() if existent_user and existent_user.is_active is False: message = _("This user already exists, but is not active. \ Please check your spam or <a href='/account/resend-email-verification/'> \ resend an email</a>") messages.info(request, message) if not user_form.is_valid() or not lists_form.is_valid(): return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) user = user_form.save(commit=False) user.needs_update = False user.is_active = False user.save() email = EmailAddressValidation.create(user.email, user) location = reverse('archive_email_view', kwargs={'key': email.validation_key}) verification_url = request.build_absolute_uri(location) EmailAddressValidation.verify_email(email, verification_url) # Check if the user's email have been used previously # in the mainling lists to link the user to old messages email_addr, created = EmailAddress.objects.get_or_create( address=user.email) if created: email_addr.real_name = user.get_full_name() email_addr.user = user email_addr.save() mailing_lists = lists_form.cleaned_data.get('lists') mailman.update_subscription(user.email, mailing_lists) messages.success(request, _('Your profile has been created!')) messages.warning(request, _("Please verify your inbox or spam" " and activate your account.")) return redirect('user_profile', username=user.username)
def signup(request): if request.user.is_authenticated(): if not request.user.needs_update: return redirect('user_profile', username=request.user.username) if request.method == 'GET': user_form = ColabSetUsernameForm() lists_form = ListsForm() return render(request, 'accounts/user_create_form.html', { 'user_form': user_form, 'lists_form': lists_form }) user_form = ColabSetUsernameForm(request.POST) lists_form = ListsForm(request.POST) if not user_form.is_valid() or not lists_form.is_valid(): return render(request, 'accounts/user_create_form.html', { 'user_form': user_form, 'lists_form': lists_form }) user = user_form.save(commit=False) user.needs_update = False user.is_active = False user.save() email = EmailAddressValidation.create(user.email, user) location = reverse('archive_email_view', kwargs={'key': email.validation_key}) verification_url = request.build_absolute_uri(location) EmailAddressValidation.verify_email(email, verification_url) # Check if the user's email have been used previously # in the mainling lists to link the user to old messages email_addr, created = EmailAddress.objects.get_or_create( address=user.email) if created: email_addr.real_name = user.get_full_name() email_addr.user = user email_addr.save() mailing_lists = lists_form.cleaned_data.get('lists') mailman.update_subscription(user.email, mailing_lists) messages.success(request, _('Your profile has been created!')) return redirect('user_profile', username=user.username)
def test_send_verification_email_successfuly(self, mock_send_verification_email): user = User.objects.get(username="******") EmailAddressValidation.create(user.email, user) email_addr, created = EmailAddress.objects.get_or_create(address=user.email) email_addr.user = user email_addr.save() self.authenticate_user() response = self.client.post("/archives/manage/email/validate/", {"user": user.id, "email": user.email}) self.assertEqual(response.status_code, 204) self.assertTrue(mock_send_verification_email.called)
def signup(request): if request.user.is_authenticated(): if not request.user.needs_update: return redirect('user_profile', username=request.user.username) if request.method == 'GET': user_form = UserCreationForm() lists_form = ListsForm() return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) user_form = UserCreationForm(request.POST) lists_form = ListsForm(request.POST) if not user_form.is_valid() or not lists_form.is_valid(): return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) user = user_form.save(commit=False) user.needs_update = False user.is_active = False user.save() email = EmailAddressValidation.create(user.email, user) location = reverse('archive_email_view', kwargs={'key': email.validation_key}) verification_url = request.build_absolute_uri(location) EmailAddressValidation.verify_email(email, verification_url) # Check if the user's email have been used previously # in the mainling lists to link the user to old messages email_addr, created = EmailAddress.objects.get_or_create( address=user.email) if created: email_addr.real_name = user.get_full_name() email_addr.user = user email_addr.save() mailing_lists = lists_form.cleaned_data.get('lists') mailman.update_subscription(user.email, mailing_lists) messages.success(request, _('Your profile has been created!')) return redirect('user_profile', username=user.username)
def resend_email_verification(request): if request.method == 'GET': return render(request, 'registration/resend_email_verification.html') email = request.POST.get('email', '') user = User.objects.filter(email=email).first() if not user: msg = _('This emails is not registered yet.') messages.error(request, msg) return render(request, 'registration/resend_email_verification.html') email = EmailAddressValidation.objects.get_or_create(address=email, user_id=user.id)[0] location = reverse('archive_email_view', kwargs={'key': email.validation_key}) verification_url = request.build_absolute_uri(location) if EmailAddressValidation.verify_email(email, verification_url): msg = _('An email was sent to you. Verify your inbox or spam.') messages.success(request, msg) else: msg = _('An error occurred while sending mail.') messages.error(request, msg) return redirect('login')
def test_send_verification_email_successfuly(self, mock_send_verification_email): user = User.objects.get(username='******') EmailAddressValidation.create(user.email, user) email_addr, created = EmailAddress.objects.get_or_create( address=user.email) email_addr.user = user email_addr.save() self.authenticate_user() response = self.client.post('/archives/manage/email/validate/', { 'user': user.id, 'email': user.email }) self.assertEqual(response.status_code, 204) self.assertTrue(mock_send_verification_email.called)
def signup(request): BROWSERID_ENABLED = getattr(settings, 'BROWSERID_ENABLED', False) if BROWSERID_ENABLED: # If the user is not authenticated, redirect to login if not request.user.is_authenticated(): return redirect('login') if request.user.is_authenticated(): # If the user doesn't need to update its main data, # redirect to its profile # It happens when user is created by browserid # and didn't set his/her main data if not request.user.needs_update: return redirect('user_profile', username=request.user.username) # If the user is authenticated in Persona, but not in the Colab then he # will be redirected to the register form. if request.method == 'GET': if BROWSERID_ENABLED: user_form = UserForm() else: user_form = UserCreationForm() lists_form = ListsForm() return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) if BROWSERID_ENABLED: user_form = UserForm(request.POST, instance=request.user) else: user_form = UserCreationForm(request.POST) lists_form = ListsForm(request.POST) if not user_form.is_valid() or not lists_form.is_valid(): return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) user = user_form.save(commit=False) user.needs_update = False if not BROWSERID_ENABLED: user.is_active = False user.save() EmailAddressValidation.create(user.email, user) else: user.save() # Check if the user's email have been used previously # in the mainling lists to link the user to old messages email_addr, created = EmailAddress.objects.get_or_create( address=user.email) if created: email_addr.real_name = user.get_full_name() email_addr.user = user email_addr.save() mailing_lists = lists_form.cleaned_data.get('lists') mailman.update_subscription(user.email, mailing_lists) messages.success(request, _('Your profile has been created!')) return redirect('user_profile', username=user.username)