Example #1
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            first = form.cleaned_data['first_name']
            last = form.cleaned_data['last_name']
            pass1 = form.cleaned_data['password']
            pass2 = form.cleaned_data['confirm_password']
            email1 = form.cleaned_data['email']
            email2 = form.cleaned_data['confirm_email']
            if User.objects.filter(username=username).count():
                return HttpResponseRedirect('/register/')
            if pass1 == pass2 and email1 == email2:
                user = User.objects.create_user(username, email1, pass1)
                try:
                    user.first_name = first
                except:
                    pass
                try:
                    user.last_name = last
                except:
                    pass
             
                user.save()
                return HttpResponseRedirect('/success/')
            else:
                return HttpResponseRedirect('/register/')
        else:
            return HttpResponseRedirect('/register/')
    else:
        form = RegistrationForm()
    return render(request, 'register/register.html', {'form' : form})
Example #2
0
def accept(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return render(request, 'done.html')
    return render(request, 'signup.html')
Example #3
0
	def post(self,request,*args,**kwargs):
		form=RegistrationForm(request.POST)
		context={
		"title":"testing",
		"form":form
		}

		if form.is_valid():
			mail=form.cleaned_data.get('email')
			name=form.cleaned_data.get('name')
			phone=form.cleaned_data.get('phone')
			college=form.cleaned_data.get('college')
			stay=form.cleaned_data.get('stay')
			code=uniqueid('6')
			u=userinfo(excelid=code,name=name,college=college,email=mail,phone=phone,stay=stay,present=True)
			u.save()
			#flag for offlinereg or paidreg
			flag=0

			context = {
				"excelid":code,
				"flag" : flag
			}
			return render(request,"excelid.html",context)
		return render(request,"offlinereg.html",context)
Example #4
0
def register(request):
    if request.POST:
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/')
        else:
            return render(request, 'reg_form.html', {'form': form})
    else:
        return render(request, 'reg_form.html', {'form': RegistrationForm()})
Example #5
0
 def test_registration_form_valid_data(self):
     form = RegistrationForm(
         data={
             'first_name': 'John',
             'last_name': 'Smith',
             'username': '******',
             'email': '*****@*****.**',
             'password1': 'openplease123',
             'password2': 'openplease123'
         })
     self.assertTrue(form.is_valid())
Example #6
0
 def test_registration_form_invalid_data(self):
     form = RegistrationForm(
         data={
             'first_name': 'John',
             'last_name': 'Smith',
             'username': '******',
             'email': '*****@*****.**',
             'password1': 'openplease1234',
             'password2': 'openplease123'
         })
     self.assertFalse(form.is_valid())
     self.assertEquals(len(form.errors), 1)
Example #7
0
def register(request):
	if request.method == 'POST':
		print request.POST
		form = RegistrationForm( request.POST )
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/')
		else:
			return render(request, 'register/register.html', {'form':form})
		
	form = RegistrationForm()
	return render(request, 'register/register.html', { 'form':form })
def register(request):
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        user = Register()
        user.name = form.cleaned_data['username']
        user.mobileNo = form.cleaned_data['mobileNo']
        user.password = form.cleaned_data['password1']
        user.email = form.cleaned_data['email']
        user.save()
        request.session['username'] = user.name

        return HttpResponseRedirect('/restaurant/')
    return render(request, 'register/signUp.html', {'form': form})
Example #9
0
	def get(self,request,*args,**kwargs):
		form=RegistrationForm()
		context={
		"title":"testing",
		"form":form
		}
		return render(request,"offlinereg.html",context)
Example #10
0
def mix_of_login_register(request, slug):
    """
        Template contains 2 forms, the login and the registration
        """
    if slug == 'doer':
        is_doer = True
        is_poster = False
    elif slug == 'poster':
        is_poster = True
        is_doer = False
    if request.user.is_authenticated():
        return HttpResponseRedirect('/dashboard/')
    if 'login' in request.POST:
        return LoginRequest(request)
    elif 'register' in request.POST:
        return PersonRegistration(request, slug)
    else:
        form = LoginForm()
        form2 = RegistrationForm()
        context = {
            'form': form,
            'form2': form2,
            'is_doer': is_doer,
            'is_poster': is_poster,
        }
        return render_to_response('mixlogin.html',
                                  context,
                                  context_instance=RequestContext(request))
Example #11
0
    def get(self, request, *args, **kwargs):

        context_dict = {
            'too_many_registrations_error': TOO_MANY_REGISTRATIONS_ERROR,
            'choices': UserRegistration.BICYCLE_CHOICES,
            'show_steps': True,
            'step_2': 'class="active"',
            'form': RegistrationForm()
        }
        return render(request, self.template_name, context_dict)
Example #12
0
	def post(self,request,*args,**kwargs):
		form = RegistrationForm()
		context = {
		"title": "testing",
		"form": form
		}
		if form.is_valid():
			mail = form.cleaned_data.get('email')
			name = form.cleaned_data.get('name')
			phone = form.cleaned_data.get('phone')
			college = form.cleaned_data.get('college')
			stay1 = form.cleaned_data.get('stay')
			code = uniqueid('6')
			u = userinfo(excelid=code, name=name, college=college, email=mail, phone=phone, stay=stay1)
			u.save()
			# obj=userinfo.objects.get(email=mail)
			# im=pyqrcode.create(obj.excelid)
			# im.svg('static/qrcodes/%s.svg'%(obj.excelid),scale=20)
			return render(request,"success.html",{"name":name})

		return render(request,"home.html",context)
Example #13
0
    def post(self, request, *args, **kwargs):
        form = RegistrationForm(request.POST)
        context = {"title": "testing", "form": form}
        print(form)
        if form.is_valid():
            mail = form.cleaned_data.get('email')
            name = form.cleaned_data.get('name')
            phone = form.cleaned_data.get('phone')
            college = form.cleaned_data.get('college')
            code = 'EX' + uniqueid(7)
            u = userinfo(excelid=code,
                         name=name,
                         college=college,
                         email=mail,
                         phone=phone,
                         outsider=True)
            u.save()
            # obj=userinfo.objects.get(email=mail)
            # im=pyqrcode.create(obj.excelid)
            # im.svg('static/qrcodes/%s.svg'%(obj.excelid),scale=20)
            context = {"excelid": code, "flag": 2}
            return render(request, "excelid.html", context)

        return render(request, "home.html", context)
Example #14
0
    def post(self, request):
        form = RegistrationForm(request.POST)
        if form.is_valid():
            userObj = form.cleaned_data
            email = userObj['Email']
            password = userObj['Password']
            text = ''
            if not (USER.objects.filter(Email=email).exists()
                    or USER.objects.filter(Password=password)):
                form.save()
            else:
                return HttpResponse(
                    'Looks like a username with that email or password already exists'
                )

        else:
            form = RegistrationForm()

        args = {'form': form, 'text': text}
        return render(request, 'html/register.html', args)
Example #15
0
def signup(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            print("signup posted valid form")
            client = boto3.client('ses', region_name='us-east-1')
            user = form.save(commit=False)
            user.is_active = False
            user.save()
            current_site = get_current_site(request)
            subject = 'Activate Your WorkTracker Account'
            message = render_to_string(
                'account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(
                        user.pk)).decode(),
                    'token': account_activation_token.make_token(user),
                })
            response = client.send_email(Source='*****@*****.**',
                                         Destination={
                                             'ToAddresses': [
                                                 form.cleaned_data['username'],
                                             ],
                                         },
                                         Message={
                                             'Subject': {
                                                 'Data': subject,
                                             },
                                             'Body': {
                                                 'Html': {
                                                     'Data': message,
                                                 }
                                             }
                                         },
                                         ReplyToAddresses=[
                                             '*****@*****.**',
                                         ])
            print(response)
            return redirect('login')
    else:
        form = RegistrationForm()
    return render(request, 'register.html', {'form': form})
