Skip to content

Register via api #31 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 20 additions & 35 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import uuid
import sqlite3
from subscribie.database import database
from subscribie.schemas import Shop

builder = Blueprint("builder", __name__, template_folder="templates")


class Shop(database.Model):
class ShopInDB(database.Model):
__tablename__ = "builder_sites"
__table_args__ = {"extend_existing": True}

Expand Down Expand Up @@ -53,31 +54,18 @@ def submit_new_site_build(
when combined with domain, becomes abc.example.com
:param session: The serialized flask session data
"""
payload = {}
payload["version"] = 1
payload["users"] = [form.email.data]
payload["password"] = form.password.data
payload["login_token"] = login_token
company_name = form.company_name.data
payload["company"] = {"name": company_name, "logo": "", "start_image": ""}
# If possible, get country code and send to subscribie deployer
# Ref: https://github.com/Subscribie/module-builder/issues/33
payload["country_code"] = session.get("country_code", "GB")
payload["theme"] = {"name": "jesmond", "static_folder": "./static/"}

# Custom styles prepare as empty
payload["theme"]["options"] = {}
payload["theme"]["options"]["styles"] = []

# Pages as empty array
payload["pages"] = []

plans = []

postData = form.data
postData["users"] = [form.data.get("email", None)]
postData["version"] = 1
postData["login_token"] = login_token
postData["plans"] = []
postData["company"] = {"name": form.data.get("company_name", None)}

for index, plan in enumerate(form.title.data):
plan = {}
plan["uuid"] = str(uuid.uuid4())
plan["title"] = getPlan(form.title.data, index)
plan["sku"] = getPlan(form.title.data, index)
if getPlan(form.sell_price.data, index) is None:
plan["sell_price"] = 0
else:
Expand All @@ -93,7 +81,6 @@ def submit_new_site_build(
plan["interval_unit"] = getPlan(form.interval_unit.data, index)
plan["description"] = getPlan(form.description.data, index)
plan["subscription_terms"] = {"minimum_term_months": 12}
plan["primary_colour"] = "#e73b1a"
# Plan requirements
plan["requirements"] = {}
plan["requirements"]["instant_payment"] = getPlan(
Expand All @@ -103,16 +90,16 @@ def submit_new_site_build(
form.subscription.data, index
) # noqa: E501
plan["requirements"]["note_to_seller_required"] = False
plan["primary_icon"] = {"src": False, "type": False}
print(plan)
plans.append(plan)
payload["plans"] = plans
postData["plans"].append(plan)

shop = Shop(**postData)

# Save to json
json.dumps(payload)
with open(subdomain + ".json", "w") as fp:
fp.write(json.dumps(payload))
fp.write(json.dumps(postData))
deploy_url = app_config.get("JAMLA_DEPLOY_URL")
deployJamla(subdomain + ".json", deploy_url=deploy_url)
deploy(shop, deploy_url=deploy_url)

# Inform
try:
Expand Down Expand Up @@ -198,11 +185,9 @@ def journey_complete_subscriber(sender, **kw):


@builder.route("/sendJamla")
def deployJamla(filename, deploy_url=None):
with open(filename) as fp:
payload = json.loads(fp.read())
requests.post(deploy_url, json=payload)
return "Sent jamla file for deployment"
def deploy(shop, deploy_url=None):
requests.post(deploy_url, json=shop.json())
return "New shop deployment requested"


def create_subdomain_string(company_name=None):
Expand Down Expand Up @@ -245,7 +230,7 @@ def shop_owner_login():
@login_required
def shops():
"""List all shops"""
shops = Shop.query.all()
shops = ShopInDB.query.all()
shops = reversed(shops)
return render_template("shops.html", shops=shops)

Expand Down