Example #1
0
    def mutate(self, info, **kwargs):
        validate_entity_types(['admin', 'citizen', 'politician'], 'user_type',
                              **kwargs)  # noqa
        user = UserModel(**kwargs)

        if not verify_email(user.email):
            raise GraphQLError("This email is not allowed")
        payload = {
            'model': UserModel,
            'field': 'email',
            'value': kwargs['email']
        }
        with SaveContextManager(user, 'User email', payload):
            token = user.generate_token()
            return CreateUser(user=user, token=token)
Example #2
0
    def mutate(self, info, **kwargs):
        query_user = User.get_query(info)
        existing_user = query_user.filter_by(email=kwargs['email']).first()

        if existing_user:
            token = existing_user.generate_token()
            return CreateUser(user=existing_user, token=token)
        user = UserModel(**kwargs)
        if user.email and not verify_email(user.email):
            raise GraphQLError("This email is not allowed")
        payload = {
            'model': UserModel,
            'field': 'email',
            'value': kwargs['email'],  # noqa
        }
        with SaveContextManager(user, 'email', payload):
            token = user.generate_token()
            return CreateUser(user=user, token=token)