Esempio n. 1
0
def register(request):	
	registered = False
	if request.method == "POST":
		user_form = UserForm(data=request.POST)
		profile_form = UserProfileForm(data=request.POST)
		print profile_form
		print request.FILES['picture']
		if user_form.is_valid() and profile_form.is_valid():
			
			user = user_form.save(commit=False)
			user.set_password(user.password)
			user.is_active=True
			user.save()
			profile = profile_form.save(commit=False)
			profile.user = user
			profile.lastLoginDate = datetime.now()
			profile.ipaddress=get_client_ip(request)
			if request.FILES['picture']:
				profile.picture = request.FILES['picture']
			profile.save()
			registered = True
		else:
			print user_form.errors, profile_form.errors
			messages.info(request,str(user_form.errors)+str(profile_form.errors))
	else:
		user_form = UserForm()
		profile_form = UserProfileForm()
	return render(request,'register.html',{'title':'Sign Up','current_page':'register',\
		'user_form':user_form,'profile_form':profile_form,'registered':registered})
Esempio n. 2
0
def registerM(request):
    context = RequestContext(request)

    registered = False

    if request.POST:
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]
            profile.save()

            registered = True
        else:
            user_form = UserForm()
            profile_form = UserProfileForm()
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render_to_response(
        "registr.html", {"user_form": user_form, "profile_form": profile_form, "registered": registered}, context
    )
Esempio n. 3
0
 def save(self, commit=True):
     if not self.campaign.is_free:
         is_success, code, text = self.payment_processor.result
         if not is_success:
             raise PaymentError(
                 _('There was a system error in processing your payment.'))
         amount = D(
             self.payment_processor.transaction_data.payment.total_amount)
     else:
         amount = 0
     UserProfileForm.save(self, commit=commit)
     if not self.campaign.is_free:
         tx_id = self.payment_processor.transaction_data.payment.invoice_num
     else:
         tx_id = make_invoice_num(self.campaign, self.user_profile.user)
     c = Contribution(campaign=self.campaign,
                      contributor=self.user_profile.user,
                      amount=amount,
                      qty=self.qty,
                      paid_on=datetime.now(),
                      payment_mode='direct',
                      transaction_id=tx_id)
     if commit:
         c.save()
     return c
Esempio n. 4
0
def register(request):
    # Like before, get the request's context.
    #context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            userid = request.POST['userid']
            print userid
            user = user_form.save()
            user.username = userid
            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.mode = random.randint(0,1)

            # Now we save the UserProfile model instance.
            profile.save()
            id_holder = Id.objects.get(userid=userid)
            id_holder.usedFlag = True
            id_holder.save()
            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render_to_response(
            'registration.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context_instance=RequestContext(request)
            )
Esempio n. 5
0
def register(request):
    context = RequestContext(request)
    registered = False

    if request.POST:
        form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if form.is_valid() and profile_form.is_valid():
            user = form.save()
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user          
            profile.save()
            registered = True
        else:
            form.errors, profile_form.errors

    else:
        form = UserForm()
        profile_form = UserProfileForm()

    return render_to_response('registration/register.html',{'form':form,'profile_form':profile_form,'registered':registered},context)
Esempio n. 6
0
 def save(self, commit=True):
     UserProfileForm.save(self, commit=commit)
     if self.event.attendee_set.filter(attendee_profile=self.user_profile).count():
         return None
     a = Attendee(event=self.event, attendee_profile=self.user_profile, qty=1, added_on=datetime.now())
     a.already_registered = False
     if commit:
         a.save()
     return a
Esempio n. 7
0
 def __init__(self, event, user_profile, *args, **kwargs):
     self.event = event
     self.user_profile = user_profile
     show_fields = ["name"]  # Name is always required
     if event.min_age:
         show_fields.append("birth_date")
     UserProfileForm.__init__(
         self, instance=user_profile, show_fields=show_fields, optional_fields=[], *args, **kwargs
     )
     _AgeValidatorFormBase.__init__(self, int(self.event.min_age))
