Esempio n. 1
0
    def get(self):
        misc = {
            'came_from': '',
            'target_template': 'embed_account.html',
            'time_log': [],
            'handler': 'embed_account',
            'error': None,
            'msg': None,
            'username': '',
            'password': '',
            'email': '',
            'phone': ''
        }
        user_obj = None

        session_ID = self.session.get('session_ID')

        misc['build_tag_display'] = "tag-on"
        misc['build_display'] = "visible"
        misc['import_tag_display'] = "tag-off"
        misc['import_display'] = "hidden"

        if session_ID not in [None, 0]:
            user_obj = get_user_obj({'session_ID': session_ID})
            if user_obj['auth']:

                misc, user_obj, tmp = build_product_data_embed(user_obj, misc)

                tv = {
                    'user_obj':
                    finish_user_obj(user_obj),
                    'misc':
                    finish_misc(misc, user_obj),
                    'layout':
                    "layout_main.html"
                    if user_obj['has_active'] else "layout_lurker.html"
                }
                path = os.path.join("templates", misc['target_template'])
                self.response.out.write(template.render(path, tv))
            else:
                misc['target_template'] = "embed_home.html"
                tv = {
                    'user_obj': None,
                    'misc': finish_misc(misc, user_obj),
                    'layout': 'layout_no_auth.html'
                }
                path = os.path.join("templates", misc['target_template'])
                self.response.out.write(template.render(path, tv))
        else:

            misc['target_template'] = "embed_home.html"
            user_obj = process_non_auth(self)
            tv = {
                'user_obj': finish_user_obj(user_obj),
                'misc': finish_misc(misc, user_obj),
                'layout': 'layout_no_auth.html'
            }
            path = os.path.join("templates", misc['target_template'])
            self.response.out.write(template.render(path, tv))
Esempio n. 2
0
    def post(self):
        queries = []
        params = []
        misc = {
            'came_from': self.request.get("came_from"),
            'error': None,
            'target_template': "embed_home.html",
            'time_log': [],
            'handler': 'embed_home',
            'user_ID': None,
            'process_step': 'start'
        }
        user_obj = None
        misc['username'] = ''
        misc['password'] = ''
        misc['email'] = ''
        misc['phone'] = ''
        misc['embed_domain'] = ''
        misc['REQUIRE_CC_FOR_TRIAL'] = REQUIRE_CC_FOR_TRIAL
        res = {}

        stripe.api_key = STRIPE_SERVER_KEY
        misc['clientKey'] = STRIPE_CLIENT_KEY

        session_ID = self.session.get('session_ID')
        if session_ID not in [None, 0]:
            user_obj = get_user_obj({'session_ID': session_ID})
            if user_obj['auth']:

                layout = "layout_main.html" if user_obj[
                    'has_active'] else "layout_lurker.html"
            else:
                user_obj = process_non_auth(self)
                user_obj['ID'] = None
                layout = 'layout_no_auth.html'
        else:
            user_obj = process_non_auth(self)
            user_obj['ID'] = None
            layout = 'layout_no_auth.html'

        tv = {
            'user_obj': finish_user_obj(user_obj),
            'misc': finish_misc(misc, user_obj),
            'layout': layout
        }
        path = os.path.join("templates", misc['target_template'])
        self.response.out.write(template.render(path, tv))
