예제 #1
0
 def post(self, login_args):
     user = User.query.filter_by(email=login_args['email']).first()
     if user is None:
         return error_object('Bad username or password', 401)
     if not user.validate_password(login_args['password']):
         return error_object('Bad username or password', 401)
     access_token = create_access_token(identity=user)
     return make_response(jsonify(access_token=access_token), 200)
예제 #2
0
 def put(self, user_args, id):
     user = User.query.get(id)
     if user is None:
         return error_object('User not found', 404)
     for key, value in user_args.items():
         setattr(user, key, value)
     try:
         db.session.add(user)
         db.session.commit()
     except IntegrityError:
         return error_object('Email already registered', 422)
     return UserSchema().dump(user).data, 200
예제 #3
0
 def delete(self, id):
     user = User.query.get(id)
     if user is None:
         return error_object('User not found', 404)
     db.session.delete(user)
     db.session.commit()
     return '', 204
예제 #4
0
 def wrapper(*args, **kwargs):
     verify_jwt_in_request()
     claims = get_jwt_claims()
     if claims['role'] != role:
         return error_object(
             'Sorry, you do not have access to this resource', 401)
     return wrapper(*args, **kwargs)
예제 #5
0
 def post(self, id, action):
     task = DeliveryTask.query.get(id)
     if task is None:
         return error_object('Task not found')
     action_state = {
         'accept': 'accepted',
         'complete': 'completed',
         'decline': 'declined',
         'cancel': 'cancelled'
     }
     task = change_task_state(task, action_state[action])
     db.session.add(task)
     try:
         db.session.commit()
         return make_response(jsonify(msg='Success!'), 200)
     except Exception:
         return error_object('Error changing state', 500)
예제 #6
0
 def post(self, user_args):
     try:
         user = User(user_args['name'], user_args['email'],
                     user_args['password'])
         db.session.add(user)
         db.session.commit()
     except IntegrityError:
         db.session.rollback()
         return error_object('User already exists', 422)
     return UserSchema().dump(user).data, 201
예제 #7
0
 def get(self, id):
     query = DeliveryTask.query
     if current_user.role == Role.STORE_MANAGER:
         task = query.filter_by(id=id, created_by=current_user).one()
     elif current_user.role == Role.DELIVERY_AGENT:
         task = query.filter_by(id=id, accepted_by=current_user).one()
     elif current_user.role == Role.ADMIN:
         task = query.get(id)
     if task is None:
         return error_object('Task not found', 404)
     return DeliveryTaskSchema().dump(task).data, 200
예제 #8
0
 def put(self, task_args, id):
     task = DeliveryTask.query.filter_by(id=id,
                                         created_by=current_user).one()
     if task is None:
         return error_object('Task not found', 404)
     for key, value in task_args.items():
         setattr(task, key, value)
     task.last_updated_at = datetime.utcnow()
     db.session.add(task)
     db.session.commit()
     return DeliveryTaskSchema().dump(task).data, 200
예제 #9
0
 def get(self, id):
     user = User.query.get(id)
     if user is None:
         return error_object('User not found', 404)
     return UserSchema().dump(user).data, 200