From b4e7acc5db6fb0653d85782bd72786290f97fc06 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Thu, 25 Jan 2024 17:20:13 -0600 Subject: [PATCH] adding signup to parser --- config.json | 13 +++++++--- www/parser/_plugins/store.py | 16 +++++++++---- www/parser/_plugins/users.py | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 www/parser/_plugins/users.py diff --git a/config.json b/config.json index b42636c..b6e2b4e 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "system":{ - "logo":"logo.svg","context":"", "theme":"oss.css", + "logo":"www/parser/_images/cog-red.png","context":"", "theme":"oss.css", "app":{ "debug":true,"port":8000}, @@ -9,12 +9,19 @@ "id":"cloud", "auth":"nextcloud-auth.json", "store":"/home/steve/git/sites/parser/store-auth.json" + }, + "routes":{ + "data-transport":{ + "menu":"tools", + "path":"/home/steve/git/sites/data-transport/config.json" + } } }, "plugins":{ - "store":["init","plans"] + "store":["init","plans"], + "users":["signup"] }, "layout":{ "header":{"title":"{x12} Parser :: Healthcare/IO","logo":true,"subtitle":"Open, Simple & Extensible - Powered by data-transport"}, @@ -22,7 +29,7 @@ "root":"www/parser", "index":"index.html", "order":{ - "menu":["resources","about"] + "menu":["tools","resources","about"] }, "overwrite":{ "license":{ diff --git a/www/parser/_plugins/store.py b/www/parser/_plugins/store.py index 3fcc862..f3da5a2 100644 --- a/www/parser/_plugins/store.py +++ b/www/parser/_plugins/store.py @@ -39,9 +39,15 @@ def plans (**_args) : _features = _features.sort_values(by=[_key],ascending=False) _lrow = pd.DataFrame([dict(zip(columns,pricing))],index=['']) - _df = pd.concat([_features,_lrow]) + _df = _features + # _df = pd.concat([_features,_lrow]) return _df.to_json() - # _df[_plan['nickname']] = _features.values - # _df.index = list(_features.keys()) - # print (pd.DataFrame(_df)) - # return json.dumps([_plan for _plan in .. if _plan['active'] == True]) + +def signup (**_args): + _email = _args['email'] + _name = None if 'name' in _args else _args['name'] + product = store.get.product('healthcareio') + # + # If the user is already signed up + customer = store.get.customer(_email) + diff --git a/www/parser/_plugins/users.py b/www/parser/_plugins/users.py new file mode 100644 index 0000000..d2ed98d --- /dev/null +++ b/www/parser/_plugins/users.py @@ -0,0 +1,46 @@ +import store +import json +import os +def __init__ (**_args): + _path = _args['config']['system']['source']['store'] + if not store.isready() : + if os.path.exists(_path) : + f = open(_path) + _info = json.loads(f.read()) + f.close() + store.init(_info['secret']) + return "1" + else: + return "0" + else: + return "1" + +def signup(**_args): + """ + This function creates or pulls a customer's key from the backend (stripe) + """ + if not store.isready() : + __init__(**_args) + _email = _args['email'] + _customer = store.get.customer(_email) + _user = {} + if not _customer : + # + # Create/add a new user information to the backend + _customer = store.set.customer(_email,'') + plans = store.get.plans('healthcareio') + plans = [plan for plan in plans if plan.amount == 0] + plan = plans[0] + # + # signup to free plan + store.set.subscribe(_customer.id,plan.id) + if _customer : + _customer = _customer[0] + _user['email'] = _email + _user['token'] = _customer['id'] + + return json.dumps(_user) + +def upgrade (**_args): + pass +