How to use the flask.session.get function in Flask

To help you get started, we’ve selected a few Flask examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OmegaTrading / OmegaUI / omega_ui / socket_logging.py View on Github external
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']})
github freezingsaddles / freezing-web / freezing / web / views / user.py View on Github external
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.
github southampton / cortex / lib / core.py View on Github external
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
github liwanlei / FXTest / app / home / views.py View on Github external
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'))
github matkam11 / plex-visualizer / plex_vis.py View on Github external
@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)
github globocom / secDevLabs / owasp-top10-2017-apps / a10 / games-irados / app / routes.py View on Github external
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')
github govau / notify / admin / app / __init__.py View on Github external
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
github lucahammer / WischWasch / default / main / auth / twitter.py View on Github external
def get_twitter_token():
  return flask.session.get('oauth_token')
github llvm-mirror / lnt / lnt / server / ui / views.py View on Github external
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
    }
github MrFu1998 / bbs / bbs.py View on Github external
def post_before_request():
    id = flask.session.get(constants.FRONT_SESSION_ID)
    if id:
        user = FrontUser.query.get(id)
        flask.g.front_user = user