def product_2(): form = forms.Product_2() service = IntakeService(session['user'], 'product_2', session['onboarding_complete']) if 'view_id' not in request.args: view_id = service.get_product(request.args.get('view_id')) return redirect(url_for('product_2', view_id=view_id, splash=False)) if ViewFuncs.ValidSubmission(form=form, method=request.method): if request.form['submit_button'] != 'skip': service.product_2(form.data, request.args.get('view_id')) else: service.skip(60) if request.form['submit_button'] == 'update next product': next_id = service.get_product(request.args.get('view_id')) return redirect(url_for('product_2', view_id=next_id, splash=False)) else: return redirect(url_for('home', view='profile')) return ViewFuncs.view_page( user=session['user'], user_name=session['user_name'], form=form, view_page='product_2', next_page='salescycle', coming_home=request.args.get('home'), onboarding_complete=session['onboarding_complete'], splash=request.args.get('splash'))
def company(): form = forms.Company() service = IntakeService(session['user'], 'company', session['onboarding_complete']) if ViewFuncs.ValidSubmission(form=form, method=request.method): if request.form['submit_button'] != 'skip': service.company(form.data) else: service.skip(30) if session['onboarding_complete'] == True: return redirect(url_for('home', view='profile')) else: return redirect(url_for('audience')) return ViewFuncs.view_page( user=session['user'], user_name=session['user_name'], form=form, view_page='company', next_page='audience', coming_home=request.args.get('home'), splash=request.args.get('splash'), onboarding_complete=session['onboarding_complete'], onboarding=True if session['onboarding_complete'] == False else False)
def customers(): form = forms.AddRep() page = AdminViewModel(session['permissions'], 'customers', admin=session['admin']) return ViewFuncs.view_admin(page=page, owner=session['owner_logged_in'], admin=session['admin_logged_in'], manager=session['manager_logged_in'], form=form)
def audience(): form = forms.Audience() service = IntakeService(session['user'], 'audience', session['onboarding_complete']) if 'view_id' not in request.args: view_id = service.get_persona() return redirect(url_for('audience', view_id=view_id, splash=False)) if ViewFuncs.ValidSubmission(form=form, method=request.method): if request.form['submit_button'] != 'skip': service.audience(form.data, request.args.get('view_id')) else: service.skip(40) if request.form['submit_button'] == '+ save and add another audience': next_id = service.get_persona() return redirect(url_for('audience', view_id=next_id, splash=False)) else: if not session['onboarding_complete']: ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime( '%Y-%m-%d %H:%M:%S') UserService.init_profile(st, session['user']) google = GoogleChatService() google.onboarding_complete(email=session['email']) session['onboarding_complete'] = True intro = True else: intro = False return redirect(url_for('home', view='campaigns', intro=intro)) return ViewFuncs.view_page( user=session['user'], user_name=session['user_name'], form=form, view_page='audience', next_page='product', coming_home=request.args.get('home'), splash=request.args.get('splash'), onboarding_complete=session['onboarding_complete'])
def begin(): form = forms.Profile() service = IntakeService(session['user'], 'begin', session['onboarding_complete']) if ViewFuncs.ValidSubmission(form=form, method=request.method): if request.form['submit_button'] != 'skip': service.begin(form.data) if session['onboarding_complete'] == False: payments = PaymentsService(session['email']) stripe_id = payments.create_customer() session['stripe_id'] = stripe_id UserService.UpdateStripeId(session['email'], session['stripe_id']) gchat = GoogleChatService() gchat.onboarding_started(email=session['email']) stripe_info = PaymentsService(session['email'], customer_id=session['stripe_id']) stripe_info.modify(company_name=form.company_name.data) else: service.skip(10) if session['onboarding_complete'] == True: return redirect(url_for('home', view='profile')) else: return redirect(url_for('competitors')) return ViewFuncs.view_page( user=session['user'], user_name=session['user_name'], form=form, view_page='profile', next_page='competitors', coming_home=request.args.get('home'), splash=request.args.get('splash'), onboarding_complete=session['onboarding_complete'], onboarding=True if session['onboarding_complete'] == False else False)
def past(): form = forms.Past() service = IntakeService(session['user'], 'past', session['onboarding_complete']) if ViewFuncs.ValidSubmission(form=form, method=request.method): if request.form['submit_button'] != 'skip': service.past(form.data) else: service.skip(110) return redirect(url_for('home', init=True)) return ViewFuncs.view_page( user=session['user'], user_name=session['user_name'], form=form, view_page='past', next_page='home', coming_home=request.args.get('home'), splash=request.args.get('splash'), onboarding_complete=session['onboarding_complete'])
def goals(): form = forms.Goals() service = IntakeService(session['user'], 'goals', session['onboarding_complete']) if ViewFuncs.ValidSubmission(form=form, method=request.method): if request.form['submit_button'] != 'skip': service.goals(form.data) else: service.skip(80) return redirect(url_for('home', view='profile')) return ViewFuncs.view_page( user=session['user'], user_name=session['user_name'], form=form, view_page='goals', next_page='history', coming_home=request.args.get('home'), splash=request.args.get('splash'), onboarding_complete=session['onboarding_complete'])
def admin_login(): form = forms.AdminLogin() if ViewFuncs.ValidSubmission(form=form, method=request.method): service = AdminService() return service.login(form.email.data, form.password.data, form=form) elif request.method == 'GET': session['owner_logged_in'] = False session['admin_logged_in'] = False session['manager_logged_in'] = False return render_template("admin_view/login.html", form=form)
def customer_login(): if 'logged_in' in session and session.get('logged_in') == True: return redirect(url_for("home")) else: form = forms.CustomerLogin() if ViewFuncs.ValidSubmission(form=form, method=request.method): loginResult, action = UserService.customer_login( form.email.data, form.password.data) return UserService.routeLogin(loginResult, action, form=form) elif request.method == 'GET': session['logged_in'] = False return render_template('login.html', form=form)
def forgot(): form = forms.ForgotPassword() if ViewFuncs.ValidSubmission(form=form, method=request.method): email = EmailService() email.send_email_reset(form.email.data) message_sent = "Your password reset link has been sent! If there is an account associated with that email, you should see it any moment." return render_template('forgot.html', form=form, send=True, message_sent=message_sent) elif request.method == 'GET': session['logged_in'] = False return render_template('forgot.html', form=form, send=True)
def load_past_inputs(): page = request.args.get('page') page = page.replace("/", " ") *first, page = page.split() del first result = ViewFuncs.past_inputs(page, session['user'], view_id=request.args.get('view_id')) if len(result) > 0: result = result.to_json(orient='records') return result else: return 'nah, not this time'
def update_password(token): form = forms.UpdatePassword() if ViewFuncs.ValidSubmission(form=form, method=request.method): email = EmailService() email.update_password(form.password.data, token=token) return redirect(url_for('customer_login', conf=True)) try: return render_template("change_pass.html", pass_step=True, form=form, token=token, send=False, conf=False, reset=False) except: return redirect(url_for('customer_login', expired=True))
def new(): form = forms.CreateCustomer() if ViewFuncs.ValidSubmission(form=form, method=request.method): result = UserService.CreateCustomer(form.email.data, form.password.data, form=form, app=app) if result: # return redirect(url_for('"splash", next_step="begin"')) login = UserService.customer_login(form.email.data, form.password.data) if login: return redirect(url_for('begin')) else: error = "something went wrong." return render_template('new.html', form=form, error=error) elif request.method == 'GET': session['logged_in'] = False return render_template('new.html', form=form)
def tags(): form = forms.TagForm() tag_id = request.args.get('tag_id') if request.args.get('tag_id') else 4 page = AdminViewModel(session['permissions'], 'tags', tag_id=tag_id) if request.method == 'POST' and form.validate_on_submit(): if request.form.get('submit_button'): #if he's searching by id pass else: # if he's submitting the form tactics = TacticService(tag_id=form.search.data) tactics.add(form.data) return redirect( url_for('tags', tag_id=str(int(form.search.data) + 1))) return redirect(url_for('tags', tag_id=form.search.data)) return ViewFuncs.view_admin(page=page, owner=session['owner_logged_in'], admin=session['admin_logged_in'], manager=session['manager_logged_in'], form=form)
def acct_mgmt(customer_id): csv_form = forms.CSVForm() ab_form = forms.ABForm() insight_form = forms.InsightForm() temp_form = forms.TempData() vf = AdminViewFuncs(customer_id) if vf.ValidView(): session['account_rep'] = True if request.method == 'POST': if request.form[ 'submit_button'] == 'submit csv' and csv_form.validate_on_submit( ): ads = google_ads(df=pd.read_csv(csv_form.csv.data.stream), start_range=request.form['start_date'], end_range=request.form['end_date']) ads.save(customer_id) return redirect(url_for('acct_mgmt', customer_id=customer_id)) elif request.form[ 'submit_button'] == 'submit insight' and insight_form.validate_on_submit( ): service = AdminActions(customer_id, session['admin']) service.send_insight(insight_form.body.data, customer_id=customer_id) return redirect(url_for('acct_mgmt', customer_id=customer_id)) elif request.form[ 'submit_button'] == 'submit ab test' and ab_form.validate_on_submit( ): ab = ab_test(df=pd.read_csv(ab_form.csv.data.stream), start_range=request.form['start_date'], end_range=request.form['end_date']) ab.save(customer_id) return redirect(url_for('acct_mgmt', customer_id=customer_id)) elif request.form[ 'submit_button'] == 'temp_data' and temp_form.validate_on_submit( ): service = TempDataService() service.add_record(temp_form, customer_id) return redirect(url_for('acct_mgmt', customer_id=customer_id)) else: return redirect(url_for('acct_mgmt', customer_id=customer_id)) elif request.method == 'GET': page = AdminViewModel(session['permissions'], 'acct_mgmt', admin=session['admin'], user=customer_id, view="dashboard") chat = ChatService('Admin', session['admin'], session['admin'], customer_id=customer_id) chat.run() page.chat = { 'type': chat.type, 'email': chat.email, 'user_id': f"admin-{str(chat.user_id)}", 'hash': chat.hash, 'customer_email': chat.customer_email, 'admin_name': chat.admin_name, 'customer_name': chat.customer_name, 'customer_id': str(chat.customer_id) } return ViewFuncs.view_admin(page=page, owner=session['owner_logged_in'], admin=session['admin_logged_in'], manager=session['manager_logged_in'], csv_form=csv_form, ab_form=ab_form, insight_form=insight_form, temp_form=temp_form, form=None) else: session['account_rep'] = False return "You don't have permissions!"