Esempio n. 8
0
    def test_missing_designation(self):
        form_instance = UserProfileForm(
            data={
                "user": "******",
                "phone_number": 9999999999,
                "institute": "Sample institute",
            })

        self.assertEqual(form_instance.is_valid(), False)
        self.assertNotEqual(form_instance.errors.get("designation"), None)
Esempio n. 9
0
 def save(self, commit=True):
     """Leave contributions pending until we later receive notifications for them."""
     UserProfileForm.save(self, commit=commit)
     c = PendingContribution(campaign=self.campaign,
                      contributor=self.user_profile.user,
                      amount=self.campaign.contribution_amount * self.qty,
                      qty=self.qty,
                      paid_on=datetime.now(),
                      payment_mode=self.payment_mode)
     if (commit):
         c.save()
     return c
Esempio n. 10
0
 def save(self, commit=True):
     """Leave contributions pending until we later receive notifications for them."""
     UserProfileForm.save(self, commit=commit)
     c = PendingContribution(campaign=self.campaign,
                             contributor=self.user_profile.user,
                             amount=self.campaign.contribution_amount *
                             self.qty,
                             qty=self.qty,
                             paid_on=datetime.now(),
                             payment_mode=self.payment_mode)
     if (commit):
         c.save()
     return c
Esempio n. 11
0
 def __init__(self, event, user_profile, *args, **kwargs):
     self.event = event
     self.user_profile = user_profile
     show_fields = ['name']  # Name is always required
     if event.min_age:
         show_fields.append('birth_date')
     UserProfileForm.__init__(self,
                              instance=user_profile,
                              show_fields=show_fields,
                              optional_fields=[],
                              *args,
                              **kwargs)
     _AgeValidatorFormBase.__init__(self, int(self.event.min_age))
Esempio n. 12
0
 def save(self, commit=True):
     UserProfileForm.save(self, commit=commit)
     if self.event.attendee_set.filter(
             attendee_profile=self.user_profile).count():
         return None
     a = Attendee(event=self.event,
                  attendee_profile=self.user_profile,
                  qty=1,
                  added_on=datetime.now())
     a.already_registered = False
     if commit:
         a.save()
     return a
Esempio n. 13
0
def register(request):

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the the form is valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            profile.save()
            # Update our variable to tell the template registration was successful.
            registered = True

            new_user = authenticate(
                username=user_form.cleaned_data['username'],
                password=user_form.cleaned_data['password'],
            )
            login(request, new_user)

            return HttpResponseRedirect('/')

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()

    # Render the template depending on the context.
    return render(request, 'registration/register.html', {})
Esempio n. 14
0
 def __init__(self, campaign, user_profile, *args, **kwargs):
     self.campaign = campaign
     self.user_profile = user_profile
     show_fields = ['name'] # Name is always required
     if campaign.min_age:
         show_fields.append('birth_date')
     if campaign.address_required:
         show_fields.append('address')
     if campaign.phone_required:
         show_fields.append('phone_number')
     UserProfileForm.__init__(self, instance=user_profile, show_fields=show_fields, optional_fields=[], *args, **kwargs)
     _AgeValidatorFormBase.__init__(self, int(self.campaign.min_age))
     if user_profile.user.first_name and user_profile.user.last_name:
         self.fields['first_name'].widget = forms.HiddenInput()
         self.fields['last_name'].widget = forms.HiddenInput()
     try:
         del self.fields['has_opted_in']
     except KeyError:
         pass
