Esempio n. 1
0
    def post(self):
        url = settings.URL_PURCHASE_FASTSPRING

        # ------
        # Requires enkiDL
        if self.request.get('download'):
            ref_url = enki.libutil.get_local_url('store')
            self.session['sessionrefpath'] = ref_url
            url_fetcher = ''
            if settings.URLS_ENKIDL:
                # shuffle then try to download from locations in sequence
                random.shuffle(settings.URLS_ENKIDL)
                for i in range(len(settings.URLS_ENKIDL)):
                    url_enkiDL = settings.URLS_ENKIDL[i]
                    item_to_download = 'product_a'
                    url_fetcher = enki.libenkiDL.URLFetcher()
                    url_fetcher.get_download_URL(url_enkiDL,
                                                 settings.SECRET_ENKIDL,
                                                 item_to_download,
                                                 self.request.remote_addr)
                    if not url_fetcher.error:
                        enki.modelcounter.increment('downloads_product_a')
                        break
                if url_fetcher and url_fetcher.error:
                    self.response.status_int = 500
                    self.add_infomessage(MSG.WARNING(), MSG.DOWNLOAD_ERROR())
                    self.redirect('info')
                    return
                url = url_fetcher.download_url
            else:
                self.add_infomessage(MSG.WARNING(), MSG.DOWNLOAD_ERROR())
                self.redirect('info')
                return
        # -------

        else:
            if not settings.SECRET_FASTSPRING or enki.libutil.is_debug(
            ) or settings.ENKI_EMULATE_STORE:
                url = enki.libutil.get_local_url('storeemulatefastspring')
            else:
                enki.modelcounter.increment('purchases_product_a')
            if self.is_logged_in():
                purchaser_user_id = self.enki_user.key.id()
                token = security.generate_random_string(entropy=256)
                token_purchase = EnkiModelTokenVerify(
                    token=token,
                    user_id=purchaser_user_id,
                    type='purchasebyuser')
                token_purchase.put()
                url += '?referrer=' + token_purchase.token.encode('utf-8')
        self.redirect(url)
Esempio n. 2
0
 def get(self):
     if not settings.SECRETS_EXIST:
         self.add_infomessage(
             'warning', MSG.WARNING(),
             'Setup incomplete, see <a class="alert-link"" href="https://github.com/juliettef/enkiWS#enabling-oauth-login-with-google-facebook-twitter">documentation</a>.'
         )
     self.render_tmpl('home.html', False, active_menu='home')
Esempio n. 3
0
	def get( self ):
		# retrieve optional message code - must be 2 lower case letters
		message = self.request.get( 'm' )
		if message and re.search('[a-z]{2}', message):
			if message == 'dl':
				# enkiDL error
				self.add_infomessage( MSG.WARNING(), MSG.DOWNLOAD_ERROR())
		self.render_tmpl( 'info.html' )
Esempio n. 4
0
 def add_infomessage(self, message_header, message_body):
     # reference: http://bootswatch.com/flatly/#indicators
     # message_type values: 'success', 'info', 'warning', 'danger'
     if message_header == MSG.SUCCESS():
         message_type = 'success'
     elif message_header == MSG.INFORMATION():
         message_type = 'info'
     elif message_header == MSG.WARNING():
         message_type = 'warning'
     else:
         message_header = MSG.DANGER()
         message_type = 'danger'
     self.session['infomessage'] = self.session.pop(
         'infomessage', []) + [[message_type, message_header, message_body]]
 def post(self):
     if self.ensure_is_logged_in():
         self.check_CSRF()
         submit_type = self.request.get('submittype')
         if submit_type == 'reset':
             self.redirect(enki.libutil.get_local_url('emailbatchsending'))
         elif submit_type == 'send' or submit_type == 'sendtest':
             ready_to_send = 'off'
             newsletter = self.request.get('newsletter')
             subject = self.request.get('subject')
             body_text = self.request.get('body_text')
             footer_template = self.get_mailgun_email_footer_template(
                 newsletter)
             if submit_type == 'sendtest':
                 self.send_email(self.enki_user.email, subject,
                                 body_text + footer_template)
                 self.add_infomessage(
                     MSG.INFORMATION(),
                     'Test email sent to ' + self.enki_user.email)
             elif submit_type == 'send':
                 ready_to_send = self.request.get('readytosend')
                 if ready_to_send == 'on':
                     batches_emails, batches_emails_recipient_variables = EnkiModelEmailSubscriptions.get_mailgun_email_batches(
                         newsletter)
                     send_success = False
                     for batch_emails, batch_emails_recipient_variables in zip(
                             batches_emails,
                             batches_emails_recipient_variables):
                         send_success = self.send_mailgun_batch_email(
                             batch_emails, subject, body_text,
                             footer_template,
                             batch_emails_recipient_variables)
                     if send_success:
                         self.add_infomessage(MSG.SUCCESS(),
                                              'Batch email sent')
                         self.redirect(
                             enki.libutil.get_local_url(
                                 'emailbatchsending'))
                         return
                     else:
                         self.add_infomessage(MSG.WARNING(),
                                              'Batch email sending failed')
             self.render_tmpl('emailbatchsending.html',
                              newsletter=newsletter,
                              subject=subject,
                              body_text=body_text,
                              footer=footer_template,
                              ready_to_send=ready_to_send)
