Example #1
0
        def clean(self):
            cleaned_data = super().clean()
            api_key = cleaned_data.get("api_key")
            api_secret = cleaned_data.get("api_secret")
            access_token = cleaned_data.get("access_token")
            access_token_secret = cleaned_data.get("access_token_secret")

            if api_key and api_secret and access_token and access_token_secret:
                twitter = TembaTwython(api_key, api_secret, access_token, access_token_secret)
                try:
                    twitter.verify_credentials()
                except TwythonError:
                    raise ValidationError(_("The provided Twitter credentials do not appear to be valid."))

            return cleaned_data
Example #2
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        cleaned_data = form.cleaned_data
        api_key = cleaned_data['api_key']
        api_secret = cleaned_data['api_secret']
        access_token = cleaned_data['access_token']
        access_token_secret = cleaned_data['access_token_secret']

        twitter = TembaTwython(api_key, api_secret, access_token,
                               access_token_secret)
        account_info = twitter.verify_credentials()
        handle_id = account_info['id']
        screen_name = account_info['screen_name']

        config = {
            'handle_id': handle_id,
            'api_key': api_key,
            'api_secret': api_secret,
            'access_token': access_token,
            'access_token_secret': access_token_secret,
            Channel.CONFIG_CALLBACK_DOMAIN: org.get_brand_domain(),
        }

        self.object = Channel.create(org,
                                     self.request.user,
                                     None,
                                     self.channel_type,
                                     name="@%s" % screen_name,
                                     address=screen_name,
                                     config=config)

        return super(ClaimView, self).form_valid(form)
Example #3
0
        def clean(self):
            cleaned_data = super(ClaimView.Form, self).clean()
            api_key = cleaned_data.get('api_key')
            api_secret = cleaned_data.get('api_secret')
            access_token = cleaned_data.get('access_token')
            access_token_secret = cleaned_data.get('access_token_secret')

            org = self.request.user.get_org()

            if api_key and api_secret and access_token and access_token_secret:
                twitter = TembaTwython(api_key, api_secret, access_token,
                                       access_token_secret)
                try:
                    user = twitter.verify_credentials()

                    # check there isn't already a channel for this Twitter account
                    if org.channels.filter(channel_type=self.channel_type.code,
                                           address=user['screen_name'],
                                           is_active=True).exists():
                        raise ValidationError(
                            _("A Twitter channel already exists for that handle."
                              ))

                except TwythonError:
                    raise ValidationError(
                        _("The provided Twitter credentials do not appear to be valid."
                          ))

            return cleaned_data
Example #4
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        cleaned_data = form.cleaned_data
        api_key = cleaned_data["api_key"]
        api_secret = cleaned_data["api_secret"]
        access_token = cleaned_data["access_token"]
        access_token_secret = cleaned_data["access_token_secret"]
        env_name = cleaned_data["env_name"]

        twitter = TembaTwython(api_key, api_secret, access_token,
                               access_token_secret)
        account_info = twitter.verify_credentials()
        handle_id = str(account_info["id"])
        screen_name = account_info["screen_name"]

        config = {
            "handle_id": handle_id,
            "api_key": api_key,
            "api_secret": api_secret,
            "access_token": access_token,
            "access_token_secret": access_token_secret,
            "env_name": env_name,
            Channel.CONFIG_CALLBACK_DOMAIN: settings.HOSTNAME,
        }

        try:
            self.object = Channel.create(
                org,
                self.request.user,
                None,
                self.channel_type,
                name="@%s" % screen_name,
                address=screen_name,
                config=config,
            )
        except ValidationError as e:
            self.form.add_error(None, e)
            return self.form_invalid(form)

        return super().form_valid(form)
Example #5
0
    def form_valid(self, form):
        org = self.request.user.get_org()

        cleaned_data = form.cleaned_data
        api_key = cleaned_data["api_key"]
        api_secret = cleaned_data["api_secret"]
        access_token = cleaned_data["access_token"]
        access_token_secret = cleaned_data["access_token_secret"]
        env_name = cleaned_data["env_name"]

        twitter = TembaTwython(api_key, api_secret, access_token, access_token_secret)
        account_info = twitter.verify_credentials()
        handle_id = str(account_info["id"])
        screen_name = account_info["screen_name"]

        config = {
            "handle_id": handle_id,
            "api_key": api_key,
            "api_secret": api_secret,
            "access_token": access_token,
            "access_token_secret": access_token_secret,
            "env_name": env_name,
            Channel.CONFIG_CALLBACK_DOMAIN: settings.HOSTNAME,
        }

        try:
            self.object = Channel.create(
                org,
                self.request.user,
                None,
                self.channel_type,
                name="@%s" % screen_name,
                address=screen_name,
                config=config,
            )
        except ValidationError as e:
            self.form.add_error(None, e)
            return self.form_invalid(form)

        return super().form_valid(form)