<s> import httplib as http <EOL> from flask import redirect <EOL> from framework . auth . decorators import must_be_logged_in <EOL> from framework . exceptions import HTTPError <EOL> from website . oauth . models import ExternalAccount <EOL> from website . oauth . utils import get_service <EOL> from website . oauth . signals import oauth_complete <EOL> @ must_be_logged_in <EOL> def oauth_disconnect ( external_account_id , auth ) : <EOL> account = ExternalAccount . load ( external_account_id ) <EOL> user = auth . user <EOL> if account is None : <EOL> raise HTTPError ( http . NOT_FOUND ) <EOL> if account not in user . external_accounts : <EOL> raise HTTPError ( http . FORBIDDEN ) <EOL> for user_settings in user . get_oauth_addons ( ) : <EOL> user_settings . revoke_oauth_access ( account ) <EOL> user_settings . save ( ) <EOL> user . external_accounts . remove ( account ) <EOL> user . save ( ) <EOL> @ must_be_logged_in <EOL> def oauth_connect ( service_name , auth ) : <EOL> service = get_service ( service_name ) <EOL> return redirect ( service . auth_url ) <EOL> @ must_be_logged_in <EOL> def oauth_callback ( service_name , auth ) : <EOL> user = auth . user <EOL> provider = get_service ( service_name ) <EOL> if not provider . auth_callback ( user = user ) : <EOL> return { } <EOL> if provider . account not in user . external_accounts : <EOL> user . external_accounts . append ( provider . account ) <EOL> user . save ( ) <EOL> oauth_complete . send ( provider , account = provider . account , user = user ) <EOL> return { } </s>
