コード例 #1
0
ファイル: views.py プロジェクト: Bisk1/kongming
def register_page(request):
    """
    User can register here to get an account
    :param request: HTTP request
    :return: HTTP response
    """
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data.get('username'),
                password=form.cleaned_data.get('password'),
                email=form.cleaned_data.get('email')
            )
            user.save()
            subscription = Subscription(name=user,
                                        registration_date=datetime.now(),
                                        last_login_date=datetime.now(),
                                        abo_date=datetime.now() + timedelta(days=30))
            subscription.save()

            return render(request, "users/register_success.html", {'username': form.cleaned_data['username']})
    else:
        form = RegistrationForm()
    return render(request, "users/register.html", {"form": form})
コード例 #2
0
    def test_new_subscription(self):
        """ Tests whether the creation logic is working

        Returns:

        """
        pre_count_subscriptions = Subscription.objects.all().count()
        post_params = {
            "metadata": self.service_md.id,
            "user": self.user.id,
            "notify_on_update": True,
            "notify_on_metadata_edit": True,
            "notify_on_access_edit": True,
        }
        response = self.client.post(
            path=Subscription.get_add_view_url(),
            data=post_params
        )
        post_count_subscriptions = Subscription.objects.count()
        self.assertEqual(response.status_code, 302)
        self.assertEqual(pre_count_subscriptions + 1, post_count_subscriptions)
        try:
            new_subscription = Subscription.objects.get(
                metadata=self.service_md,
                user=self.user
            )
            self.assertEqual(post_params["notify_on_update"], new_subscription.notify_on_update)
            self.assertEqual(post_params["notify_on_metadata_edit"], new_subscription.notify_on_metadata_edit)
            self.assertEqual(post_params["notify_on_access_edit"], new_subscription.notify_on_access_edit)
        except ObjectDoesNotExist:
            self.fail(msg="Subscription was not created for correct user or metadata!")

        # Check that no duplicates can be created
        self.client.post(
            path=Subscription.get_add_view_url(),
            data=post_params
        )
        post_count_subscriptions = Subscription.objects.all().count()
        self.assertEqual(pre_count_subscriptions + 1, post_count_subscriptions)
コード例 #3
0
ファイル: fb.py プロジェクト: daasara/riba
def subscribe_user(request, name, email_id, mobile_no, source=None):
    info = {}
    info['error'] = ''
    info['image_url'] = ''
    domain = request.client
    # Check if email_id is subscribed for the Deal on a requestes Domain
    # Invalidate the user if already subscribed
    emails = Subscription.objects.filter(contact_type='email', contact=email_id, source=source)
    if emails:
        email = emails[0]
        if not email.verified_on:
            send_subscription_email(request, email)
            info['email_status'] = 'ok'
        else:
            info['email_status'] = 'fail'
    else:
        # subscribe user email
        email = Subscription(contact_type='email', source=source)
        email.contact = email_id
        newsletter = NewsLetter.objects.get(newsletter='DailyDeals',client=request.client.client)
        email.newsletter = newsletter
        if name:
            email.name = name
        email.save()
        send_subscription_email(request, email)
        info['email_status'] = 'ok'
    if mobile_no:
        phones = Subscription.objects.filter(contact_type='phone', contact=mobile_no, source=source)
        if phones:
            phone = phones[0]
            if phone.verified_on:
                info['phone_status'] = 'fail'
                return info
        else:
            phone = Subscription(contact_type='phone', source=source)
            newsletter = NewsLetter.objects.get(newsletter='DailyDeals',client=request.client.client)
            phone.newsletter = newsletter
            phone.contact = mobile_no
            if name:
                phone.name = name
            phone.save()
            # Send deal subscription confirmation sms
    #        utils.subscribe_send_sms(mobile_no)
            
        # call zip dial for phone verification
        jsonDict = {}
        jsonDict['userEnteredMobileNumber'] = mobile_no
        jsonDict['zipDialCallerID'] = 'subscription'
        jsonStr = simplejson.dumps(jsonDict)
        #jsonStr = "{\"userEnteredMobileNumber\":\"" + str(mobile_no) + "\"}"
        try:
            s1 = subscribeUser(jsonStr)
            s = simplejson.loads(s1)
            if(s['status'] == '1'):
                info['image_url'] = s['img']
                info['verification_code'] = s['transaction_token']
                
                # update verification_code in the subscription table
                phone.verification_code = s['transaction_token']
                phone.save()
                info['phone_status'] = 'ok'
            else:
                log.info("==== ZIP DIAL has returned empty string or failed status")
                info['phone_status'] = 'error'
             #   info['error'] = 'Sorry we can not verify your phone number now. Please try again later'
        except Exception as e:
            log.info("==== ZIP DIAL has returned exception: %s" % e)
            info['phone_status'] = 'error'
            #info['error'] = 'Sorry we can not verify your phone number now. Please try again later'
            
    return info
コード例 #4
0
def subscribe_user(request, name, email_id, mobile_no, source=None):
    info = {}
    info["error"] = ""
    info["image_url"] = ""
    domain = request.client
    # Check if email_id is subscribed for the Deal on a requestes Domain
    # Invalidate the user if already subscribed
    emails = Subscription.objects.filter(contact_type="email", contact=email_id, source=source)
    if emails:
        email = emails[0]
        if not email.verified_on:
            send_subscription_email(request, email)
            info["email_status"] = "ok"
        else:
            info["email_status"] = "fail"
    else:
        # subscribe user email
        email = Subscription(contact_type="email", source=source)
        email.contact = email_id
        newsletter = NewsLetter.objects.get(newsletter="DailyDeals", client=request.client.client)
        email.newsletter = newsletter
        if name:
            email.name = name
        email.save()
        send_subscription_email(request, email)
        info["email_status"] = "ok"
    if mobile_no:
        phones = Subscription.objects.filter(contact_type="phone", contact=mobile_no, source=source)
        if phones:
            phone = phones[0]
            if phone.verified_on:
                info["phone_status"] = "fail"
                return info
        else:
            phone = Subscription(contact_type="phone", source=source)
            newsletter = NewsLetter.objects.get(newsletter="DailyDeals", client=request.client.client)
            phone.newsletter = newsletter
            phone.contact = mobile_no
            if name:
                phone.name = name
            phone.save()
            # Send deal subscription confirmation sms
        #        utils.subscribe_send_sms(mobile_no)

        # call zip dial for phone verification
        jsonDict = {}
        jsonDict["userEnteredMobileNumber"] = mobile_no
        jsonDict["zipDialCallerID"] = "subscription"
        jsonStr = simplejson.dumps(jsonDict)
        # jsonStr = "{\"userEnteredMobileNumber\":\"" + str(mobile_no) + "\"}"
        try:
            s1 = subscribeUser(jsonStr)
            s = simplejson.loads(s1)
            if s["status"] == "1":
                info["image_url"] = s["img"]
                info["verification_code"] = s["transaction_token"]

                # update verification_code in the subscription table
                phone.verification_code = s["transaction_token"]
                phone.save()
                info["phone_status"] = "ok"
            else:
                log.info("==== ZIP DIAL has returned empty string or failed status")
                info["phone_status"] = "error"
            #   info['error'] = 'Sorry we can not verify your phone number now. Please try again later'
        except Exception as e:
            log.info("==== ZIP DIAL has returned exception: %s" % e)
            info["phone_status"] = "error"
            # info['error'] = 'Sorry we can not verify your phone number now. Please try again later'

    return info