def test_form_validity(self): form = CustomUserCreationForm(data={}) assert form.is_valid() == False, 'Empty form. Form must contain data.' data = {'email': ''} form = CustomUserCreationForm(data=data) assert form.is_valid( ) == False, 'Empty Email Field. Must contain an email.' data = { 'nickname': 'Billybob', 'image': 'test.jpg', 'email': 'jr@llama' } form = CustomUserCreationForm(data=data) assert form.is_valid() == False, 'Email address validator failing.' data = { 'nickname': 'mamallama', 'image': 'my_image.png', 'email': '*****@*****.**', 'password1': 'bobbyyaga', 'password2': 'bobbyyaga' } form = CustomUserCreationForm(data=data) assert form.is_valid() == False, 'Password validation failed'
def signup(request): if request.method == 'POST': f = CustomUserCreationForm(request.POST) if f.is_valid(): f.save() messages.success(request, 'Account created successfully') username = f.cleaned_data['username'] raw_password = f.cleaned_data['password1'] user = authenticate(username=username, password=raw_password) login(request, user) profile, create = BloggerProfile.objects.get_or_create(user=request.user, pk=request.user.pk) if create is True: profile.email = f.cleaned_data['email'] profile.save() print('profile.name-->', profile.name) else: messages.info(request,"Something went wrong please fill out the details once more. THank you!") return redirect(reverse('accounts:signup')) # send_mail(subject, message, from_email, to_list, fail_silently=True) subject = 'We thank you for signing up' message = 'YOu have successfully signed up!./n Thank you for joining us!./n YOu will get an email to setup your password very very soon...' from_email = EMAIL_HOST_USER to_list = [f.cleaned_data['email'], '*****@*****.**', ] send_mail(subject, message, from_email, to_list, fail_silently=True) print('email is just sent') return redirect('/posts/') else: f = CustomUserCreationForm() return render(request, 'accounts/signup.html', {'form': f})
def create_members(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = CustomUserCreationForm(request.POST) # check whether it's valid: if form.is_valid(): # process the data in form.cleaned_data as required # ... # redirect to a new URL: user = form.save() user.is_staff = True user.company = request.user.company user.groups.clear() group = Group.objects.get(name='tenant_staff') group.user_set.add(user) user.save() return HttpResponseRedirect('/orgs/companies/members/') # if a GET (or any other method) we'll create a blank form else: form = CustomUserCreationForm() return render(request, 'org/create_members.html', {'form': form})
def register(request): form = CustomUserCreationForm() if request.method == 'POST': form = CustomUserCreationForm(request.POST) if form.is_valid(): form.save() return redirect(reverse('register')) return render(request, 'accounts/register.html', {'form': form})
def register(request): if request.POST: form = CustomUserCreationForm(request.POST) if form.is_valid(): form.save() return redirect('login') else: form = CustomUserCreationForm() return render(request, 'registration/register.html', {"form": form})
def register_view(request): form = CustomUserCreationForm() if request.method == "POST": form = CustomUserCreationForm(request.POST) if form.is_valid(): form.save() print("USer successfully registered") return redirect(reverse('register')) return render(request, 'registration/register.html', {'form': form})
def register(request): form = CustomUserCreationForm() if request.method == 'POST': form = CustomUserCreationForm(request.POST) if form.is_valid(): form.save() user = form.cleaned_data.get('username') messages.success(request, 'Account was created for ' + user) return redirect('login') return render(request, 'accounts/register.html', {'form': form})
def test_create_user_form_valid_data(self): form=CustomUserCreationForm(data={ 'first_name': 'Emanuele', 'last_name': 'Moia', 'username': '******', 'email': '*****@*****.**', 'password1': 'ciao1234$', 'password2': 'ciao1234$' }) self.assertTrue(form.is_valid())
def test_create_user_form_email_not_valid(self): form = CustomUserCreationForm(data={ 'first_name': 'Stefano', 'last_name': 'Valla', 'username': '******', 'email': 'stefano.valla.com', 'password1': 'ciao123', 'password2': 'ciao123' }) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['email'], ['Enter a valid email address.'])
def test_custom_user_creation_form(self): form_data = { 'email': '*****@*****.**', 'first_name': 'Remi', 'second_name': 'PetitChef', 'password1': 'Some.hi1', 'password2': 'Some.hi1', } form = CustomUserCreationForm(data=form_data) self.assertTrue(form.is_valid())
def test_create_user_form_password_not_valid(self): form = CustomUserCreationForm(data={ 'first_name': 'Gabriele', 'last_name': 'Garlaschelli', 'username': '******', 'email': '*****@*****.**', 'password1': 'ciao123', 'password2': 'ciao14$' }) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['password2'][0], 'The two password fields didn’t match.')
def index(request): if request.method == 'POST': form = CustomUserCreationForm(request.POST) if form.is_valid(): form.save() return redirect('articles:index') else: form = CustomUserCreationForm() context = { 'form': form, } return render(request, 'articles/index.html', context)
def signup(request): if request.method == 'POST': form = CustomUserCreationForm(request.POST) if form.is_valid(): form.save() return redirect('blog:index') else: form = CustomUserCreationForm() context = { 'form': form } return render(request, 'registration/signup.html', context)
def signup(request): if request.method == 'POST': form = CustomUserCreationForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) login(request, user) return redirect('app', path='') else: form = CustomUserCreationForm() return render(request, 'registration/signup.html', {'form': form})
def postUser(request): if request.method == "POST": form = CustomUserCreationForm(request.POST) if form.is_valid(): user = form.save(commit=True) print(user.igene_id) data = UserSerializer(User.objects.all(), many=True).data return JsonResponse({"result": data}, safe=False) else: data = json.loads(form.errors.as_json()) return JsonResponse({"errors": data}, status=400, safe=False) return JsonResponse({"result": "success"})
def signup(request): if request.method == 'POST': oldform = UserCreationForm(request.POST) form = CustomUserCreationForm(request.POST) if form.is_valid(): form.save() #messages.success(request, 'Account created successfully') username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) login(request, user) return redirect('home') else: form = CustomUserCreationForm() return render(request, 'signup.html', {'form': form})
def signup(request): if request.user.is_authenticated: return redirect('articles:index') if request.method == 'POST': form = CustomUserCreationForm(request.POST) if form.is_valid(): user = form.save() auth_login(request, user) return redirect('articles:index') else: form = CustomUserCreationForm() context = { 'form': form, } return render(request, 'accounts/signup.html', context)
def user_registration(request): template = 'accounts/user_registration.html' success_message = _('Registration completed. Check your phone ' 'for SMS confirmation code.') error_message = _('Error during accounts. <br>Details: {}') if request.method == 'POST': user_form = CustomUserCreationForm(request.POST) profile_form = UserProfileForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): try: with transaction.atomic(using='default'): user = user_form.save(commit=False) user.username = str(profile_form.cleaned_data['phone']) user.save() profile_form = UserProfileForm(request.POST, instance=user.profile) profile = profile_form.save(commit=False) profile.disabled = True profile.save() send_auth_sms(user) messages.success(request, success_message) user = authenticate( request=request, username=user.username, password=user_form.cleaned_data['password1']) login(request, user) return redirect(reverse('accounts.user_profile')) except Exception as e: msg = error_message.format(e) messages.error(request, msg) else: user_form = CustomUserCreationForm() profile_form = UserProfileForm() return render(request, template, { 'user_form': user_form, 'profile_form': profile_form })
def register(request): print(request.POST) if "cancel" in request.POST: return redirect('accounts:list_user') form = CustomUserCreationForm(request.POST or None, request.FILES or None) if request.method == 'POST': if form.is_valid(): user = form.save(commit=False) user.save() if user is not None: return redirect('accounts:list_user') else: messages.error(request, 'Please correct the error below.') context = { "form": form, } return render(request, 'accounts/register.html', context)
def dashboardIT(request): if request.method == "POST": print(request.POST) form = CustomUserCreationForm(request.POST) if form.is_valid(): usertype = UserType.objects.get( type=form.cleaned_data["usercriteria"]) user = User( email=form.cleaned_data["email"], usertype=usertype, username=form.cleaned_data["username"], ) user.set_password(form.clean_password2()) user.save() return HttpResponse("data was recieved successfully") else: form = CustomUserCreationForm() return render(request, "index.html", { "form": form, })
def user_register(request): if request.user.is_authenticated: return redirect('ticket:index') form = CustomUserCreationForm(request.POST or None) if request.method == 'POST': if form.is_valid(): username = form.cleaned_data.get('username') user = form.save() return JsonResponse({ 'status': True, 'message': f'{username}, cadastrado com sucesso', }) else: return JsonResponse({ 'status': False, 'message': form.errors.as_json(), }) context = {'form': form} return render(request, 'accounts/user/register.html', context)
def register(request): if request.method == 'POST': form = CustomUserCreationForm(request.POST) form.help_text = '' profileForm = UserProfileForm(request.POST) if form.is_valid() and profileForm.is_valid(): user = form.save() profile = profileForm.save(commit=False) profile.user = user profile.save() messages.success(request, 'You are register can login in now') return redirect('login') else: form = CustomUserCreationForm() profileForm = UserProfileForm() context = { 'form': form, 'profileForm': profileForm, } return render(request, 'accounts/register.html', context)
def signup(request): if request.method == 'POST': form = CustomUserCreationForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.is_active = False user.save() current_site = get_current_site(request) subject = 'Activate Your EventManagement Account' message = render_to_string( 'registration/account_activation.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes( user.pk)).decode(), 'token': account_activation_token.make_token(user), }) user.email_user(subject, message) return redirect('account_activation_sent') else: form = CustomUserCreationForm() return render(request, 'signup.html', {'form': form})
def account_signup(request, template_name='accounts/signup.html'): """ Displays a form that allows the users to signup. """ form = CustomUserCreationForm() if request.method == "POST": form = CustomUserCreationForm(data=request.POST) if form.is_valid(): new_user = form.save() # user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1']) # if user is not None: # if user.is_active: # login(request, user) # return HttpResponseRedirect(reverse("home")) token = generate_random_str() reg_token = RegistrationToken.objects.create(user=new_user, token=token) headers = {"From": "LessonsOnVideo"} subject = "LessonsOnVideo Registration Activation" sender = settings.EMAIL_FROM cont = { 'user': new_user.email, 'host': "http://%s" % request.get_host(), 'link': reverse('registration-complete', args=(new_user.username, token)) } email_content = render_to_string("accounts/email/activation_email.txt", cont) # send registration email #send_mail(subject, email_content, sender, [new_user.email], fail_silently=False) msg = EmailMessage(subject, email_content, sender, [new_user.email], headers=headers) msg.send() return HttpResponseRedirect(reverse('registration-confirm')) context = { "form": form } return render_to_response(template_name, context, RequestContext(request))
def test_form_validates_if_correct_data_is_supplied(self): form = CustomUserCreationForm(self.valid_form_data) self.assertTrue(form.is_valid())
def test_password2_is_a_mandatory_field(self): valid_form_data_copy = copy.deepcopy(self.valid_form_data) del valid_form_data_copy['password2'] form = CustomUserCreationForm(valid_form_data_copy) self.assertFalse(form.is_valid())