Esempio n. 6
0
    def post(self):
        if not settings.SECRET_FASTSPRING or enki.libutil.is_debug(
        ) or settings.ENKI_EMULATE_STORE:
            self.check_CSRF()

            product = xstr(self.request.get('product'))
            quantity = xint(self.request.get('quantity'))
            purchase_price = xstr(self.request.get('purchase_price'))
            purchaser_email = xstr(self.request.get('purchaser_email'))
            licence_keys = 'not generated'
            user_id = ''
            emulator_order_id = 'EMULATED_' + webapp2_extras.security.generate_random_string(
                length=10, pool=webapp2_extras.security.DIGITS)

            url = enki.libutil.get_local_url('genlicencefastspring')
            form_fields = {
                'secret': 'pretendsecret',
                'quantity': str(quantity)
            }
            form_data = urllib.urlencode(form_fields)
            result = urlfetch.fetch(url=url,
                                    payload=form_data,
                                    method=urlfetch.POST)
            if result.status_code == 200:
                licence_keys = result.content.replace('-', '')

            referrer = xstr(self.request.get('referrer'))
            token = EnkiModelTokenVerify.get_by_token_type(
                referrer, 'purchasebyuser')
            if token:
                user_id = token.user_id
            licence_key_display = []
            for item in licence_keys.split():
                item_dash = enki.libstore.insert_dashes_5_10(item)
                licence_key_display.append(item_dash)
            self.add_infomessage(
                'info', MSG.INFORMATION(),
                '<h3>FastSpring Store Emulator - Step 1</h3>' +
                '<h4>Emulated purchase details</h4>' + '<ul>' +
                '<li>&lt;EnkiModelProductKey&gt; #{FastSpring variable} = <em>&lt;emulated value&gt;</em></li>'
                + '<li>product_name #{orderItem.productName} = <em>' +
                product + '</em></li>' + '<li>order_id #{order.id} = <em>' +
                emulator_order_id + '</em></li>' +
                '<li>quantity #{orderItem.quantity} = <em>' + xstr(quantity) +
                '</em></li>' +
                '<li>purchase_price #{orderItem.totalUSD} = <em>' +
                purchase_price + '</em></li>' +
                '<li>purchaser_email #{order.customer.email} = <em>' +
                purchaser_email + '</em></li>' +
                '<li>shop_name = <em>Emulator_FastSpring</em></li>' +
                '<li>licence_key #{orderItem.fulfillment.licence.licences.list} = <br><em><b>'
                + '<br>'.join(licence_key_display) + '</b></em></li>' + '</ul>'
                '<h4>Internal data - generated if the purchaser was logged in when they bought the product</h4>'
                + '<ul>' +
                '<li>EnkiModelTokenVerify.user_id = purchaser user_id = <em>' +
                (xstr(user_id) if user_id else 'None') + '</em></li>' +
                '<li>EnkiModelTokenVerify.type purchasebyuser referrer #{order.referrer} = <em>'
                + (xstr(referrer) if referrer else 'None') + '</em></li>' +
                '</ul>')

            url = enki.libutil.get_local_url('ordercompletefastspring')
            form_fields = {
                'licence_key': licence_keys,
                'purchase_price': purchase_price,
                'order_id': emulator_order_id,
                'product_name': product,
                'purchaser_email': purchaser_email,
                'shop_name': 'Emulator_FastSpring',
                'quantity': quantity,
                'referrer': referrer,
                'is_test': True
            }

            form_data = urllib.urlencode(form_fields)
            result = urlfetch.fetch(url=url,
                                    payload=form_data,
                                    method=urlfetch.POST)
            if result.status_code == 200:
                message_view_library = ''
                if self.is_logged_in():
                    message_view_library = '<p><a href="/profile" class="alert-link">View and activate licence keys</a>.</p>'
                self.add_infomessage(
                    'info', MSG.INFORMATION(),
                    '<h3>FastSpring Store Emulator - Step 2</h3><p>Purchase records created<p>'
                    + message_view_library)
            else:
                self.add_infomessage(
                    'warning', MSG.WARNING(),
                    '<h3>FastSpring Store Emulator - Step 2 FAILED: Purchase records not created</h3>'
                )

            self.redirect_to_relevant_page()