Esempio n. 15
0
    def clean(self):
        super(DirectContributionForm, self).clean()
        if not self._errors and not self.campaign.is_free:
            #
            # ---- IMPORTANT -----
            #
            # Ideally, we would verify the CC here and post the transaction
            # later in save(). However, there isn't an efficient way to merely
            # verify a credit card without actually posting the CC transaction; 
            # All that the ``CreditCardField`` validates that the CC number 
            # abides by the Luhn-checksum but this could still not be a 
            # legitimately issued CC number.
            #
            # Therefore, post the transaction here and produce validation errors 
            # based on what the transaction processor returns.
            #
            # The end result is that if this method succeeds, the transaction has 
            # already been posted.
            #

            # Save ``UserProfile`` and ``User`` fields to the database
            # because ``TransactionData`` needs to extract the payer's
            # name and address from the user instance.
            UserProfileForm.save(self, commit=True)
            data = TransactionData()
            data.user = self.user_profile.user
            payment = Payment()
            data.payment = payment
            payment.invoice_num = make_invoice_num(self.campaign, data.user)
            payment.total_amount = '%s' % self.campaign.contribution_amount * self.qty
            payment.cc_num = self.cleaned_data['cc_num']
            payment.expiration_date = self.cleaned_data['expiration_date']
            payment.ccv = self.cleaned_data['ccv']
            self.payment_processor = PaymentProcessor()
            extra = dict(x_description=self.campaign.title)
            self.payment_processor.prepare_data(data, extra_dict=extra)
            is_success, code, text = self.payment_processor.process()
            if not is_success:
                raise forms.ValidationError(escape(text))
        return self.cleaned_data
Esempio n. 16
0
    def clean(self):
        super(DirectContributionForm, self).clean()
        if not self._errors and not self.campaign.is_free:
            #
            # ---- IMPORTANT -----
            #
            # Ideally, we would verify the CC here and post the transaction
            # later in save(). However, there isn't an efficient way to merely
            # verify a credit card without actually posting the CC transaction;
            # All that the ``CreditCardField`` validates that the CC number
            # abides by the Luhn-checksum but this could still not be a
            # legitimately issued CC number.
            #
            # Therefore, post the transaction here and produce validation errors
            # based on what the transaction processor returns.
            #
            # The end result is that if this method succeeds, the transaction has
            # already been posted.
            #

            # Save ``UserProfile`` and ``User`` fields to the database
            # because ``TransactionData`` needs to extract the payer's
            # name and address from the user instance.
            UserProfileForm.save(self, commit=True)
            data = TransactionData()
            data.user = self.user_profile.user
            payment = Payment()
            data.payment = payment
            payment.invoice_num = make_invoice_num(self.campaign, data.user)
            payment.total_amount = '%s' % self.campaign.contribution_amount * self.qty
            payment.cc_num = self.cleaned_data['cc_num']
            payment.expiration_date = self.cleaned_data['expiration_date']
            payment.ccv = self.cleaned_data['ccv']
            self.payment_processor = PaymentProcessor()
            extra = dict(x_description=self.campaign.title)
            self.payment_processor.prepare_data(data, extra_dict=extra)
            is_success, code, text = self.payment_processor.process()
            if not is_success:
                raise forms.ValidationError(escape(text))
        return self.cleaned_data
Esempio n. 17
0
def register(request):
    if request.method == 'POST':
        print '*'*100
    	print request.POST
        uform = UserCreationForm(request.POST)
        upform= UserProfileForm(request.POST)
        if uform.is_valid() and upform.is_valid():
            user = uform.save()
            account_type = request.POST.get("account_type")
            institution_id = request.POST.get("institution")
            institution = Institution.objects.get(id=institution_id)
            userprofile = UserProfile.objects.create(user=user,account_type=account_type,institution=institution)

        	#userprofile = upform.save()
        	# userprofile.user =user
            print '*'*100
        	# print userprofile.__dict__
            print '#'*100
            print user.__dict__
            print '?'*100
        	#userprofile.save()

            # account_type = request.POST.get('account_type')
            # institution_id = request.POST.get('institution')
            # institution = Institution.objects.get(id=institution_id)
            
            # UserProfile.objects.create(user=user,account_type=account_type, institution=institution)
            return HttpResponseRedirect("/")
        else:
        	print uform.errors
        	print upform.errors

    else:
        uform = UserCreationForm()
        upform = UserProfileForm()
    return render(request, "registration/register.html", {
        'uform': uform, 'upform':upform
    })
