def save(self, commit=True): super(RefereeRegistrationForm, self).save(commit=False) referee = Referee.objects.create_referee(**prep_dict( **self.cleaned_data)) if commit: referee.save() send_activation_email(referee.user) return referee
def save(self, commit=True): super(AthleteRegisterForm, self).save(commit=False) athlete = Athlete.objects.create_athlete( **prep_dict(**self.cleaned_data) ) if commit: athlete.save() send_activation_email(athlete.user) return athlete
def register(request): if request.user.is_authenticated(): return HttpResponseRedirect(reverse('home')) if request.method == 'POST': registration_form = RegistrationForm(request.POST) try: if registration_form.is_valid(): user = registration_form.save(commit=False) user.is_active = False user.save() user.idp_uuid = idp_interface.create_user( user=user, password=registration_form.cleaned_data.get('password1')) user.save() activation_key = utils.generate_activation_key(user.email) activation = Activation(user=user, activation_key=activation_key) activation.save() utils.send_activation_email(user, activation_key) return render(request, 'profiles/registration_complete.html', {'email': user.email}) except Exception as e: logger.exception(e) return render( request, 'error.html', { 'error': 'Registration Failed', 'description': 'Something went wrong.', }) else: registration_form = RegistrationForm() return render(request, 'profiles/register.html', { 'page_type': 'register', 'registration_form': registration_form })
def test_send_activation_email(self): print('send_activation_email') self.delete_user_instance(self.email) user = User.objects.create_user(**self.data['user']) self.assertFalse(user.is_active and user.key) self.assertEqual(send_activation_email(user), 'localhost:8000/activate/' + user.key + '/')
def send_activation_email(user_id): user = UserProfile.objects.get(id=user_id) idp_uuid = idp_interface.create_user(user) if 'user_exist' in idp_uuid: if idp_uuid.get('user_exist'): user.is_active = True user.idp_uuid = idp_uuid.get('uuid') user.save() utils.send_duplicate_account_notification(user) else: user.idp_uuid = idp_uuid activation_key = utils.generate_activation_key(user.email) activation = Activation(activation_key=activation_key, user=user) activation.save() utils.send_activation_email(user, activation_key) user.save()
def handle(self, *args, **options): try: users = Registration.objects.filter(status='initial')[:1] if users: for usr in users: usr.status = 'processing' usr.save() user = UserProfile.objects.get(id=usr.user_id) user.idp_uuid = idp_interface.create_user(user) user.save() activation_key = utils.generate_activation_key(user.email) activation = Activation(user=user, activation_key=activation_key) activation.save() utils.send_activation_email(user, activation_key) usr.status = 'pending' usr.save() print "Activation email sent at {0}".format(user.email) else: print "No record found" except Exception as e: print e