def test_signup_email_twice(self): request = RequestFactory().post( reverse('account_signup'), { 'username': '******', 'email': '*****@*****.**', 'email2': '*****@*****.**', 'password1': 'johndoe', 'password2': 'johndoe', 'country_id': 1, 'country_name': 'new country', 'city_id': 1, 'city_name': 'new city', 'university_id': 1, 'university_name': 'new university', 'phone': '+78005003020' }) from django.contrib.messages.middleware import MessageMiddleware from django.contrib.sessions.middleware import SessionMiddleware SessionMiddleware().process_request(request) MessageMiddleware().process_request(request) request.user = AnonymousUser() from allauth.account.views import signup signup(request) user = get_user_model().objects.get(username='******') self.assertEqual(user.email, '*****@*****.**')
def signup_wrapper(request, *args, **kwargs): from allauth.account.views import signup ret = signup(request, *args, **kwargs) # Log signup attempts. if request.method == "POST": import django.http.response import django.template.response result = "?" if isinstance(ret, django.template.response.TemplateResponse): try: result = "error:" + repr(ret.context_data['form'].errors) except: result = "error:" + type(ret) elif isinstance(ret, django.http.response.HttpResponseRedirect): result = "success" import logging logger = logging.getLogger(__name__) logger.error( "signup ip={ip} username={username} result={result}".format( ip=request.META.get("REMOTE_ADDR"), username=request.POST.get("username"), result=result)) return ret
def _test_signup_email_verified_externally(self, signup_email, verified_email): username = '******' request = RequestFactory().post( reverse('account_signup'), { 'username': username, 'email': signup_email, 'password1': 'johndoe', 'password2': 'johndoe', 'country_id': 1, 'country_name': 'new country', 'city_id': 1, 'city_name': 'new city', 'university_id': 1, 'university_name': 'new university', 'phone': '+78005003020' }) # Fake stash_verified_email from django.contrib.messages.middleware import MessageMiddleware from django.contrib.sessions.middleware import SessionMiddleware SessionMiddleware().process_request(request) MessageMiddleware().process_request(request) request.user = AnonymousUser() request.session['account_verified_email'] = verified_email from allauth.account.views import signup from allauth.account.adapter import get_adapter resp = signup(request) self.assertEqual(resp.status_code, 302) self.assertEqual(resp['location'], get_adapter().get_login_redirect_url(request)) self.assertEqual(len(mail.outbox), 0) return get_user_model().objects.get(username=username)
def _test_signup_email_verified_externally(self, signup_email, verified_email): username = '******' request = RequestFactory().post( reverse('account_signup'), { 'username': username, 'email': signup_email, 'password1': 'johndoe', 'password2': 'johndoe' }) # Fake stash_verified_email from django.contrib.messages.middleware import MessageMiddleware from django.contrib.sessions.middleware import SessionMiddleware SessionMiddleware().process_request(request) MessageMiddleware().process_request(request) request.user = AnonymousUser() request.session['account_verified_email'] = verified_email from allauth.account.views import signup resp = signup(request) self.assertEqual(resp.status_code, 302) self.assertEqual(resp['location'], get_adapter().get_login_redirect_url(request)) self.assertEqual(len(mail.outbox), 0) user = get_user_model().objects.get(username=username) braintree.Customer.delete(user.usermerchantid.customer_id) return user
def signup(request): """return the django.contrib.auth or the django-allauth login view""" if settings.USE_ALL_AUTH: # noinspection PyPackageRequirements from allauth.account.views import signup return signup(request) return SignupView.as_view()(request)
def signup(request): if request.method == "GET": user = request.user if user.is_authenticated: return redirect(reverse("index")) template = "results_base.min.html" results = get_signup_results() context = { "results": results, } if request.is_ajax(): return render(request, template, context) return render_non_ajax(request, template, context) if request.method == "POST": template = "results_base.min.html" try: ajax = request.META["HTTP_X_REQUESTED_WITH"] except KeyError: ajax = None request.META["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" response = allauth.signup(request) request.META["HTTP_X_REQUESTED_WITH"] = ajax context = {} if response.status_code == 200: context.update({ "message": "We have sent a confirmation link to your email address. Please contact us if you do not receive it within a few minutes." }) results = get_login_results() context.update({ "results": results, }) return render(request, template, context) results = get_signup_results() context.update({ "results": results, }) context = get_form_errors(context, response) if request.is_ajax(): return render(request, template, context, status=400) return render_non_ajax(request, template, context) raise Http404()