def delete_index(username): user = Users.get(username) if user: current_user.delete_index() EventLogger.new_event(msg="index for {} deleted".format(user.id)) return "index for {} deleted".format(username) else: return "no user {}".format(username)
def delete(username): user = Users.get(username) username = user.username user_id = user.id logout_user() # the current user is now logged out try: user.delete() except Exception as e: flash(str(e)) else: flash("user '{}' ({}) deleted".format(username, user_id)) EventLogger.new_event(msg="{} deleted".format(user_id)) return redirect(url_for("splash"))
def auth_callback(): state = request.args.get("state") if "error" in request.args: flash("Error: {}".format(request.args.get("error"))) if current_user.is_anonymous: args = { "code": request.args.get("code"), "client_id": app.config["STRAVA_CLIENT_ID"], "client_secret": app.config["STRAVA_CLIENT_SECRET"] } client = stravalib.Client() try: access_token = client.exchange_code_for_token(**args) except Exception as e: log.error("authorization error:\n{}".format(e)) flash(str(e)) return redirect(state) user_data = Users.strava_data_from_token(access_token) # log.debug("user data: {}".format(user_data)) try: user = Users.add_or_update(**user_data) except Exception as e: log.exception(e) user = None if user: # remember=True, for persistent login. login_user(user, remember=True) # log.debug("authenticated {}".format(user)) EventLogger.new_event(msg="authenticated {}".format(user.id)) else: log.error("user authenication error") flash("There was a problem authorizing user") return redirect( request.args.get("state") or url_for("main", username=user.id))
def main(username): if current_user.is_authenticated: # If a user is logged in from a past session but has no record in our # database (was deleted), we log them out and consider them anonymous try: assert current_user.id except AssertionError: logout_user() else: current_user.update_usage() user = None key = username if redis.get("Q:" + username) else "" if not key: # note: 'current_user' is the user that is currently logged in. # 'user' is the user we are displaying data for. user = Users.get(username) if not user: flash("user '{}' is not registered with this app".format(username)) return redirect(url_for('splash')) date1 = request.args.get("date1") or request.args.get("after", "") date2 = request.args.get("date2") or request.args.get("before", "") preset = request.args.get("preset", "") limit = request.args.get("limit", "") baselayer = request.args.getlist("baselayer") ids = request.args.get("id", "") group = "multi" if key else request.args.get("group", "") if not ids: if (not date1) and (not date2): if preset: try: preset = int(preset) except ValueError: flash("'{}' is not a valid preset".format(preset)) preset = 7 elif limit: try: limit = int(limit) except ValueError: flash("'{}' is not a valid limit".format(limit)) limit = 1 elif group: pass else: limit = 10 c1 = request.args.get("c1", "") c2 = request.args.get("c2", "") sz = request.args.get("sz", "") lat = request.args.get("lat") lng = request.args.get("lng") zoom = request.args.get("zoom") autozoom = request.args.get("autozoom") in ["1", "true"] if (not lat) or (not lng): lat, lng = app.config["MAP_CENTER"] zoom = app.config["MAP_ZOOM"] autozoom = "1" if current_user.is_anonymous or (not current_user.is_admin()): event = { "ip": request.access_route[-1], "agent": vars(request.user_agent), "msg": Utility.href(request.url, request.full_path) } if not current_user.is_anonymous: event.update({ "profile": current_user.profile, "cuid": current_user.id }) EventLogger.new_event(**event) paused = request.args.get("paused") in ["1", "true"] return render_template('main.html', user=user, lat=lat, lng=lng, zoom=zoom, ids=ids, group=group, key=key, preset=preset, date1=date1, date2=date2, limit=limit, autozoom=autozoom, paused=paused, baselayer=baselayer, c1=c1, c2=c2, sz=sz)