Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_message(message):
flask.session['receive_count'] = flask.session.get('receive_count', 0) + 1
pool.spawn(background_thread, message['data'])
fsio.emit('log_response', {'data': message['data'], 'count': flask.session['receive_count']})
def ride_refetch_photos():
ride_id = request.form["id"]
ride = (
meta.scoped_session()
.query(Ride)
.filter(Ride.id == ride_id)
.filter(Ride.athlete_id == session.get("athlete_id"))
.one()
)
ride.photos_fetched = False
logging.info("Marking photos to be refetched for ride {}".format(ride))
meta.scoped_session().commit()
return jsonify(success=True) # I don't really have anything useful to spit back.
username: The username. Defaults to None, which will use the username from session.
related_id: An ID of the element in a table this event refers to. Defaults to None.
success: Was this 'event' succcessful? Generally, you don't need to use this. Defaults to True.
Returns:
Nothing
Raises:
Nothing
"""
if not source.startswith("cortex."):
source = "cortex." + source
if username is None:
username = session.get('username', None)
if success:
status = 1
else:
status = 2
app.logger.info(str(source) + ',' + str(related_id) + ',' + str(name) + ',' + str(username) + ',' + str(desc))
try:
cur = g.db.cursor()
stmt = 'INSERT INTO `events` (`source`, `related_id`, `name`, `username`, `desc`, `status`, `ipaddr`, `start`, `end`) VALUES (%s, %s, %s, %s, %s, %s, %s, NOW(), NOW())'
params = (source, related_id, name, username, desc, status, request.remote_addr)
cur.execute(stmt, params)
g.db.commit()
except Exception:
pass
def get(self):
username = session.get("username")
session.clear()
logout_user()
user = User.query.filter_by(username=username).first()
user.is_login = False
db.session.add(user)
db.session.commit()
return redirect(url_for('home.login'))
@app.route('/regen')
def regen(force=False):
username = ""
if (session.get('logged_in') and session['username'] == app.config["ADMIN"]) or force:
print("Logged In!")
db = get_db()
movies = get_movies(db, username)
tv = get_tv(db, username)
output = { "loggedIn": False, "Movies": movies,"TV": tv}
datafile = app.root_path + "/data/notLoggedIn.json"
with open(datafile, 'w') as outfile:
json.dump(output, outfile, indent=4)
datafile = datafile.replace(app.root_path,"")
if force:
return datafile
return render_template('index.html',data=datafile)
else:
abort(401)
def generate_csrf_token():
'''
Generate csrf token and store it in session
'''
if '_csrf_token' not in session:
session['_csrf_token'] = str(uuid.uuid4())
return session.get('_csrf_token')
def load_service_before_request():
if '/static/' in request.url:
_request_ctx_stack.top.service = None
return
if _request_ctx_stack.top is not None:
_request_ctx_stack.top.service = None
if request.view_args:
service_id = request.view_args.get('service_id', session.get('service_id'))
else:
service_id = session.get('service_id')
if service_id:
try:
_request_ctx_stack.top.service = service_api_client.get_service(service_id)['data']
except HTTPError as exc:
# if service id isn't real, then 404 rather than 500ing later because we expect service to be set
if exc.status_code == 404:
abort(404)
else:
raise
def get_twitter_token():
return flask.session.get('oauth_token')
def ts_data(ts):
"""Data about the current testsuite used by layout.html which should be
present in most templates."""
baseline_id = flask.session.get(baseline_key())
baselines = request.session.query(ts.Baseline).all()
return {
'baseline_id': baseline_id,
'baselines': baselines,
'ts': ts
}
def post_before_request():
id = flask.session.get(constants.FRONT_SESSION_ID)
if id:
user = FrontUser.query.get(id)
flask.g.front_user = user