def api_v1_users(): user_id = request.args.get("id") if user_id: if user_id == "me": return jsonify(act.user(pointer=g.USER.id).serialize) try: user = act.user(pointer=user_id) return jsonify(user.serialize) except BaseException: return jsonify(error="NOT FOUND"), 404 else: return jsonify(all_users=[user.serialize for user in act.all_users()])
def profileNested(pointer): try: # Fetch the data from database user = act.user(pointer=pointer) return render_template( "profile.html", categories=act.categories(user_id=user.id), items=act.items(For="user", pointer=user.id), user=user, ) except BaseException: return redirect(url_for("notFound"))
def profile(username): try: try: # Check that it's not a user id # to make sure it's only allowed # to pass usernames after the root directory int(username) return redirect(url_for("notFound")) except BaseException: # Fetch the data from database user = act.user(pointer=username) return render_template( "profile.html", categories=act.categories(user_id=user.id), items=act.items(For="user", pointer=user.id), user=user, ) except BaseException: return redirect(url_for("notFound"))
def global_variables(): """ global variables for templates environment """ item_catalog_app.jinja_env.globals["ALL_CATEGORIES"] = act.all_categories() __logged_in_user__ = act.user(pointer=login_session.get("user_id")) item_catalog_app.jinja_env.globals["USER"] = __logged_in_user__ g.USER = __logged_in_user__
def verify_access_token(access_token, password): user_id = User.verify_auth_token(access_token) if user_id: user = act.user(pointer=user_id) g.USER = user return True