Esempio n. 18
0
    def test_all_details_submitted(self):
        form_instance = UserProfileForm(instance=self.user.userprofile,
                                        data={
                                            "user": self.user.id,
                                            "phone_number": "9999999999",
                                            "institute": self.name.id,
                                            "designation": "STU",
                                        })

        if not form_instance.is_valid():
            print(form_instance.errors)
        self.assertEqual(form_instance.is_valid(), True)

        register = form_instance.save(commit=False)

        register.save()

        model_instance = UserProfile.objects.get(user="******")

        self.assertEqual(model_instance.user, "Sample User")
        self.assertEqual(model_instance.phone_number, 9999999999)
        self.assertEqual(model_instance.institute, self.name)
        self.assertEqual(model_instance.designation, "STU")
Esempio n. 19
0
 def save(self, commit=True):
     if not self.campaign.is_free:
         is_success, code, text = self.payment_processor.result
         if not is_success:
             raise PaymentError(_('There was a system error in processing your payment.'))
         amount = D(self.payment_processor.transaction_data.payment.total_amount)
     else:
         amount = 0
     UserProfileForm.save(self, commit=commit)
     if not self.campaign.is_free:
         tx_id = self.payment_processor.transaction_data.payment.invoice_num
     else:
         tx_id = make_invoice_num(self.campaign, self.user_profile.user)
     c = Contribution(campaign=self.campaign,
                      contributor=self.user_profile.user,
                      amount=amount,
                      qty=self.qty,
                      paid_on=datetime.now(),
                      payment_mode='direct',
                      transaction_id=tx_id)
     if commit:
         c.save()
     return c
Esempio n. 20
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     data = {}
     photo_url = None
     if self.request.user.is_authenticated:
         data['login'] = self.request.user.username
         data['email'] = self.request.user.email
         profile = UserProfile.objects.filter(user=self.request.user)
         if profile is not None:
             photo_url = profile[0].photo.url
     context['form'] = UserProfileForm(initial=data)
     context['photo_url'] = photo_url
     context['trends'] = Questions.get_trends()
     return context
Esempio n. 21
0
 def __init__(self, campaign, user_profile, *args, **kwargs):
     self.campaign = campaign
     self.user_profile = user_profile
     show_fields = ['name']  # Name is always required
     if campaign.min_age:
         show_fields.append('birth_date')
     if campaign.address_required:
         show_fields.append('address')
     if campaign.phone_required:
         show_fields.append('phone_number')
     UserProfileForm.__init__(self,
                              instance=user_profile,
                              show_fields=show_fields,
                              optional_fields=[],
                              *args,
                              **kwargs)
     _AgeValidatorFormBase.__init__(self, int(self.campaign.min_age))
     if user_profile.user.first_name and user_profile.user.last_name:
         self.fields['first_name'].widget = forms.HiddenInput()
         self.fields['last_name'].widget = forms.HiddenInput()
     try:
         del self.fields['has_opted_in']
     except KeyError:
         pass
