def add_user(request): form = UserProfileForm() user_formset = userProfileFormset(instance=RegistrationProfile()) if request.method == 'POST': form = UserProfileForm(request.POST) if form.is_valid(): #user_profile = form.save() data = form.cleaned_data site = Site.objects.get_current() new_user_instance = UserModel().objects.create_user( **form.cleaned_data) new_user = RegistrationProfile.objects.create_inactive_user( new_user=new_user_instance, site=site, send_email=False, request=request, ) #new_user = RegistrationProfile.objects.create_inactive_user(data['username'] , data['email'],data['password'], site) #signals.user_registered.send(sender=self.__class__, user=new_user,request=request) user_formset = userProfileFormset(request.POST, request.FILES, instance=new_user_instance) if user_formset.is_valid(): user_formset.save() return render(request, "userprofiles/registration_complete.html", {}) return render(request, "userprofiles/registration.html", { 'form': form, 'user_formset': user_formset, 'action': 'Create' })
def create_user_profile_signal(sender, instance, created, **kwargs): if created: r_user = RegistrationProfile(user=instance) #print r_user up = UserProfile(registration_profile=r_user) r_user.activation_key = RegistrationProfile.ACTIVATED r_user.save() up.save()
def test_activation_email(self): site = Site.objects.get() user = User(email='*****@*****.**') profile = RegistrationProfile(user=user, activation_key='activation-key') profile.send_activation_email(site) self.assertEqual(len(mail.outbox), 1) message = mail.outbox.pop() self.assertEqual(message.subject, 'Activate your djangoproject.com account') self.assertEqual( message.body, "\nSomeone, hopefully you, signed up for a new account at " "djangoproject.com using this email address. If it was you, and " "you'd like to activate and use your account, click the link below " "or copy and paste it into your web browser's address bar:\n\n" "https://www.djangoproject.com/accounts/activate/activation-key/\n\n" "If you didn't request this, you don't need to do anything; you " "won't receive any more email from us, and the account will expire " "automatically in three days.\n" )
def save(self, validated_data): email = validated_data.get('email') new_user = User( username=email, email=email, is_active=False, ) new_user.save() reg_profile = RegistrationProfile(user=new_user, code_type='RV') reg_profile.save() email = EmailMessage( subject='Discovery Email verification', body= f'Hi \n\nThis is your verification code for registering on Discovery: ' f'{reg_profile.code}\n\n' f'Please proceed with the sign-up process.\n\n' f'Your Discovery team', to=[f"{reg_profile.user.email}"], ) email.send() return new_user
def test_create_balafon_contact(self): user = self._create_user() RegistrationProfile(user=user, activation_key=RegistrationProfile.ACTIVATED) self._create_profile_and_check(user)