def otp(request): otp_entered = request.POST.get('otp_entered', False) username = request.session['username'] password = request.session['password'] email_id = request.session['email'] user_type = request.session['user_type'] otp_generated = request.session['otp_generated'] if (otp_entered == False or otp_entered != otp_generated): return render(request, "signup/signup.html", {'message': "Invalid OTP!!!"}) if (user_type == "customer"): new_user = Customer() page_to_redirect = "customer/home.html" elif (user_type == "regular_employee" or user_type == "system_manager" or user_type == "system_admin"): new_user = Employee() new_user.cadre = user_type page_to_redirect = user_type + "/home.html" elif (user_type == "merchant"): new_user = Merchant() page_to_redirect = "merchant/home.html" new_user.username = username new_user.password = password new_user.email = email_id new_user.save() return render(request, page_to_redirect, {'username': username})
def upload_v1(conn, fileitem): import csv import repositories from models import Merchant, Sale, Upload upload = Upload() upload = repositories.UploadRepository(conn).create(upload) for row in csv.DictReader(fileitem.file, delimiter="\t"): merchant = Merchant(name=row['merchant name'].decode('utf-8'), address=row['merchant address'].decode('utf-8')) merchant = repositories.MerchantRepository(conn).create(merchant) sale = Sale(upload=upload, merchant=merchant, purchaser_name=row['purchaser name'].decode('utf-8'), description=row['item description'].decode('utf-8'), unit_price=row['item price'], count=row['purchase count']) sale = repositories.SaleRepository(conn).create(sale) upload.add_sale(sale) repositories.UploadRepository(conn).save(upload) return upload
def create_merchant(): try: body = request.get_json() merchant = Merchant(name=body['name'], city=body['city'], email=body['email']) merchant.insert() except KeyError: abort(500) return jsonify({"success": True, "merchant": merchant.format()})
def add_merchant(): user = g.user form = MerchantForm() if form.validate_on_submit(): try: merchant = db.session.query(Merchant).filter_by( name=form.merchant.data.strip().lower()).one() except: merchant = Merchant(name=form.merchant.data.strip().lower()) db.session.add(merchant) db.session.commit() flash( "The Merchant: '{}' was added".format( form.merchant.data.strip()), 'success') return redirect(url_for('dashboard')) return render_template('add_merchant.html', user=user, form=form)
def merchant_create_user(): if request.method == "POST": name = request.form["name"] email = request.form["email"] password = request.form["password"] confirm_password = request.form["confirm_password"] if not email.index("@") > 0 and not email.index(".") > email.index( "@"): return redirect(url_for('.home_page')) if not confirm_password == password: return redirect(url_for('.home_page')) u = Merchant.query.filter_by(email=email).count() if u == 0: new_merchant = Merchant(name, email, password) db_session.add(new_merchant) db_session.commit() print('Created Merchant', file=sys.stderr) return redirect(url_for('.home_page')) return redirect(url_for('.home_page'))
def save(): # import ipdb; ipdb.set_trace() create_merchant() create_purchase() lines = [] i = 0 receita_total = 0 file_upload = request.files.get('file') content = file_upload.read() lines = content.split('\n') for line in lines: #pula o cabecalho if i == 0: i = i + 1 continue if line == '': continue line = line.split('\t') merchant = Merchant(line[index_merchant_name], line[index_merchant_adress]) purchase = Purchase(line[index_puchaser_name], line[index_item_description], float(line[index_item_price]), int(line[index_purchase_count]), line[index_merchant_name]) receita_total = float(line[index_item_price]) * int( line[index_purchase_count]) + receita_total insere_merchant(merchant) insere_purchase(purchase) return render_template('save.html', receita=receita_total)
def finalize(): code = request.args.get('code') shop_name = request.args.get('shop') timestamp = request.args.get('timestamp') hmac = request.args.get('hmac') params = { 'code': code, 'timestamp': timestamp, 'hmac': hmac, 'shop': shop_name } api_version = app.config.get('SHOPIFY_API_VERSION') shopify.Session.setup(api_key=app.config['SHOPIFY_API_KEY'], secret=app.config['SHOPIFY_API_SECRET']) session = shopify.Session(shop_name, api_version) token = session.request_token(params) try: merchant = Merchant.get(Merchant.shop_name == shop_name) except Merchant.DoesNotExist: merchant = Merchant() merchant.enable = False merchant.shop_name = shop_name merchant.token = token merchant.save() save_default_html(merchant) shop_short = shop_name.replace('.myshopify.com', '') need_webhooks = [ { 'url': 'https://{}/create_order/{}'.format( app.config.get('HOSTNAME'), shop_short), 'topic': 'orders/create', 'created': False }, { 'url': 'https://{}/uninstalled'.format( app.config.get('HOSTNAME')), 'topic': 'app/uninstalled', 'created': False }, ] with shopify.Session.temp(shop_name, api_version, merchant.token): webhooks = shopify.Webhook.find() for webhook in webhooks: for need_webhook in need_webhooks: if webhook.topic == need_webhook.get('topic') and \ webhook.address == need_webhook.get('url'): need_webhook.update({'created': True}) for need_webhook in need_webhooks: if need_webhook.get('created'): continue app.logger.info('create webhook {}'.format(need_webhook.get('topic'))) webhook = shopify.Webhook() webhook.topic = need_webhook.get('topic') webhook.address = need_webhook.get('url') webhook.format = 'json' webhook.save() pause_sdk(2) ecocart_script = shopify.ScriptTag() ecocart_script.event = 'onload' ecocart_script.src = 'https://{}/ecocart.js?shop_name={}'.format( app.config.get('HOSTNAME'), shop_name) ecocart_script.save() image_url = app.config.get('ECOCART_IMAGE_URL') e = Ecocart(image_url, merchant) e.install() if not app.config.get('CHARGE_ENABLE'): url = 'https://{}/admin/apps/{}' # редирект в админку return redirect(url.format(shop_name, app.config.get('SHOPIFY_API_KEY'))) # подписка return_url = 'https://{}/activatecharge/{}' return_url = return_url.format(app.config.get('HOSTNAME'), shop_name) data_create = { 'name': app.config.get('CHARGE_NAME'), 'price': 0.5, 'return_url': return_url, 'test': app.config.get('CHARGE_TEST'), } url = create_application_charge(shop_name, token, data_create) return redirect(url)