def get(self): parts = self.decode_state_parameter(self.request.get('state') or '') callback = parts and parts.get('callback') if self.request.get('declined'): # disable declined means no change took place if callback: callback = util.add_query_params(callback, {'result': 'declined'}) self.redirect(callback.encode('utf-8')) else: self.messages.add('If you want to disable, please approve the prompt.') self.redirect('/') return if (not parts or 'feature' not in parts or 'source' not in parts): self.abort(400, 'state query parameter must include "feature" and "source"') feature = parts['feature'] if feature not in (Source.FEATURES): self.abort(400, 'cannot delete unknown feature %s' % feature) logged_in_as = ndb.Key( urlsafe=util.get_required_param(self, 'auth_entity')).get() source = ndb.Key(urlsafe=parts['source']).get() if logged_in_as and logged_in_as.is_authority_for(source.auth_entity): # TODO: remove credentials if feature in source.features: source.features.remove(feature) source.put() # remove login cookie logins = self.get_logins() login = util.Login(path=source.bridgy_path(), site=source.SHORT_NAME, name=source.label_name()) if login in logins: logins.remove(login) self.set_logins(logins) noun = 'webmentions' if feature == 'webmention' else feature + 'ing' if callback: callback = util.add_query_params(callback, { 'result': 'success', 'user': source.bridgy_url(self), 'key': source.key.urlsafe(), }) else: self.messages.add('Disabled %s for %s. Sorry to see you go!' % (noun, source.label())) # util.email_me(subject='Deleted Bridgy %s user: %s %s' % # (feature, source.label(), source.key.string_id()), # body=source.bridgy_url(self)) else: if callback: callback = util.add_query_params(callback, {'result': 'failure'}) else: self.messages.add('Please log into %s as %s to disable it here.' % (source.GR_CLASS.NAME, source.name)) self.redirect(callback.encode('utf-8') if callback else source.bridgy_url(self) if source.features else '/')
def delete_finish(): parts = util.decode_oauth_state(request.values.get('state') or '') callback = parts and parts.get('callback') if request.values.get('declined'): # disable declined means no change took place if callback: callback = util.add_query_params(callback, {'result': 'declined'}) return redirect(callback) else: flash('If you want to disable, please approve the prompt.') return redirect('/') return if not parts or 'feature' not in parts or 'source' not in parts: error('state query parameter must include "feature" and "source"') feature = parts['feature'] if feature not in (Source.FEATURES): error(f'cannot delete unknown feature {feature}') logged_in_as = ndb.Key(urlsafe=request.args['auth_entity']).get() source = ndb.Key(urlsafe=parts['source']).get() logins = None if logged_in_as and logged_in_as.is_authority_for(source.auth_entity): # TODO: remove credentials if feature in source.features: source.features.remove(feature) source.put() # remove login cookie logins = util.get_logins() login = util.Login(path=source.bridgy_path(), site=source.SHORT_NAME, name=source.label_name()) if login in logins: logins.remove(login) if callback: callback = util.add_query_params( callback, { 'result': 'success', 'user': source.bridgy_url(), 'key': source.key.urlsafe().decode(), }) else: nouns = { 'webmention': 'webmentions', 'listen': 'backfeed', 'publish': 'publishing', } msg = f'Disabled {nouns[feature]} for {source.label()}.' if not source.features: msg += ' Sorry to see you go!' flash(msg) elif callback: callback = util.add_query_params(callback, {'result': 'failure'}) else: flash( f'Please log into {source.GR_CLASS.NAME} as {source.name} to disable it here.' ) url = callback if callback else source.bridgy_url( ) if source.features else '/' return redirect(url, logins=logins)