Esempio n. 3
0
    def get(self):
        misc = {
            'new_viz': None,
            'new_embed': None,
            'came_from': '',
            'target_template': 'embed_home.html',
            'time_log': [],
            'handler': 'embed_home',
            'year': datetime.now().year,
            'error': None,
            'msg': None,
            'username': '',
            'password': '',
            'email': '',
            'phone': ''
        }
        user_obj = None
        misc['import_embed_code'] = ""
        misc['REQUIRE_CC_FOR_TRIAL'] = REQUIRE_CC_FOR_TRIAL

        session_ID = self.session.get('session_ID')

        misc['build_tag_display'] = "tag-on"
        misc['build_display'] = "visible"
        misc['import_tag_display'] = "tag-off"
        misc['import_display'] = "hidden"

        misc = build_viz_data_options(misc)
        if session_ID not in [None, 0]:
            user_obj = get_user_obj({'session_ID': session_ID})
            if user_obj['auth']:

                misc, user_obj, tmp = build_product_data_embed(user_obj, misc)

                if user_obj['active_subscription'] is not None and user_obj[
                        'active_subscription']['status'] in [
                            "expired", "cancelled"
                        ]:
                    misc['target_template'] = "team_inactive.html"
                    misc['error'] = None

                tv = {
                    'user_obj':
                    finish_user_obj(user_obj),
                    'misc':
                    finish_misc(misc, user_obj),
                    'layout':
                    "layout_main.html"
                    if user_obj['has_active'] else "layout_lurker.html"
                }
                path = os.path.join("templates", misc['target_template'])
                self.response.out.write(template.render(path, tv))
            else:
                tv = {
                    'user_obj': None,
                    'misc': finish_misc(misc, user_obj),
                    'layout': 'layout_no_auth.html'
                }
                path = os.path.join("templates", misc['target_template'])
                self.response.out.write(template.render(path, tv))
        else:

            user_obj = process_non_auth(self)
            tv = {
                'user_obj': finish_user_obj(user_obj),
                'misc': finish_misc(misc, user_obj),
                'layout': 'layout_no_auth.html'
            }
            path = os.path.join("templates", misc['target_template'])
            self.response.out.write(template.render(path, tv))
Esempio n. 4
0
    def get(self):
        misc = {
            'came_from': '',
            'view': self.request.get("view"),
            'target_template': 'embed_docs.html',
            'time_log': [],
            'handler': 'embed_docs',
            'year': datetime.now().year,
            'error': None,
            'msg': None,
            'username': '',
            'password': '',
            'email': '',
            'phone': '',
            'AB_group': None
        }
        user_obj = None

        session_ID = self.session.get('session_ID')

        conn, cursor = mysql_connect('LRP')
        query = "SELECT ID, seq, active, context, question, answer from LRP_FAQ where context='embed' and active order by seq asc"
        cursor.execute(query, [])
        misc['faq'] = zc.dict_query_results(cursor)
        cursor.close()
        conn.close()
        if len(misc['faq']) == 0:
            misc['faq'] = None

        if session_ID not in [None, 0]:
            user_obj = get_user_obj({'session_ID': session_ID})
            if user_obj['auth']:

                tv = {
                    'user_obj':
                    finish_user_obj(user_obj),
                    'misc':
                    finish_misc(misc, user_obj),
                    'layout':
                    "layout_main.html"
                    if user_obj['has_active'] else "layout_lurker.html"
                }

            else:
                tv = {
                    'user_obj': None,
                    'misc': finish_misc(misc, user_obj),
                    'layout': 'layout_no_auth.html'
                }

        else:

            user_obj = process_non_auth(self)
            tv = {
                'user_obj': finish_user_obj(user_obj),
                'misc': finish_misc(misc, user_obj),
                'layout': 'layout_no_auth.html'
            }

        if not user_obj['auth']:
            conn, cursor = mysql_connect('LRP')
            cursor.execute(
                "INSERT INTO LRP_Product_Views (datestamp, product_tag, AB_group, user_ID, view_type, tracking_tag, referrer, active) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                [
                    datetime.now(), 'embed', misc['AB_group'], None,
                    misc['handler'],
                    process_tracking_tag(self.request.get('t')),
                    process_referrer(self.request.referrer), 1
                ])
            conn.commit()
            cursor.close()
            conn.close()

        path = os.path.join("templates", misc['target_template'])
        self.response.out.write(template.render(path, tv))
