diff --git a/src/api/index.py b/src/api/index.py index 7d4ed79..6aea82e 100755 --- a/src/api/index.py +++ b/src/api/index.py @@ -72,77 +72,22 @@ def init(product): for id in sub : if sub[id]['active'] is True : features[id] = sub[id] + session['active-plans'] = [item['plan_id'] for item in features] user.refresh(uid) session['key'] = user.user_key session['uid'] = uid return json.dumps(features),200 -# @app.route("/init/",methods=['POST']) -# def init(app_name): -# plans = [] -# handler = None -# uid = request.headers['uid'] -# plan = request.headers['pid'] -# auid = None -# if 'uid' in request.headers and 'auid' not in request.headers: -# id = uid -# #couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=uid,create=False) -# #DB = couchdb.dbase -# if 'auid' in request.headers : -# auid = request.headers['auid'] -# auid = json.loads(auid)if auid.startswith('[') else auid -# if isinstance(auid,list) : -# auid = list(set(auid) - set([uid])) -# if len(auid) == 0: -# auid = None -# id = uid -# else: -# auid = auid[0] -# id = auid -# couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=id,create=False) -# DB = couchdb.dbase -# #handler.update_user(id=handler.getId(auid),uid=uid) - -# handler = Domain.User(DB,stripe) ; -# if auid is None : -# handler.init(uid,plan) ; -# else: -# if couchdb.isready() == False: -# handler.init(auid,plan) -# id = handler.getId(uid) - -# handler.initialize(auid) -# id = handler.getId(auid) -# handler.update_user(id=id,uid=uid) ; - -# plans = handler.plans() -# #return json.dumps(plans) -# _features = features(app_name) -# return _features -""" - This function will update the user's email -""" -# @app.route('/init/',methods=['PUT']) -# def init_update(app_name): -# uid = request.headers['uid'] -# id = session['customer.id'] -# couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=None) -# DB = couchdb.dbase -# handler = Domain.User(DB,stripe) -# handler.update_user(uid=uid,id=id) - -# return ('',204) - - -""" - This function subscribes a user to a given service for an application - This function guarantees not to duplicate subscriptions - @resource name name of the application {cloud-music} - @header key service/plan -""" @app.route('/subscribe/',methods=['POST']) def subscribe(product): + """ + This function subscribes a user to a given service for an application + This function guarantees not to duplicate subscriptions + @resource name name of the application {cloud-music} + @header key service/plan + """ + # # The name is the full name of the service # @@ -174,7 +119,8 @@ def subscribe(product): #session['plans'] = plans session['key'] = user.user_key session['uid'] = uid - + session['active-plans'] = [item['id'] for item in plans] + print session['active-plans'] return (json.dumps(plans),200) def get_plans(product) : @@ -264,11 +210,21 @@ def signup(product) : # # @TODO: Mark the plans the current user is signed up for # + if 'themes' in CONFIG: + theme = CONFIG['themes'][product] if product in CONFIG['themes'] else CONFIG['theme']['default'] + else: + theme = '' platform='web' if 'platform' not in request.args else request.args['platform'] alias = plans[0]['product_alias'] - active_plan = session['plans'] if 'plans' in session else [] - print [' ** ',uid,active_plan] - return render_template('subscribe.html',context=CONTEXT,uid=uid,alias=alias,platform=platform,app_name=product,plans=plans,apikey=apikey) + if 'user-plan' in session : + user_plans = [item['id'] for item in session['user-plan']] + else : + user_plans = [] + # active_plan = session['active-plans'] if 'active-plans' in session else [] + args = {"context":CONTEXT,"theme":theme,"uid":uid,"alias":alias,"platform":platform,"app_name":product,"apikey":apikey,"plans":plans} + args['active_plans'] = user_plans + + return render_template('subscribe.html',**args) #context=CONTEXT,uid=uid,alias=alias,platform=platform,app_name=product,plans=plans,apikey=apikey) @app.route('/subscribe/',methods=['DELETE']) def cancel_subscribe(name) : diff --git a/src/api/templates/subscribe.html b/src/api/templates/subscribe.html index b69b217..7a877c4 100755 --- a/src/api/templates/subscribe.html +++ b/src/api/templates/subscribe.html @@ -8,19 +8,73 @@ --> + {{app_name.replace('-',' ')}}