Esempio n. 1
0
    def put(self):
        email = request.json.get('email')
        password = request.json.get('password')

        if email is None or password is None:
            abort(400)  # missing arguments
        if User.objects(email=email).first() is not None:
            abort(400)  # existing user

        user = User(email=email)
        user.hash_password(password)
        user.save()

        return user.as_dict(), 201
Esempio n. 2
0
    def post(self, request):
        schema = UserSchema()
        if schema.is_valid(request.data):

            email = schema.data['email'].lower()
            password = schema.data['password']
            user = self.db_session.query(User).filter_by(email=email).first()

            if not user:
                salted_hash = User.hash_password(password)
                user = User(email=email, password=salted_hash)
                self.db_session.add(user)
                self.db_session.commit()
                return Response(content=user.to_dict(skip_fields=['password']),
                                status=status.HTTP_STATUS_201)

            msg = {'msg': 'User already exist with email: %s' % email}
            return Response(content=msg, status=status.HTTP_STATUS_400)

        return Response(content=schema.errors, status=status.HTTP_STATUS_400)