def get(self): print("id", current_user.get_id()) print(current_user.as_dict()) urls = db.session.query(Url).filter_by( user_id=current_user.get_id()).all() print(urls) return jsonify(urls_with_jsons(urls), { "user": current_user.as_dict(), "isLoggedIn": True })
def put(self): feed_url = request.json.get('url') if feed_url is None: abort(400) # missing arguments feed = Feed.objects(url=feed_url).first() if feed is None: try: res = requests.get(feed_url) except requests.exceptions.ConnectionError as e: return 'error fetching this feed: %s' % (e), 400 if not res.ok: return 'feed returned %s: %s' % (res.status_code, res.content), 400 if not res.headers.get('Content-Type', False) not in rss_and_atom_headers: return 'feed is not rss or atom: %s' % res.headers.get( 'Content-Type', False), 400 feed = Feed(url=feed_url) feed.save() if current_user not in feed.users: feed.users.append(current_user.id) feed.save() return current_user.as_dict()['feeds'], 201
def get(self, id): # a special case for checking whether an account exists # fix(soon): carefully throttle this endpoint if request.values.get('check_exists', False): try: u = User.query.filter(User.email_address == id).one() return {'exists': 1} except NoResultFound: try: u = User.query.filter(User.user_name == id).one() return {'exists': 1} except NoResultFound: return {'exists': 0} # normal user lookup elif current_user.is_authenticated: if current_user.id == id: return current_user.as_dict() elif current_user.role == current_user.SYSTEM_ADMIN: try: u = User.query.filter(User.id == id).one() except NoResultFound: abort(404) return u.as_dict() else: abort(403)
def _email_driver(carpool, current_user, subject, template_name_specifier): send_email( template_name_specifier, carpool.driver.email, subject, rider=current_user.as_dict(), carpool=carpool.as_dict(), )
def update_profile(): request_json: Json = request.get_json() user: User = User.query.filter_by(id=current_user.id).one() if request_json["name"]: user.name = request_json["name"] if request_json["color"]: user.color = request_json["color"] db.session.commit() return current_user.as_dict()
def get_songs(): query = session.query(Song).order_by(Song.name) songs = [row.as_dict() for row in query.all()] if request.is_json: return jsonify(songs) else: user = current_user.as_dict() return render_template("songs.html", user=user, songs=songs)
def settings(): org_users = OrganizationUser.query.filter( OrganizationUser.user_id == current_user.id) org_user_dicts = [] for org_user in org_users: org_user_dict = org_user.as_dict() org_user_dict['organization_full_name'] = json.loads( org_user.organization.system_attributes)['full_name'] org_user_dict['organization_name'] = org_user.organization.name org_user_dicts.append(org_user_dict) return render_template('users/settings.html', user_json=json.dumps(current_user.as_dict()), org_users=org_user_dicts)
def delete(self): feed_url = request.json.get('url', False) if request.json else False if not feed_url: feed_url = request.args.get('url', False) if not feed_url: abort(400) # missing arguments feed = Feed.objects(url=feed_url).first() if feed is None: abort(404) # feed not found Feed.objects(url=feed_url).update_one(pull__users=current_user.id) return current_user.as_dict()['feeds'], 201
def delete_user(user): # We get the user sesion_token from the session session_token = current_user.get_id() try: # We search for a user with the specified ID and with the same session_token as the one that made the request to_delete = session.query(User).filter( User.session_token == session_token, User.id == user).first() # Unexpected exception handling... except Exception as e: message = "Error... Try again" if request.is_json: return jsonify({"message": message}) else: return render_template('index.html', message=message, user=current_user.as_dict()) # If to_delete is None, the user does not exist or the user that made the request is not the same that we want to delete if to_delete is None: message = "User does not exist or you are not the user" if request.is_json: return jsonify({"message": message}) else: return render_template('index.html', message=message, user=current_user.as_dict()) # We logout the user from the session logout_user() # We delete the user from the database session.delete(to_delete) # And we commit the change to the db session.commit() message = "user deleted with success" if request.is_json: return jsonify({"message": message}) else: return render_template("login.html", message=message)
def put(self): feed_url = request.json.get('url') if feed_url is None: abort(400) # missing arguments feed = Feed.objects(url=feed_url).first() if feed is None: feed = Feed(url=feed_url) feed.save() if feed not in current_user.feeds: current_user.feeds.append(feed) current_user.save() return current_user.as_dict(), 201
def get_playlists(): #TODO Get method in models.playlis associated with user according to request.args order by Name | Creation Date | Size #Should default to ascending order by name A to Z # To order in sql alchemy: query = session.query(Playlist).filter(Playlist.user_id == current_user.get_id(token = False).ordery_by('Playlist.name')) #TODO Playlists only of user id query = session.query(Playlist).filter( Playlist.user_id == current_user.get_id(token=False)).order_by( Playlist.name) playlists = [row.__dict__ for row in query.all()] if request.is_json: return jsonify(playlists) else: user = current_user.as_dict() return render_template("playlists.html", user=user, playlists=playlists)
def get(self): return current_user.as_dict()['feeds'], 200
def get_profile_data() -> UserRecord: return current_user.as_dict()
def user_info(idx): # TODO user_dict = current_user.as_dict() del user_dict['password'], user_dict['id'] return jsonify(user_dict)
def get_current_user(): response = current_user.as_dict() return jsonify(response)
def get(self): return current_user.as_dict(), 200
def main(): user_token = current_user.as_dict() return render_template('index.html', user=user_token)
def get_current_user(): return current_user.as_dict()
def user_account(user): session = current_user.as_dict() if user == session['id']: return render_template("user.html", user=session) else: return make_response("Unauthorized", 401)