Esempio n. 5
0
    def post(self):
        queries = []
        params = []
        misc = {
            'new_viz': None,
            'new_embed': None,
            'came_from': self.request.get("came_from"),
            'error': None,
            'target_template': "embed_home.html",
            'time_log': [],
            'handler': 'embed_home',
            'user_ID': None,
            'process_step': 'start'
        }
        user_obj = None
        misc['username'] = ''
        misc['password'] = ''
        misc['email'] = ''
        misc['phone'] = ''
        misc['embed_domain'] = ''
        misc['REQUIRE_CC_FOR_TRIAL'] = REQUIRE_CC_FOR_TRIAL
        res = {}

        stripe.api_key = STRIPE_SERVER_KEY
        misc['clientKey'] = STRIPE_CLIENT_KEY

        req = dict_request(self.request)

        # For customization, we ID the embed by the import code, which is parsed (ignoring all the other req elements), which we need for updating the MetaData table

        misc['action'] = self.request.get('action')

        if misc['action'] == "customize_code":
            ignore_fields = [
                'import_embed_code', 'team_ID', 'action', 'use_rolling_n',
                'use_opp_logos'
            ]
            for k in [z for z in req.keys() if z not in ignore_fields]:
                misc[k] = req[k]

            tmps = ['use_rolling_n', 'use_opp_logos']
            for tmp in tmps:
                if tmp in req and req[tmp] in [
                        'yes', 'YES', 'on', 1, '1', 'checked'
                ]:
                    misc[tmp] = 1
                else:
                    misc[tmp] = 0

        misc['year'] = datetime.now(
        ).year if 'year' not in req else req['year']
        misc = build_viz_data_options(misc, req)
        content = {}
        on_server = os.getenv('SERVER_SOFTWARE').startswith(
            'Google App Engine/')
        misc['build_tag_display'] = "tag-off"
        misc['import_tag_display'] = "tag-off"
        misc['customize_tag_display'] = "tag-off"

        # Check what the user is trying to do
        if misc['action'] in ["build_code", "import_code", "customize_code"]:
            if misc['action'] == "import_code":
                misc['import_tag_display'] = "tag-on"
                misc['embed_code'] = parse_imported_embed_code(
                    req['import_embed_code'])
            elif misc['action'] == "build_code":
                misc['build_tag_display'] = "tag-on"
                embed_code, misc, user_obj = build_embed_code(
                    req, misc, user_obj, {})
                misc['embed_code'] = embed_code
            elif misc['action'] == "customize_code":
                misc['customize_tag_display'] = "tag-on"
                if req['import_embed_code'] != "":
                    misc['embed_code'] = parse_imported_embed_code(
                        req['import_embed_code'])
                else:
                    misc['embed_code'] = build_embed_code(
                        req, misc, user_obj, {})

            content['actual'] = 1 if misc['embed_code'] is not None else 0
            content['bad_code'] = 1 if misc['embed_code'] is None else 0

        # If the embed code was read successfully, parse it and generate the content
        if misc['action'] in ["build_code", "import_code", "customize_code"
                              ] and not content['bad_code']:
            embed_obj = read_embed_code(misc['embed_code'])
            specs = {}

            misc, user_obj, embed_obj, content = build_embed_content(
                misc, user_obj, content, embed_obj, specs)
            misc['resp'] = json.dumps({
                'misc': misc,
                'content': content,
                'lr_embed_id': "viz_panel_div",
                'success': "Content received via Post"
            })
            misc['downloadable'] = not on_server

            if misc['downloadable'] and self.request.get('download') not in [
                    None, ''
            ]:
                self.response.headers['Content-Type'] = 'application/json'
                self.response.headers['Content-Disposition'] = str(
                    'attachment; filename="%s.json"' % misc['embed_code'])
                self.response.set_status(200 if 'error' not in res else 500)
                self.response.out.write(json.dumps(res))

        else:
            misc['import_embed_code'] = ""
            misc['resp'] = json.dumps({
                'content': content,
                'error': 'Bad Code'
            })

        # If the user was doing something other than updating an embed (i.e. starting a trial) process it here
        session_ID = self.session.get('session_ID')
        if session_ID not in [None, 0]:
            user_obj = get_user_obj({'session_ID': session_ID})
            if user_obj['auth']:

                if misc['action'] == "start_trial_no_cc":
                    misc, user_obj = create_embed_account_if_missing(
                        misc, user_obj)
                    misc['build_tag_display'] = "tag-on"
                    misc['customize_tag_display'] = "tag-off"
                    misc['import_tag_display'] = "tag-off"
                    misc['embed_code'] = None
                    if 'import_embed_code' in req and req[
                            'import_embed_code'] not in [None, '']:
                        misc['embed_code'] = parse_imported_embed_code(
                            req['import_embed_code'])
                        misc['import_tag_display'] = "tag-on"
                        misc['build_tag_display'] = "tag-off"
                    elif 'build_embed_code' in req and req[
                            'build_embed_code'] not in [None, '']:
                        embed_code, misc, user_obj = build_embed_code(
                            req, misc, user_obj, {})
                        misc['embed_code'] = embed_code

                    content = {
                        'actual': 1 if misc['embed_code'] is not None else 0,
                        'bad_code': 1 if misc['embed_code'] is None else 0
                    }
                    if not content['bad_code']:
                        embed_obj = read_embed_code(misc['embed_code'])
                        specs = {}
                        misc, user_obj, embed_obj, content = build_embed_content(
                            misc, user_obj, content, embed_obj, specs)
                        misc['resp'] = json.dumps({
                            'misc':
                            misc,
                            'content':
                            content,
                            'lr_embed_id':
                            "viz_panel_div",
                            'success':
                            "Content received via Post"
                        })
                        #misc['embed_script'] = build_embed_script(embed_obj);
                    else:
                        misc['import_embed_code'] = ""
                        misc['resp'] = json.dumps({
                            'content': content,
                            'error': 'Bad Code'
                        })

                layout = "layout_main.html" if user_obj[
                    'has_active'] else "layout_lurker.html"
            else:
                user_obj = process_non_auth(self)
                user_obj['ID'] = None
                layout = 'layout_no_auth.html'
        else:
            user_obj = process_non_auth(self)
            user_obj['ID'] = None
            layout = 'layout_no_auth.html'

        misc['target_template'] = "embed_home.html"
        misc['build_display'] = "visible" if misc[
            'build_tag_display'] == "tag-on" else "hidden"
        misc['import_display'] = "visible" if misc[
            'import_tag_display'] == "tag-on" else "hidden"
        misc['customize_display'] = "visible" if misc[
            'customize_tag_display'] == "tag-on" else "hidden"

        # If you are processing a credit card save, you'll need to load the request via self.request.body
        data = {}
        if "action=customize_code" not in self.request.body and "action=build_code" not in self.request.body and "action=import_code" not in self.request.body and "action=start_trial_no_cc" not in self.request.body:
            data = json.loads(self.request.body)
            misc['action'] = 'start_trial_w_cc'

        # If you are processing a CC entry, you aren't going to render a template; just send the results as 200/500
        if misc['action'] == "start_trial_w_cc":
            if 'payment_method_id' in data:

                try:
                    user_obj['email_decrypted'] = decrypt(user_obj['email'])
                    customer = stripe.Customer.create(
                        payment_method=data['payment_method_id'])

                    # Update the customer ID in the LRP Users record
                    query = "UPDATE LRP_Users set stripe_customer_id=%s where ID=%s"
                    param = [encrypt(customer.id), user_obj['ID']]
                    queries.append(query)
                    params.append(param)

                    # Create the subscription details
                    specs = {}
                    specs['trial'] = 1
                    specs['sub_duration'] = 7
                    specs['product_ID'] = 10
                    specs['end_date'] = (datetime.now() +
                                         timedelta(days=specs['sub_duration']))
                    specs['price_paid'] = 0.
                    specs['stripe_payment_method'] = encrypt(
                        data['payment_method_id'])
                    specs['stripe_customer_id'] = encrypt(customer.id)
                    misc, user_obj = create_embed_account_if_missing(
                        misc, user_obj, specs)

                    res['success'] = 1

                except Exception:
                    res['error'] = "An error has occurred. The admin team has been notified"
                    logging.error(
                        "User %d attempted to input CC data, but it failed (storing cc info in DB failed)."
                        % (user_obj['ID']))

            else:
                res['error'] = "An error has occurred. The admin team has been notified"
                logging.error(
                    "User %d attempted to input CC data, but it failed (payment method id not found)."
                    % (user_obj['ID']))

            ex_queries(queries, params)
            self.response.set_status(200 if 'error' not in res else 500)
            self.response.out.write(json.dumps(res))
        else:
            tv = {
                'user_obj': finish_user_obj(user_obj),
                'misc': finish_misc(misc, user_obj),
                'layout': layout
            }
            path = os.path.join("templates", misc['target_template'])
            self.response.out.write(template.render(path, tv))