Example #16
0
def PersonRegistration(request, slug):

    if slug == 'doer':
        is_doer = True
        is_poster = False
    elif slug == 'poster':
        is_poster = True
        is_doer = False

    if request.user.is_authenticated():
        return HttpResponseRedirect('/profile/')
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['email'],
                email=form.cleaned_data['email'],
                password=form.cleaned_data['password'],
            )
            firstname = form.cleaned_data['firstname']
            lastname = form.cleaned_data['lastname']
            user.first_name = firstname
            user.last_name = lastname
            name = '%s %s' % (user.first_name, user.last_name)
            p = PersonClassification.objects.get(slug=slug)
            a = slug
            slug = str(user.id) + str(datetime.now().day) + str(
                datetime.now().year)
            skills = form.cleaned_data['skills']
            person = Person(
                person=user,
                person_class=p,
                is_verified=False,
                is_active=False,
                address=form.cleaned_data['address'],
                birthday=form.cleaned_data['birthday'],
                firstname=form.cleaned_data['firstname'],
                lastname=form.cleaned_data['lastname'],
                created_at=datetime.now(),
                contactno=form.cleaned_data['contactno'],
                #classification = a,
            )

            user.save()
            person.save()
            person.skills = skills
            if person.person_class.__str__() == 'poster':
                template = 'register_poster.html'
            else:
                template = 'register_doer.html'
            '''
                        send verification instructions to user
                        '''
            subject = 'Welcome to Tulong.ph'
            message = 'Hi %s we from tulong.ph, gladly welcomes you. Please reply to this email if you have any questions.' % person.firstname
            to = person.person.email
            #send_mail(subject,message,'*****@*****.**',[to],fail_silently=False)

            name = "%s %s" % (person.firstname, person.lastname)
            context = {'full_name': name, 'person': person}
            text_content = render_to_string('email/register.html', context)
            html_content = render_to_string('email/register_html.html',
                                            context)
            msg = EmailMultiAlternatives(subject, text_content,
                                         settings.EMAIL_HOST_USER, [to])
            msg.attach_alternative(html_content, "text/html")
            msg.send()
            #send_mail(subject, email_content,
            #        settings.EMAIL_HOST_USER, [to],fail_silently=False)
            '''
                        send the new user to the admin 
                        '''
            person_classification = person.person_class.__str__()
            subject = 'New User as %s' % (person_classification)
            message = 'User %s Registered as %s ' % (person.person.email,
                                                     person_classification)
            to = '*****@*****.**'
            send_mail(subject,
                      message,
                      '*****@*****.**', [to],
                      fail_silently=False)

            return render_to_response(template, {
                'status': person,
                'is_doer': is_doer,
                'is_poster': is_poster,
            },
                                      context_instance=RequestContext(request))
            #return HttpResponseRedirect('/login/')
        else:
            return render_to_response('register.html', {
                'form': form,
                'is_doer': is_doer,
                'is_poster': is_poster,
            },
                                      context_instance=RequestContext(request))

    else:
        ''' user is not submitting the form, show them a blank registration form '''
        form = RegistrationForm()
        context = {
            'form': form,
            'is_doer': is_doer,
            'is_poster': is_poster,
        }
        return render_to_response('register.html',
                                  context,
                                  context_instance=RequestContext(request))
