activate functions

This commit is contained in:
deflax 2017-07-14 16:00:04 +03:00
parent 85cdfef330
commit 41082f7808
5 changed files with 49 additions and 30 deletions

8
app/dmanager/forms.py Normal file
View file

@ -0,0 +1,8 @@
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
from wtforms import validators, ValidationError
from wtforms.fields.html5 import EmailField
class ActivateForm(FlaskForm):
period = SelectField('Domain Period', choices=[('1 Year', 12), ('2 Years', 24)])
submit = SubmitField('Activate')

View file

@ -24,21 +24,21 @@ def activate(itemid=0):
flash('Insufficient Funds') flash('Insufficient Funds')
return redirect(url_for('uinvoice.addfunds')) return redirect(url_for('uinvoice.addfunds'))
#work with disabled items only #work with disabled deploys only
result = current_user.inv_domains.filter_by(enabled=False) result = current_user.inv_domains.all()
inventory = [] inventory = []
for invcls in result: for invcls in result:
inventory.extend([invcls.pid]) inventory.extend([invcls.pid])
#checks if current user owns this item
if not itemid in inventory: if current_user.is_administrator():
current_app.logger.info('[ADMIN] Access override for domain id:{}'.format(itemid))
elif not itemid in inventory:
current_app.logger.warning('[{}] Access violation with domain id: {}'.format(current_user.email, itemid)) current_app.logger.warning('[{}] Access violation with domain id: {}'.format(current_user.email, itemid))
#TODO: log ips
abort(404) abort(404)
else:
current_app.logger.info('[{}] Disabled services: {}'.format(current_user.email, inventory))
abort(403)
#if current_user.confirmed and form.validate_on_submit(): #current_app.logger.info('[{}] Disabled deployments: {}'.format(current_user.email, inventory))
# client_id = current_user.pid form = ActivateForm(period=Domain.query.filter_by(pid=itemid))
return render_template('dmanager/activate.html', page=page, form=form) if current_user.confirmed and form.validate_on_submit():
current_app.logger.info('payment')
return render_template('dmanager/activate.html', form=form, itemid=itemid)

8
app/smanager/forms.py Normal file
View file

@ -0,0 +1,8 @@
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
from wtforms import validators, ValidationError
from wtforms.fields.html5 import EmailField
class ActivateForm(FlaskForm):
period = SelectField('Service Period', choices=[('1 Month', 1), ('3 Months', 3), ('6 Months', 6), ('1 Year', 12), ('2 Years', 24)])
submit = SubmitField('Activate')

View file

@ -24,22 +24,21 @@ def activate(itemid=0):
flash('Insufficient Funds') flash('Insufficient Funds')
return redirect(url_for('uinvoice.addfunds')) return redirect(url_for('uinvoice.addfunds'))
#work with disabled items only #work with disabled deploys only
result = current_user.inv_services.all() result = current_user.inv_services.all()
current_app.logger.info(result)
inventory = [] inventory = []
for invcls in result: for invcls in result:
inventory.extend([invcls.pid]) inventory.extend([invcls.pid])
#checks if current user owns this item
if not itemid in inventory: if current_user.is_administrator():
current_app.logger.info('[ADMIN] Access override for service id:{}'.format(itemid))
elif not itemid in inventory:
current_app.logger.warning('[{}] Access violation with service id: {}'.format(current_user.email, itemid)) current_app.logger.warning('[{}] Access violation with service id: {}'.format(current_user.email, itemid))
#TODO: log ips
abort(404) abort(404)
else:
current_app.logger.info('[{}] Disabled services: {}'.format(current_user.email, inventory))
abort(403)
#if current_user.confirmed and form.validate_on_submit(): #current_app.logger.info('[{}] Disabled deployments: {}'.format(current_user.email, inventory))
# client_id = current_user.pid form = ActivateForm(period=Service.query.filter_by(pid=itemid))
return render_template('smanager/activate.html', page=page, form=form) if current_user.confirmed and form.validate_on_submit():
current_app.logger.info('payment')
return render_template('smanager/activate.html', form=form, itemid=itemid)

View file

@ -117,9 +117,13 @@ def deploy(product_id=None):
return render_template('vmanager/deploy.html', page=page, form=form, product_id=product_id, product_pic=product_pic, product_name=product_name, product_description=product_description, product_recipe=product_recipe) return render_template('vmanager/deploy.html', page=page, form=form, product_id=product_id, product_pic=product_pic, product_name=product_name, product_description=product_description, product_recipe=product_recipe)
@vmanager.route('/activate/<int:vmid>') @smanager.route('/activate/<int:itemid>', methods=['GET', 'POST'])
@login_required @login_required
def activate(vmid=0): def activate(itemid=0):
if current_user.wallet < 1:
flash('Insufficient Funds')
return redirect(url_for('uinvoice.addfunds'))
#work with disabled deploys only #work with disabled deploys only
result = current_user.inv_deployments.all() result = current_user.inv_deployments.all()
inventory = [] inventory = []
@ -127,16 +131,16 @@ def activate(vmid=0):
inventory.extend([invcls.machine_id]) inventory.extend([invcls.machine_id])
if current_user.is_administrator(): if current_user.is_administrator():
current_app.logger.info('[ADMIN] Access override for cube id:{}'.format(vmid)) current_app.logger.info('[ADMIN] Access override for deployment id:{}'.format(itemid))
elif not vmid in inventory: elif not itemid in inventory:
current_app.logger.warning('[{}] Access violation with cube id: {}'.format(current_user.email, vmid)) current_app.logger.warning('[{}] Access violation with deployment id: {}'.format(current_user.email, itemid))
abort(404) abort(404)
#current_app.logger.info('[{}] Disabled deployments: {}'.format(current_user.email, inventory)) #current_app.logger.info('[{}] Disabled deployments: {}'.format(current_user.email, inventory))
form = ActivateForm(period=Deployment.query.filter_by(machine_id=vmid)) form = ActivateForm(period=Deployment.query.filter_by(machine_id=itemid))
if current_user.confirmed and form.validate_on_submit(): if current_user.confirmed and form.validate_on_submit():
current_app.logger.info('meh') current_app.logger.info('payment')
return render_template('vmanager/activate.html', form=form, vmid=vmid) return render_template('vmanager/activate.html', form=form, itemid=itemid)
@vmanager.route('/<cmd>/<int:vmid>') @vmanager.route('/<cmd>/<int:vmid>')
@login_required @login_required