コード例 #1
0
 def patch(self):
     userSchema = UserSchema()
     oldUser = UserModel.find_by_id(get_jwt_identity()["id"])
     logger.info("oldUser", oldUser.password)
     logger.info("request.form", request.form)
     updatedUser = userSchema.load(
         request.form, instance=oldUser).data.update()
     return userSchema.dump(updatedUser)
コード例 #2
0
    def post(self):
        logger.info("request.form: %s", request.form)
        user = UserSchema(partial=True).load(request.form).data
        logger.info(UserSchema().dump(user))
        if user.password is None:
            logger.warn("No password is provided during login")
            return {"message": UserLogin.message(
                "Username and password are required")}, 404

        try:
            databaseUser = UserModel.find_by_username(username=user.username)
        except NoResultFound:
            UserModel.verify_hash("randomness",
                                  UserModel.generate_hash(
                                    uuid.uuid4().hex[0:int(random.random()*20)]
                                    ))
            logger.warn("User did not exist: %s", user.username)
            return {'message':
                    UserLogin.message(
                        "Unknown User {}".format(user.username))
                    }, 404

        if UserModel.verify_hash(
                request.form["password"], databaseUser.password):

            access_token = create_access_token(
                identity={
                    "username": databaseUser.username,
                    "id": databaseUser.id
                })

            refresh_token = create_refresh_token(
                identity={
                    "username": databaseUser.username,
                    "id": databaseUser.id
                })

            return {'access_token': access_token,
                    'refresh_token': refresh_token,
                    'username': user.username,
                    'email': user.email
                    }
        else:
            logger.warn("Password did not exist for user: %s", user.username)
            return {
                "message": UserLogin.message(
                    "Unknown password {} for user {}".format(
                        request.form["password"], user.username))}, 404
コード例 #3
0
    def post(self):
        try:
            newUser = UserSchema(partial=True).load(request.values).data
        except ValidationError:
            return "User is not properly defined:"

        try:
            UserModel.find_by_username(newUser.username)
            return {'message': 'User {} already exists'. format(
                newUser.username)}, 500

        except NoResultFound:
            pass

        try:
            newUser.addUser()
            access_token = create_access_token(
                identity={
                    "username": newUser.username,
                    "id": newUser.id
                })

            refresh_token = create_refresh_token(
                identity={
                    "username": newUser.username,
                    "id": newUser.id
                })

            return {
                'message': 'User {} has been created'.format(newUser.username),
                'access_token': access_token,
                'refresh_token': refresh_token,
                'user': UserSchema().dump(newUser)
            }

        except Exception as error:
            logger.error(error)
            return {'message': "Something has gone wrong"}, 500
コード例 #4
0
    def post(self, partyId):
        logger.debug("request.values: %s", request.values)
        try:
            party = PartyModel.find_by_id(partyId)
        except NoResultFound:
            return {
                "message": "Could not find party with id:{}".format(partyId)
            }, 404

        logger.debug("party: %s", party)

        user = UserSchema().load(get_jwt_identity()).data

        logger.debug("user: %s", user)

        if party.host.id == user.id:
            logger.error("Host cannot invite himself. UserName: %s, Party: %s",
                         user.username, party.name)
            return {"message": "Host cannot invite himself"}, 400

        participations = PartyParticipationModel.find_by_ids(party.id, user.id)

        if len(participations) == 0:
            participation = PartyParticipationSchema(partial=True,
                                                     transient=True).load(
                                                         request.values).data
            participation.party = party
            participation.user = user
            participation.addPartyParticipation()
        else:
            logger.info("user: %s", user)
            logger.info("party: %s", party)
            logger.info("participations: %s", participations)
            logger.error(
                "Fond participation, please use other routes to modify it.")
            return {
                "message":
                "Fond participation, please use other routes to modify it."
            }, 500

        return PartyParticipationSchema().dump(participation)
コード例 #5
0
    def patch(self, partyId):
        logger.debug("request.values: %s", request.values)
        party = PartySchema().load({"id": partyId}).data

        user = UserSchema().load(get_jwt_identity()).data

        participations = PartyParticipationModel.find_by_ids(party, user)
        if len(participations) != 1:
            logger.info("user: %s", user)
            logger.info("party: %s", party)
            logger.info("participations: %s", participations)
            logger.warn(
                "Could not find 1 or found more then 1 party participation")
            return {
                "message":
                "Could not find 1 or found more then 1 party participation!"
            }, 400

        participation = PartyParticipationSchema().load(
            request.values, instance=participations[0]).data
        participation.update()
        return PartyParticipationSchema().dump(participation)
コード例 #6
0
 def get(self, userName):
     logger.error("userName %s", userName)
     user = UserModel.find_by_username(userName)
     return UserSchema(exclude=UserSchema.piiSensitive).dump(user)
コード例 #7
0
 def get(self):
     user = UserModel.find_by_id(get_jwt_identity()["id"])       
     return UserSchema().dump(user)
コード例 #8
0
 def get(self):
     return UserSchema().return_all()