Example #17
0
def registration(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/profile/')
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['email'],
                email=form.cleaned_data['email'],
                password=form.cleaned_data['password'],
            )
            firstname = form.cleaned_data['firstname']
            lastname = form.cleaned_data['lastname']
            user.first_name = firstname
            user.last_name = lastname
            name = '%s %s' % (user.first_name, user.last_name)

            a = request.session['classification']
            p = PersonClassification.objects.get(slug=a)
            slug = str(user.id) + str(datetime.now().day) + str(
                datetime.now().year)
            skills = form.cleaned_data['skills'],
            person = Person(
                person=user,
                person_class=p,
                is_verified=False,
                is_active=False,
                address=form.cleaned_data['address'],
                birthday=form.cleaned_data['birthday'],
                firstname=form.cleaned_data['firstname'],
                lastname=form.cleaned_data['lastname'],
                created_at=datetime.now(),
                contactno=form.cleaned_data['contactno'],
                classification=a,
            )

            user.save()
            person.save()
            person.skills = skills
            if a == 'poster':
                template = 'register_poster.html'
            else:
                template = 'register_doer.html'
            '''
                        send verification instructions to user
                        '''
            subject = 'Welcome to Tulong.ph'
            message = 'Hi %s we from tulong.ph, gladly welcomes you. Please reply to this email if you have any questions.' % person.firstname
            to = person.person.email
            email_from = '*****@*****.**'
            send_mail(subject, message, email_from, [to], fail_silently=False)
            '''
                        send the new user to the admin 
                        '''
            subject = 'new user'
            message = 'user %s registered' % person.firstname
            to = email_from
            send_mail(subject, message, email_from, [to], fail_silently=False)

            return render_to_response(template, {'status': person},
                                      context_instance=RequestContext(request))

        else:
            return render_to_response(
                'register.html', {
                    'form': form,
                    'test': request.session['classification'],
                },
                context_instance=RequestContext(request))

    else:
        ''' user is not submitting the form, show them a blank registration form '''
        form = RegistrationForm()
        context = {
            'form': form,
            'test': request.session['classification'],
        }
        return render_to_response('register.html',
                                  context,
                                  context_instance=RequestContext(request))
