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)
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)
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
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
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