Esempio n. 22
0
def register(request):
    registered = False  #will be set true when the registration is successful
    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        #grab information from the raw form information
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()
            # Now we hash the password with the set_password method then update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves,
            # we set commit=False. This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # If user provided a profile picture we need to get it from the input form
            # and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
                # Now we save the UserProfile model instance.
                profile.save()
                # Update our variable to indicate that registration was successful.
                registered = True
        else:
            #if form is invalid
            print(user_form.errors, profile_form.errors)
    else:  #Not a HTTP POST, so we render our blank form using two ModelForm instances
        user_form = UserForm()
        profile_form = UserProfileForm()
    # Render the template depending on the context.
    return render(
        request, 'registration/register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Esempio n. 23
0
def register(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, request.FILES)
        profile_form = UserProfileForm(request.POST, request.FILES)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            raw_password = user.password  # this will be used in logging in user later...see below
            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            # logging in user after completing registration
            user = auth.authenticate(username=user.username,
                                     password=raw_password)
            auth.login(request, user)
            return HttpResponseRedirect(reverse('index'))
        else:
            print(user_form.errors)
            print(profile_form.errors)
            # it is happening for validation errors
            # and see we are not returning anything
            # may be django handles it itself
            # beacuse django retuns this form with telling error messages
            # if we show the validation error messages to user in the template
            # so that they may enter correct value
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
    }

    return render(request, 'registration/register.html', context=context)
Esempio n. 24
0
def register_publicuser(request):

	# A boolean value for telling the template whether the registration was successful.
	# Set to False initially. Code changes value to True when registration succeeds.
	registered = False
	user_group = 'User'

	args = {}
	args.update(csrf(request))

	# If it's a HTTP POST, we're interested in processing form data.
	if request.method == 'POST':
		# Attempt to grab information from the raw form information.
		# Note that we make use of both UserForm and UserProfileForm.
		user_form = UserForm(data=request.POST)
		user_profile_form = UserProfileForm(data=request.POST)
		args['user_form'] = user_form

		# If the two forms are valid...
		if user_form.is_valid() and user_profile_form.is_valid():
			# Save the user's form data to the database.
			user = user_form.save()

			# Now we hash the password with the set_password method.
			# Once hashed, we can update the user object.
			username = user_form.cleaned_data['username']
			email = user_form.cleaned_data['email']
			user.set_password(user.password)
			user.is_active = False
			user.save()

			# Now sort out the UserProfile instance.
			# Since we need to set the user attribute ourselves, we set commit=False.
			# This delays saving the model until we're ready to avoid integrity problems.
			profile = user_profile_form.save(commit=False)
			profile.user = user

			# Generate activation key
			salt = hashlib.sha1(str(random.random()).encode('utf-8')).hexdigest()[:5]
			activation_key = hashlib.sha1((salt+email).encode('utf-8')).hexdigest()
			key_expires = datetime.datetime.today() + datetime.timedelta(2)

			profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires)
			# Now we save the UserProfile model instance.
			profile.save()

			# Set user group - for this, we set it to 'User'
			g = Group.objects.get(name = user_group)
			g.user_set.add(user)

			#Empty public user profile
			publicprofile = PublicUserProfile(userprofile = profile, allergies = "", height = 0, weight = 0)
			publicprofile.save()

			# Update our variable to tell the template registration was successful.
			registered = True

			emailnotify("publicuser", username, email, activation_key)

		# Invalid form or forms - mistakes or something else?
		# Print problems to the terminal.
		# They'll also be shown to the user.
		else:
			print(user_form.errors, user_profile_form.errors)

	# Not a HTTP POST, so we render our form using two ModelForm instances.
	# These forms will be blank, ready for user input.
	else:
		user_form = UserForm()
		user_profile_form = UserProfileForm()

	# Render the template depending on the context.
	return render_to_response(
			'registration/public-signup.html',
			{'user_form': user_form, 'user_profile_form': user_profile_form, 'registered': registered},
			RequestContext(request))
Esempio n. 25
0
 def test_user_profile_photo_label(self):
     form = UserProfileForm()
     self.assertEqual(form.fields['photo'].label, 'Аватарка')
Esempio n. 26
0
 def test_user_profile_login_label(self):
     form = UserProfileForm()
     self.assertEqual(form.fields['login'].label, 'Логин')
