Exemplo n.º 1
0
 def get(self):
     """Method to handle user profile retrieval"""
     exact_user = UserModel.query.filter_by(
         id=get_jwt_identity().get('id')).first()
     if not exact_user:
         return error_response(message="No associated account " +
                               "with this email. 😩", status=404)
     user_data = UserSchema(exclude=['password']).dump(exact_user)
     return success_response(data=user_data)
Exemplo n.º 2
0
 def delete(self, diary_id):
     validate_uuid(diary_id)
     user_diary = DiaryModel.query.filter_by(
         id=diary_id, deleted=False,
         user_id=get_jwt_identity().get('id')).first()
     if not user_diary:
         return error_response(message='Diary not found', status=404)
     user_diary.delete()
     return success_response(message='Diary deleted successfully')
Exemplo n.º 3
0
 def put(self, diary_id):
     validate_uuid(diary_id)
     diary_update_data = request.get_json(force=True)
     diary_data = DiarySchema(exclude=['id', 'created_on', 'updated_on']).\
         load_object_into_schema(
             diary_update_data, partial=True)
     user_diary = DiaryModel.query.filter_by(
         id=diary_id, deleted=False,
         user_id=get_jwt_identity().get('id')).first()
     if not user_diary:
         return error_response(message='Diary not found', status=404)
     if user_diary.updated_on and (user_diary.updated_on -
                                   user_diary.created_on).days > 0:
         return error_response(
             message='Diary cannot be modified after 24hrs', status=400)
     user_diary = user_diary.update(**diary_data)
     return success_response(data=DiarySchema().dump(user_diary),
                             status=200,
                             message='Diary updated successfully')
Exemplo n.º 4
0
 def get(self, diary_id):
     validate_uuid(diary_id)
     user_diary = DiaryModel.query.filter_by(
         id=diary_id, deleted=False,
         user_id=get_jwt_identity().get('id')).first()
     if not user_diary:
         return error_response(message='Diary not found', status=404)
     return success_response(data=DiarySchema().dump(user_diary),
                             status=200,
                             message='Diary retrieved successfully')
Exemplo n.º 5
0
 def post(self):
     user_info = request.get_json(force=True)
     exact_user = UserModel.query.filter_by(
         email=user_info['email']).first()
     if not exact_user:
         return error_response(message="No associated account " +
                               "with this email. 😩",
                               status=404)
     is_valid_password = BCrypt.check_password_hash(exact_user.password,
                                                    user_info['password'])
     if not is_valid_password:
         return error_response(message="Email or Password " +
                               "is not correct 😕",
                               status=401)
     user_schema = UserSchema(exclude=['password', 'push_sub'])
     user_info = user_schema.dump(exact_user)
     token = create_access_token(identity={"id": exact_user.id})
     return success_response(message='Logged in successfuly',
                             data=dict(token=token, user=user_info),
                             status=200)
Exemplo n.º 6
0
    def post(self):
        user_info = request.get_json(force=True)
        existing_user = UserModel.query.filter_by(
            email=user_info['email']).first()
        if existing_user:
            return error_response(message="This email address" +
                                  " has been taken",
                                  status=409)
        new_user = UserModel(**user_info)
        new_user.save()

        return success_response(
            message="Your account has been created successfully",
            data=UserSchema(exclude=['password']).dump(new_user),
            status=201)