Exemplo n.º 1
0
    def save(self):
        """Create a new user and parent. Returns the new user."""
        data = self.cleaned_data
        password = data["password"]
        email = data["email"]
        first_name = data["first_name"]
        last_name = data["last_name"]
        phone_number = data["phone_number"]
        address = data["address"]
        address2 = data["address2"]
        city = data["city"]
        state = data["state"]
        zip_code = data["zip_code"]

        username = generate_id(first_name, last_name)

        # new_user = RegistrationProfile.objects.create_inactive_user(username, password, email, send_email=True)
        new_user = User.objects.create_user(username, email, password)

        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.save()
        # new_user.groups.add(2)

        if Parent.objects.filter(email=email).count() < 1:
            new_parent = Parent()
            new_household = Household()
            new_household.creation_date = date.today()
            new_household.save()
            new_parent.household = new_household
            new_parent.first_name = first_name
            new_parent.last_name = last_name
            new_parent.email = email
            new_parent.phone_number = phone_number
            new_parent.address = address
            new_parent.address2 = address2
            new_parent.city = city
            new_parent.state = state
            new_parent.zip_code = zip_code
            new_parent.user = new_user
            new_parent.save()
        else:
            new_parent = Parent.objects.get(email=email)
            new_parent.user = new_user
            new_parent.save()

        subject = "Seaturtle Swim School Online Registration"

        message = render_to_string("registration/new_account_confirmation.txt", {"email": email, "password": password})

        send_mail(subject, message, "*****@*****.**", [new_user.email])

        return new_user
Exemplo n.º 2
0
def parentresetpassword(request):
	if request.POST:
		email = request.POST['email']
		
		try:
			parent = Parent.objects.get(email=email)
			if parent.user is not None:
				user = parent.user
				new_pass = random_string(5)
				user.set_password(new_pass)
				user.email = parent.email
				user.save()
			
			else:
				first_name = parent.first_name
				last_name = parent.last_name
				username = generate_id(first_name, last_name)
				new_pass = random_string(5)
				new_user = User.objects.create_user(username, email, new_pass)
				new_user.first_name = first_name
				new_user.last_name = last_name
				new_user.save()
				user = new_user
				
				parent.user = user
				parent.save()

			
			subject2 = 'Password Reminder'
			message2 = render_to_string('email/password_reminder.txt',
									{ 'new_pass': new_pass })

			user.email_user(subject2, message2, settings.DEFAULT_FROM_EMAIL)
			messages.success(request, 'Your password has been reset and emailed to you.')
		
			return HttpResponseRedirect('/schedule/parentdashboard/')
			
		except:
			messages.error(request, 'A user account with that email address could not be found. Please call 1-855-888-SWIM')
			return redirect('/schedule/parentdashboard')
	else:
		return render_to_response('schedule/parent_reset_password.html', context_instance=RequestContext(request))