Example #18
0
    def post(self, request):
        if not request.user.is_authenticated():
            return HttpResponseRedirect('/accounts/login')
        if not Convention.objects.filter(active=True).order_by('-id')[0].registration_open:
            raise PermissionDenied()
        if 'confirm' in request.POST.keys():
            form = request.session['form']
            dealer_price = 0
            dealer_reglevel = None
            if form.cleaned_data['dealer_registration_level']:
                dealer_reglevel = DealerRegistrationLevel.objects.get(id=form['dealer_registration_level'].value)
                dealer_price = dealer_reglevel.price
            discount_amount = 0
            discount_percent = 0
            code = None
            reglevel = RegistrationLevel.objects.get(id=form['registration_level'].value)
            if form.cleaned_data['coupon_code']:
                code = CouponCode.objects.get(code=form.cleaned_data['coupon_code'])
                if code.percent:
                    discount_percent = code.discount
                else:
                    discount_amount = code.discount
                if code.force_registration_level:
                    reglevel = code.force_registration_level
                if code.force_dealer_registration_level:
                    dealer_reglevel = code.force_dealer_registration_level
                    dealer_price = dealer_reglevel.price
            amount = max(((reglevel.price + dealer_price - discount_amount) * (1 - discount_percent)), 0)
            if 'stripeToken' in request.POST.keys():
                # Process Stripe payment
                try:
                    stripe.api_key = Convention.objects.filter(active=True).order_by('-id')[0].stripe_secret_key
                    charge = stripe.Charge.create(
                                                  amount=int(amount) * 100,
                                                  currency="USD",
                                                  card=request.POST['stripeToken'],
                                                  description=reglevel.title)
                    reg = form.save(commit=False)
                    reg.ip = request.META['REMOTE_ADDR']
                    reg.user = request.user
                    reg.registration_level = reglevel
                    reg.dealer_registration_level = dealer_reglevel
                    try:
                        reg.save()
                        method = PaymentMethod.objects.get(id=form['payment_method'].value)
                        payment = Payment(registration=reg,
                                          payment_method=method,
                                          payment_amount=amount,
                                          payment_extra=charge.id)
                        payment.save()
                        if code:
                            couponuse = CouponUse(registration=reg,
                                                  coupon=code)
                            couponuse.save()
                    except Exception as e:
                        charge.refunds.create()
                        raise e
                    request.session.pop('form')
                except stripe.error.CardError as e:
                    # Pass a "Payment Declined" error to the user
                    form.errors['__all__'] = form.error_class([e.json_body['error']['message']])
                    request.session.pop('form')
                    return render(request, 'register/register.html', {'form': form})
            else:
                # Confirm normally; don't create payment record
                reg = request.session['form'].save(commit=False)
                reg.ip = request.META['REMOTE_ADDR']
                reg.user = request.user
                reg.registration_level = reglevel
                reg.dealer_registration_level = dealer_reglevel
                try:
                    reg.save()
                    if amount == 0:
                        method = PaymentMethod.objects.get(id=form['payment_method'].value)
                        payment = Payment(registration=reg,
                                          payment_method=method,
                                          payment_amount=0)
                        payment.save()
                        if code:
                            couponuse = CouponUse(registration=reg,
                                                  coupon=code)
                            couponuse.save()
                except Exception as e:
                    raise e
                request.session.pop('form')

            convention = Convention.objects.filter(active=True).order_by('-id')[0]
            try:
                send_mail('Convention Registration',
                          "We have your registration down for %s.\n\n" % ( convention.name ) +
                          'If you have any questions, please let us know!',
                          convention.contact_email,
                          [form.cleaned_data['email']], fail_silently=True)
            except Exception as e:
                logging.exception("Failed sending email")
            return render(request, 'register/success.html')
        else:
            form = RegistrationForm(request.POST)
            if form.is_valid():
                request.session['form'] = form
                convention = Convention.objects.filter(active=True).order_by('-id')[0]
                reglevel = RegistrationLevel.objects.get(id=form['registration_level'].value)
                dealer_price = 0
                dealer_tables = None
                if form.cleaned_data['dealer_registration_level']:
                    dealer_reglevel = DealerRegistrationLevel.objects.get(id=form['dealer_registration_level'].value)
                    dealer_price = dealer_reglevel.price
                    dealer_tables = dealer_reglevel.number_tables
                discount_amount = 0
                discount_percent = 0
                if form.cleaned_data['coupon_code']:
                    code = CouponCode.objects.get(code=form.cleaned_data['coupon_code'])
                    if code.percent:
                        discount_percent = code.discount
                    else:
                        discount_amount = code.discount
                    if code.force_registration_level:
                        reglevel = code.force_registration_level
                    if code.force_dealer_registration_level:
                        dealer_reglevel = code.force_dealer_registration_level
                        dealer_price = dealer_reglevel.price
                        dealer_tables = dealer_reglevel.number_tables

                method = PaymentMethod.objects.get(id=form['payment_method'].value)
                shirt_size = ShirtSize.objects.get(id=form['shirt_size'].value)
                amount = max(((reglevel.price + dealer_price - discount_amount) * (1 - discount_percent)), 0)
                if amount == 0:
                    method.is_credit = False

                return render(request, 'register/confirm.html', {'convention': convention,
                                                                 'form': form,
                                                                 'registration_level': reglevel.title,
                                                                 'registration_price': amount,
                                                                 'registration_amount': int(amount) * 100,
                                                                 'dealer_number_tables': dealer_tables,
                                                                 'is_credit': method.is_credit,
                                                                 'method': method.name,
                                                                 'shirt_size': shirt_size,
                                                                 'birthday': form.cleaned_data['birthday'].strftime("%B %d, %Y")})
            else:
                return render(request, 'register/register.html', {'form': form})
Example #19
0
 def get(self, request):
     form = RegistrationForm()
     return render(request, 'html/register.html', {'form': form})
Example #20
0
 def test_registration_form_no_data(self):
     form = RegistrationForm(data={})
     self.assertFalse(form.is_valid())
     self.assertEquals(len(form.errors), 6)