Ejemplo n.º 1
0
    def discourse_client(self, username=None):
        # get a discourse client impersonating this user, or
        # anonymous if they're not logged in
        username = username or self.discourse_username
        anon = not username

        return discourse_client(anonymous=anon, username=username)
Ejemplo n.º 2
0
    def discourse_client(self, username=None):
        # get a discourse client impersonating this user, or
        # anonymous if they're not logged in
        username = username or self.discourse_username
        anon = not username

        return discourse_client(
                anonymous=anon,
                username=username)
Ejemplo n.º 3
0
    def clean(self):
        """ authenticate user """
        if not self._errors:
            # call discourse
            discourse = discourse_client()
            try:
                user = discourse.authenticate_user(login=self.cleaned_data['username'],
                                                   password=self.cleaned_data['password'])
                log.info("Authenticated as: %s" % user)
                self.discourse_username = user['username']
            except DiscourseClientError as e:
                raise ValidationError(e.message)

        return self.cleaned_data
Ejemplo n.º 4
0
    def clean(self):
        """ authenticate user """
        if not self._errors:
            # call discourse
            discourse = discourse_client()
            try:
                user = discourse.authenticate_user(
                    login=self.cleaned_data['username'],
                    password=self.cleaned_data['password'])
                log.info("Authenticated as: %s" % user)
                self.discourse_username = user['username']
            except DiscourseClientError as e:
                raise ValidationError(e.message)

        return self.cleaned_data
Ejemplo n.º 5
0
    def clean(self):
        """ create user """
        if not self._errors:
            # call discourse
            discourse = discourse_client()
            try:
                user = discourse.create_user(
                    name=self.cleaned_data['name'],
                    username=self.cleaned_data['username'],
                    email=self.cleaned_data['email'],
                    password=self.cleaned_data['password'],
                    active=True)

                log.info("Created user: %s" % user)
                self.discourse_username = self.cleaned_data['username']
            except DiscourseError as e:
                raise ValidationError(e.message)

        return self.cleaned_data
Ejemplo n.º 6
0
    def clean(self):
        """ create user """
        if not self._errors:
            # call discourse
            discourse = discourse_client()
            try:
                user = discourse.create_user(
                    name=self.cleaned_data['name'],
                    username=self.cleaned_data['username'],
                    email=self.cleaned_data['email'],
                    password=self.cleaned_data['password'],
                    active=True)

                log.info("Created user: %s" % user)
                self.discourse_username = self.cleaned_data['username']
            except DiscourseError as e:
                raise ValidationError(e.message)

        return self.cleaned_data