Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def login():
form = LoginForm()
if form.validate_on_submit():
try:
user_token = client.login(form['username'].data, form['password'].data)
if not validate_permissions(user_token['perms']):
perms = REQUIRED_PERMISSIONS
msg = 'Invalid permissions, saltpad needs {0} for user {1}'.format(perms, form['username'].data)
flash(msg, 'error')
else:
session['username'] = form['username'].data
session['user_token'] = user_token['token']
flash('Hi {0}'.format(form['username'].data))
return redirect(request.args.get("next") or url_for("index"))
except Unauthorized:
flash('Invalid credentials', 'error')
return render_template("login.html", form=form)
def edit(container=None):
"""
edit containers page and actions if form post request
"""
host_memory = lwp.host_memory_usage()
cfg = lwp.get_container_settings(container)
if request.method == 'POST':
form = request.form.copy()
if form['bucket'] != get_bucket_token(container):
g.db.execute("INSERT INTO machine(machine_name, bucket_token) VALUES (?, ?)", [container, form['bucket']])
g.db.commit()
flash(u'Bucket config for %s saved' % container, 'success')
# convert boolean in correct value for lxc, if checkbox is inset value is not submitted inside POST
form['flags'] = 'up' if 'flags' in form else 'down'
form['start_auto'] = '1' if 'start_auto' in form else '0'
# if memlimits/memswlimit is at max values unset form values
if int(form['memlimit']) == host_memory['total']:
form['memlimit'] = ''
if int(form['swlimit']) == host_memory['total'] * 2:
form['swlimit'] = ''
def mod_bans():
ban_messages = []
if request.method == 'POST':
ban_form = BanForm(request.form)
if ban_form.validate():
ip4 = parse_ip4(ban_form.ban_ip4.data)
ip4_end_form = ban_form.ban_ip4_end.data
ip4_end = parse_ip4(ip4_end_form) if ip4_end_form else None
ban = BanModel()
ban.ip4 = ip4
if ip4_end is not None:
ban.ip4_end = ip4_end
ban.reason = ban_form.reason.data
board_form = ban_form.board.data
ban.board = board_form if board_form else None
ban.length = ban_form.duration.data * 60 * 60 * 1000
try:
ban_service.add_ban(ban)
def track_download(self, event, resource, **kwargs):
tracker = PiwikQueryTrackDownload()
resource_url = request.url if isinstance(resource, LocalFile) else resource.getURL()
resource_title = resource.getFileName() if isinstance(resource, LocalFile) else resource.getURL()
resource_title = 'Download - {}'.format(resource_title)
tracker.call(resource_url, resource_title)
def signin():
username = request.form['username']
password = request.form['password']
error = None
if len(username) < 5:
error = 'Username must be at least 5 characters'
if len(password) < 6:
error = 'Password must be at least 8 characters'
elif not any(c.isupper() for c in password):
error = 'Your password needs at least 1 capital'
if error is not None:
return jsonify({'r': 1, 'error': error})
return jsonify({'r': 0, 'rs': 'Ok'})
def restrict_to_role(role):
if current_user.is_anonymous:
flash('You are trying to access a protected area. Please log in first.', 'error')
return redirect(url_for('account.login', next=request.url))
if not current_user.has_role(role):
flash('You do not have permission to access this area of the site.', 'error')
return redirect(url_for('doaj.home'))
def add_at_prefix():
r = request.get_json()
if r is not None:
keys = ['id', 'type']
for key in keys:
if r.get(key, False):
r['@'+key] = r.pop(key)
def is_organisation_name_unique():
organisation_id, name = check_request_args(request)
name_exists = Organisation.query.filter(Organisation.name.ilike(name)).first()
result = (not name_exists) or str(name_exists.id) == organisation_id
return jsonify(result=result), 200
domain_data=domain_data,
all_data=constants.DOMAIN_DATA,
site_tutorial_links=site_links,
tutorial_data=current_tutorial_data,
tutorial_data_json=json.dumps(current_tutorial_data),
domain_data_json=json.dumps(domain_data),
html_title=html_title,
language_code=language,
languages=get_languages(),
language_names=get_language_names(),
uid=uid,
**current_tutorial_data
))
# POST method handling
data = run_code(request.json["code"], domain_data["language_id"])
if "output" in current_tutorial_data and current_tutorial_data["output"] == data["output"]:
data["solved"] = True
else:
data["solved"] = False
return make_response(json.dumps(data))