def delete(self, project_id): g.abort_doesnt_exist(db, Project, Project.id, project_id) project = Project.query.get(project_id) if project is None: return g.get_res_data(rmg="プロジェクトが存在しません。"), 404 db.session.delete(project) db.session.commit() return g.get_res_data(rmg="削除しました。"), 200
def put(self, project_id): g.abort_doesnt_exist(db, Project, Project.id, project_id) data = request.get_json() res_title = data.get("title") project = Project.query.filter(Project.id == project_id).first() if project is None: return g.get_res_data(rmg="プロジェクトが存在しません。"), 404 project.title = res_title db.session.commit() project = Project.query.filter(Project.id == project_id).first() data = {**ProjectScheme().dump(project)} return g.get_res_data(rmg="編集しました。", data=data), 200
def delete(self): jti = get_raw_jwt()['jti'] try: RevokedTokenModel(jti=jti) return g.get_res_data(rmg='リフレシュトークンは取り消されました!'), 200 except: return {'rmg': 'サーバーエラーです。'}, 500
def delete(self): jti = get_raw_jwt()['jti'] try: RevokedTokenModel(jti=jti) return g.get_res_data(rmg='ログアウトしました!'), 200 except: return {'rmg': 'ログアウトエラーです。'}, 500
def get(self): current_user = get_jwt_identity() expires = datetime.timedelta(days=1) access_token = create_access_token(identity=current_user, expires_delta=expires) data = {'access_token': access_token} return g.get_res_data(data=data), 200
def post(self): data = request.get_json() res_email = data.get('email') res_password = data.get('password') cur_user = db.session.query(User).filter_by(email=res_email).first() email = cur_user and cur_user.to_dict()['email'] password = cur_user and cur_user.to_dict()['password'] if email is None: return g.get_err_msg('user', 'err2'), 400 # if User.verify_hash(res_password, password): if res_password == password: expires = datetime.timedelta(days=1) access_token = create_access_token(identity=res_email, expires_delta=expires) refresh_token = create_refresh_token(identity=res_email) userinfo = UserScheme().dump(cur_user) del userinfo['password'] _data = { **userinfo, 'access_token': access_token, 'refresh_token': refresh_token } data = dictUnderline2hump(_data) return g.get_res_data(rmg='ログイン成功しました!', data=data), 200 else: return g.get_err_msg('user', 'err3'), 400
def put(self, id): g.abort_doesnt_exist(db, User, User.id, id) data = request.get_json() res_name = data.get("name") user = db.session.query(User).filter(User.id == id).first() if user is None: return g.get_res_data(rmg="ユーザーIDが存在しません。"), 404 user.name = res_name db.session.commit() user = db.session.query(User).filter(User.id == id).first() data = {**UserScheme().dump(user)} return {**g.get_err_msg(), **{'data': data}}, 200
def post(self): data = request.get_json() res_title = data.get('title') id = ProjectScheme.get_cur_user_info(self) db.create(Project, title=res_title, user_id=id) project = Project.query.filter(Project.user_id == id).order_by( Project.id.desc()).first() if res_title == '': return g.get_res_data(rmg="タイトルがnullです"), 400 # プロジェクトに使うファイルを作成とか # project_files_service = ProjectFiles(project) # project_files_service.create() projects = Project.query.filter(Project.user_id == id).order_by( Project.id.desc()).all() _data = ProjectScheme().dump(projects, many=True) data = listUnderline2hump(_data) return get_res_data(data=data), 200