Esempio n. 27
0
def user_register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the registration was successful.
    # Set to False initially. Code changes value to True when registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.is_active = False
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set commit=False.
            # This delays saving the model until we're ready to avoid integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

            #send an Email
            send_to = request.POST['email']
            firstname = request.POST['firstname']
            lastname = request.POST['lastname']
            name = firstname+' '+lastname
            body = unicode(u'''
Hello %s!
             
Thank you for registering!

Greetings from BITS Pilani!

It gives me immense pleasure in inviting your institute to the 30th edition of BITS Open Sports Meet (BOSM), the annual national sports meet of Birla Institute of Technology & Science, Pilani, India. This year, BOSM will be held from September 18th to 22nd.             

Kindly go through the invite attached with this email and apply through our website www.bits-bosm.org. Applications close on 31st August 2015 at 1700 hrs.            

Please apply as soon as possible to enable us to confirm your participation at the earliest.             

We would be really happy to see your college represented at our sports festival.            

We look forward to seeing you at BOSM 2015.

P.S: THIS EMAIL DOES NOT CONFIRM YOUR PRESENCE AT BOSM 2015.

Regards,
Vinit Bhat
CoSSAcn (Head)
Dept. of Publications & Correspondence, BOSM 2015
BITS Pilani
Ph: +91 96605 77340
                ''') % name
            email = EmailMessage('Registration Confirmation', body, '*****@*****.**', [send_to])
            email.attach_file('/home/dvm/bosm/bosm2015/bosm2015/media/pdf/BOSM 2015 Invite.pdf')
            email.send()

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print user_form.errors, profile_form.errors

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    return render(request, 'registration/register.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
Esempio n. 28
0
def register_clinician(request):

	# A boolean value for telling the template whether the registration was successful.
	# Set to False initially. Code changes value to True when registration succeeds.
	registered = False
	user_group = 'Clinician'

	args = {}
	args.update(csrf(request))

	# If it's a HTTP POST, we're interested in processing form data.
	if request.method == 'POST':

		user_form = UserForm(data=request.POST)
		user_profile_form = UserProfileForm(data=request.POST)
		clinical_profile_form = ClinicalUserProfileForm(data=request.POST)
		clinic_form = ClinicForm(data=request.POST)
		args['user_form'] = user_form

		# If the two forms are valid...
		if user_form.is_valid() and clinical_profile_form.is_valid() and clinic_form.is_valid() and user_profile_form.is_valid():
			# Save the user's form data to the database.
			user = user_form.save()
			username = user_form.cleaned_data['username']
			email = user_form.cleaned_data['email']
			user.set_password(user.password) # hash password
			user.is_active = False
			user.save()

			user_profile = user_profile_form.save(commit=False)
			user_profile.user = user
			user_profile.save()

			# save clinician profile
			clinical_profile = clinical_profile_form.save(commit=False)
			clinical_profile.userprofile = user_profile
			clinical_profile.save()

			# save clinic - need to check if user inputted the text himself/herself
			clinic = clinic_form.save(commit=False)
			clinical_profile.clinic_of_practice = clinic
			clinic.save()

			# Set user group - for this, we set it to 'User'
			g = Group.objects.get(name = user_group)
			g.user_set.add(user)

			# Update our variable to tell the template registration was successful.
			registered = True

			emailnotify("clinicianuser", username, email, "")

		else:
			print(user_form.errors, user_profile_form.errors, clinic_form.errors, clinical_profile_form.errors)

	# Not a HTTP POST, so we render our form using two ModelForm instances.
	# These forms will be blank, ready for user input.
	else:
		user_form = UserForm()
		user_profile_form = UserProfileForm()
		clinical_profile_form = ClinicalUserProfileForm()
		clinic_form = ClinicForm()

	# Render the template depending on the context.
	return render_to_response(
			'registration/doctor-signup.html',
			{'user_form': user_form, 'user_profile_form': user_profile_form, 'clinical_profile_form': clinical_profile_form, 'clinic_form': clinic_form, 'registered': registered},
			RequestContext(request))