def store(): try: name = request.form['name'] email = request.form['email'] password = request.form['password'] users = Users(name=name, email=email) users.setPassword(password) db.session.add(users) db.session.commit() return response.ok([], 'Successfully create data') except Exception as e: print(e) return response.ok([], 'Failed, user is exist')
def login(): try: email = request.form['email'] password = request.form['password'] user = Users.query.filter_by(email=email).first() if not user: return response.badRequest([], 'Empty...') if not user.checkPassword(password): return response.badRequest([], 'Password is wrong') data = _singleTransform(user, withTodo=False) # jwt config expires = timedelta(days=1) expires_refresh = timedelta(days=3) access_token = create_access_token(data, fresh=True, expires_delta=expires) refresh_token = create_refresh_token(data, expires_delta=expires_refresh) # jwt return response.ok({ "data": data, "token_access": access_token, "token_refresh": refresh_token }, 'Success signin') except Exception as e: print(e) return response.badRequest([], 'Params is failed')
def index(): try: users = Users.query.all() data = _transform(users) return response.ok(data, "success") except Exception as e: print(e) return response.badRequest([], 'failed')
def index(): try: id = request.args.get('user_id') todo = Todo.query.filter_by(user_id=id).all() data = transform(todo) return response.ok(data, "") except Exception as e: print(e)
def show(id): try: users = Users.query.filter_by(id=id).first() if not users: return response.badRequest([], 'Empty..') data = _singleTransform(users) return response.ok(data, "success") except Exception as e: print(e) return response.badRequest([], 'failed')
def show(id): try: todo = Todo.query.filter_by(id=id).first() if not todo: return response.badRequest([], 'Empty....') data = singleTransform(todo) return response.ok(data, "") except Exception as e: print(e)
def refresh(): try: user = get_jwt_identity() new_token = create_access_token(identity=user, fresh=False) return response.ok({ "token_access": new_token }, "successfully refresh token") except Exception as e: print(e) return response.badRequest([], 'Failed refresh token')
def delete(id): try: user = Users.query.filter_by(id=id).first() if not user: return response.badRequest([], 'Users didn\' found') db.session.delete(user) db.session.commit() return response.ok([], 'Successfully delete') except Exception as e: print(e)
def delete(id): try: todo = Todo.query.filter_by(id=id).first() if not todo: return response.badRequest([], 'Empty....') db.session.delete(todo) db.session.commit() return response.ok('', 'Successfully delete data!') except Exception as e: print(e)
def store(): try: todo = request.json['todo'] desc = request.json['description'] user_id = request.json['user_id'] todo = Todo(user_id=user_id, todo=todo, description=desc) db.session.add(todo) db.session.commit() return response.ok('', 'Successfully create todo!') except Exception as e: print(e)
def update(id): try: todo = request.json['todo'] desc = request.json['description'] todo = Todo.query.filter_by(id=id).first() todo.todo = todo todo.description = desc db.session.commit() return response.ok('', 'Successfully update todo!') except Exception as e: print(e)
def update(id): try: name = request.form['name'] email = request.form['email'] password = request.form['password'] user = Users.query.filter_by(id=id).first() user.email = email user.name = name user.setPassword(password) db.session.commit() return response.ok('', 'Successfully update data!') except Exception as e: print(e)