Esempio n. 7
0
 def post(self):
     choice = self.request.get('choice')
     # Step 1
     if choice == 'create' or choice == 'cancel':
         token = self.session.get('tokenregisterauth')
         tokenEntity = EnkiModelTokenVerify.get_by_token_type(
             token, 'register')
         authId = tokenEntity.auth_ids_provider
         provider_name, provider_uid = authId.partition(':')[::2]
         auth_email = tokenEntity.email if tokenEntity.email else None
         if choice == 'create':
             if auth_email:
                 # If the email is given by the provider, it is verified. Get or ceate the account and log the user in.
                 user = self.get_or_create_user_from_authid(
                     authId, auth_email)
                 if user:  # login the user through auth
                     self.log_in_session_token_create(user)
                     self.add_infomessage('success', MSG.SUCCESS(),
                                          MSG.LOGGED_IN())
                 else:  # user creation failed (timeout etc.)
                     self.add_infomessage(
                         'warning', MSG.WARNING(),
                         MSG.AUTH_LOGIN_FAILED(provider_name))
                 self.redirect_to_relevant_page()
                 tokenEntity.key.delete()
                 self.session.pop('tokenregisterauth')
             else:
                 # If the email isn't given by the provider, use the manually entered email.
                 self.check_CSRF()
                 email = self.request.get('email')
                 user = self.get_or_create_user_from_authid(authId)
                 self.log_in_session_token_create(user)
                 error_message = ''
                 success = False
                 result = enki.libuser.validate_email(email)
                 if result == enki.libutil.ENKILIB_OK:
                     result = self.email_change_request(
                         email
                     )  # send an email for verification. Since it's not verified at this point, create the account without the email.
                     self.add_infomessage(
                         'info', MSG.INFORMATION(),
                         MSG.REGISTER_AUTH_ADD_EMAIL_INFO_EMAIL_SENT(email))
                     if result == enki.handlerbase.ERROR_EMAIL_IN_USE:
                         self.add_debugmessage(
                             'Comment - whether the email is available or not, the feedback through the UI is identical to prevent email checking.'
                         )
                     success = True
                     tokenEntity.key.delete()
                     self.session.pop('tokenregisterauth')
                 elif result == enki.libuser.ERROR_EMAIL_FORMAT_INVALID:
                     error_message = MSG.WRONG_EMAIL_FORMAT()
                 elif result == enki.libuser.ERROR_EMAIL_MISSING:
                     error_message = MSG.MISSING_EMAIL()
                 self.render_tmpl('registeroauthconfirm.html',
                                  active_menu='register',
                                  token=tokenEntity,
                                  provider_name=provider_name,
                                  provider_uid=str(provider_uid),
                                  error=error_message,
                                  success=success)
         elif choice == 'cancel':
             self.add_infomessage('info', MSG.INFORMATION(),
                                  MSG.REGISTRATION_ABORT())
             self.redirect_to_relevant_page()
             tokenEntity.key.delete()
             self.session.pop('tokenregisterauth')
     # Step 2 (those choices will only be presented to the user if they successfully added an email manually).
     elif choice == 'continue':
         self.redirect_to_relevant_page()
     elif choice == 'profile':
         url = enki.libutil.get_local_url('profile')
         self.session['sessionrefpath'] = url
         self.redirect(url)