def get_inviteable_user(ag_name, ag): query = request.values.get('query', default='') users = db.session.query(User).join( UserAG, and_(UserAG.ag_id == ag.id, UserAG.user_id == User.id), isouter=True).filter( or_((and_(UserAG.ag_id == None, User.username.like(f'%{query}%'))), (and_( UserAG.ag_id == ag.id, UserAG.role == 'NONE', or_(UserAG.status == 'LEFT', UserAG.status == 'REJECTED', UserAG.status == 'APPLIED'), User.username.like(f'%{query}%'))))) users_schema = UserSchema(many=True) return users_schema.jsonify(users)
def get(self): current_user = get_jwt_identity() user = User.find_by_email(current_user) try: info_schema = UserSchema() data = info_schema.dump(user) return make_response( jsonify({ 'status': 200, 'data': data, 'msg': "Personal Information Updated" }), 200) except Exception: return make_response( jsonify({ 'status': 500, 'msg': "Internal server error" }), 500)
import re from datetime import datetime from flask_jwt import jwt_required from sqlalchemy.exc import SQLAlchemyError from flask_restful import Resource, reqparse from flask import request from app import db from app.models.user import User, UserSchema, UserTypesEnum from app.models.room import Room, RoomUser from app.utils import response, rollback schema = UserSchema() def check_args(args): _args = args.copy() check = all(_args.values()) # verifica se os campos não estão vazios if check: email_re = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)" check = False if not re.findall(email_re, args["email"]) else True return check def get_args(): parser = reqparse.RequestParser() parser.add_argument("name", type=str, location="json", required=True) parser.add_argument("uid", type=str, location="json", required=True) parser.add_argument("userType", type=str, location="json", required=True) parser.add_argument("email", type=str, location="json", required=True)
from flask import request from flask_restful import Resource from app.models.user import User as UserModel, UserSchema from app.models.notebook import Notebook as NotebookModel, NotebookSchema from app.models.reading import Reading as ReadingModel, ReadingSchema, ReadingNotebookSchema from flask_jwt_extended import ( jwt_required ) user_schema = UserSchema() notebook_list_schema = NotebookSchema(many=True) reading_list_schema = ReadingSchema(many=True) reading_notebook_list_schema = ReadingNotebookSchema(many=True) class User(Resource): @classmethod def get(cls, id): user = UserModel.find_by_id(id) if not user: return {'message':'User not found'}, 400 return user_schema.dump(user), 200 class UserNotebooks(Resource): @classmethod def get(cls,id): user = UserModel.find_by_id(id) if not user: return {'message':'User not found'}, 400 return {"notebooks": notebook_list_schema.dump(NotebookModel.find_all_by_user(id))}, 200 class UserReadings(Resource):
from flask_restful import Resource from flask import request from app import api from flask_jwt_extended import (get_jwt_identity, get_jwt_claims, jwt_required, get_raw_jwt) from app.models.user import UserSchema, UserModel from app.models.organisation import OrganisationModel, OrganisationSchema user_schema = UserSchema() user_schema_list = UserSchema(many=True) class User(Resource): @jwt_required def get(self, uuid): user = UserModel.find_by_uuid(uuid) if user: return {"user": user_schema.dump(user)}, 200 return {"message": "No user found"}, 404 @jwt_required def put(self, uuid): user = UserModel.find_by_uuid(uuid) if user: return {"user": user_schema.dump(user)}, 200 return {"message": "No user found"}, 404
from flask import request, jsonify from flask_restful import Resource, abort from app.extensions import api,db, KEY from app.models.user import User, UserSchema user_schema = UserSchema(many = True) class UserAPI(Resource): def get(self): try: if request.json['key'] == KEY: users = User.query.all() res = user_schema.dump(users) return jsonify(res) except: abort(404, message="Not authorized.") def put(self): try: if request.json['key'] == KEY: new_data = User(request.json) db.session.add(new_data) db.session.commit() res = user_schema.dump([new_data]) return jsonify(res) except: abort(404, message="Can't add new user.") def post(self): res = {'user':'', 'login':'******', 'level':''}
def get(self, uid): user = User.query.get_or_404(uid) data = UserSchema().dump(user) return Success(data=data)
def get(self): users = User.query.all() data = UserSchema(many=True).dump(users) return Success(data=data)
async def post(payload: UserSchema): payload.dict()["dob"] = datetime.strptime(payload.dob, '%d-%b-%Y') query = user.insert(), [payload.dict()] return await database.execute(query=query)
def get(self): user = User.query.get(g.user.uid) data = UserSchema().dump(user) return Success(data=data)