def get(self): token = self.get_argument('token', None) client = AsyncLastfmClient() if not token: callback_url = self.get_absolute_url(self.reverse_url( 'lastfm' if not self.popup else 'lastfm_popup')) self.redirect(client.get_auth_url(callback_url)) else: session = yield client.auth.get_session(token=token) client.session_key = session['key'] profile = yield client.user.get_info() try: user = User.objects.get(lastfm__name=session['name']) except User.DoesNotExist: if self.current_user: # Connect user = self.current_user user.lastfm = LastfmAccount() else: user = User( name=profile.get('realname', ''), lastfm=LastfmAccount() ) user.lastfm.session_key = session['key'] profile['subscriber'] = bool(int(profile['subscriber'])) user.lastfm.update_fields(**profile) if not user.picture: # noinspection PyUnresolvedReferences user.picture = user.lastfm.get_picture() user.save() self.service_connected(user)
def _on_login(self, fb_data): if fb_data: # TODO: drop FB usernames (deprecated for versions v2.0 and higher) # https://github.com/jakubroztocil/cloudtunes/issues/3 # HACK: work around removed FB usernames fb_data['username'] = fb_data['id'] try: user = User.objects.get(facebook__id=fb_data['id']) except User.DoesNotExist: if self.current_user: # Connect user = self.current_user user.facebook = FacebookAccount() else: # Sign up user = User( name=' '.join([fb_data.get('first_name'), fb_data.get('last_name')]), facebook=FacebookAccount() ) user.facebook.update_fields(**fb_data) if not user.picture: user.picture = user.facebook.get_picture() if not user.email: user.email = user.facebook.email if not user.username and 'username' in fb_data: max_length = User._fields['username'].max_length username = fb_data.get('username', '')[:max_length] if (username and not User.objects.filter(username__iexact=username).count()): user.username = username if not user.location: user.location = fb_data.get('location', {}).get('name', '') user.save() sync_account.delay(user.facebook.id) self.service_connected(user)
def _on_login(self, fb_data): if fb_data: # TODO: drop FB usernames (deprecated for versions v2.0 and higher) # https://github.com/jkbrzt/cloudtunes/issues/3 # HACK: work around removed FB usernames fb_data['username'] = fb_data['id'] try: user = User.objects.get(facebook__id=fb_data['id']) except User.DoesNotExist: if self.current_user: # Connect user = self.current_user user.facebook = FacebookAccount() else: # Sign up user = User(name=' '.join( [fb_data.get('first_name'), fb_data.get('last_name')]), facebook=FacebookAccount()) user.facebook.update_fields(**fb_data) if not user.picture: user.picture = user.facebook.get_picture() if not user.email: user.email = user.facebook.email if not user.username and 'username' in fb_data: max_length = User._fields['username'].max_length username = fb_data.get('username', '')[:max_length] if (username and not User.objects.filter( username__iexact=username).count()): user.username = username if not user.location: user.location = fb_data.get('location', {}).get('name', '') user.save() sync_account.delay(user.facebook.id) self.service_connected(user)
def get(self): token = self.get_argument('token', None) client = AsyncLastfmClient() if not token: callback_url = self.get_absolute_url(self.reverse_url( 'lastfm' if not self.popup else 'lastfm_popup')) self.redirect(client.get_auth_url(callback_url)) else: session = yield client.auth.get_session(token=token) client.session_key = session['key'] profile = yield client.user.get_info() try: user = User.objects.get(lastfm__name=session['name']) except User.DoesNotExist: if self.current_user: # Connect user = self.current_user user.lastfm = LastfmAccount() else: user = User( name=profile.get('realname', ''), lastfm=LastfmAccount() ) user.lastfm.session_key = session['key'] profile['subscriber'] = bool(int(profile['subscriber'])) user.lastfm.update_fields(**profile) if not user.picture: # noinspection PyUnresolvedReferences user.picture = user.lastfm.get_picture() if not user.username: user.username = user.lastfm.name user.save() self.service_connected(user)
def get(self): key = self.session.pop("dropbox_tmp_key", None) secret = self.session.pop("dropbox_tmp_secret", None) if not (key and secret): return self.redirect(self.reverse_url("dropbox", "start")) # Fetch account info # TODO: async session = Session() session.set_request_token(key, secret) access_token = session.obtain_access_token(session.token) # https://www.dropbox.com/developers/reference/api#account-info info = Client(session).account_info() try: user = User.objects.get(dropbox__id=info["uid"]) except User.DoesNotExist: if self.current_user: # Connect user = self.current_user user.dropbox = DropboxAccount() else: # Sign up name = info.get("display_name", "") user = User(name=name, dropbox=DropboxAccount()) user.dropbox.update_fields( id=info["uid"], display_name=info["display_name"], country=info.get("country", None), oauth_token_key=access_token.key, oauth_token_secret=access_token.secret, ) user.save() sync_account.delay(user.dropbox.id) self.service_connected(user)
def get(self): key = self.session.pop('dropbox_tmp_key', None) secret = self.session.pop('dropbox_tmp_secret', None) if not (key and secret): return self.redirect(self.reverse_url('dropbox', 'start')) # Fetch account info # TODO: async session = Session() session.set_request_token(key, secret) access_token = session.obtain_access_token(session.token) # https://www.dropbox.com/developers/reference/api#account-info info = Client(session).account_info() try: user = User.objects.get(dropbox__id=info['uid']) except User.DoesNotExist: if self.current_user: # Connect user = self.current_user user.dropbox = DropboxAccount() else: # Sign up name = info.get('display_name', '') user = User(name=name, dropbox=DropboxAccount()) user.dropbox.update_fields( id=info['uid'], display_name=info['display_name'], country=info.get('country', None), oauth_token_key=access_token.key, oauth_token_secret=access_token.secret, ) user.save() sync_account.delay(user.dropbox.id) self.service_connected(user)
def _on_login(self, fb_data): try: user = User.objects.get(facebook__id=fb_data['id']) except User.DoesNotExist: if self.current_user: # Connect user = self.current_user user.facebook = FacebookAccount() else: # Sign up user = User( name=' '.join([fb_data.get('first_name'), fb_data.get('last_name')]), facebook=FacebookAccount() ) user.facebook.update_fields(**fb_data) if not user.picture: user.picture = user.facebook.get_picture() if not user.email: user.email = user.facebook.email if not user.username and 'username' in fb_data: max_length = User._fields['username'].max_length username = fb_data.get('username', '')[:max_length] if (username and not User.objects.filter(username__iexact=username).count()): user.username = username if not user.location: user.location = fb_data.get('location', {}).get('name', '') user.save() sync_account.delay(user.facebook.id) self.service_connected(user)
def get(self): redirect_url = self.get_absolute_url('facebook') if self.popup: redirect_url += '?popup=1' if self.get_argument('code', None): fb_data = yield self.get_authenticated_user( redirect_uri=redirect_url, client_id=settings.FACEBOOK_APP_ID, client_secret=settings.FACEBOOK_APP_SECRET, code=self.get_argument('code') ) if fb_data: # TODO: drop FB usernames (deprecated for versions v2.0 and higher) # https://github.com/jakubroztocil/cloudtunes/issues/3 # HACK: work around removed FB usernames fb_data['username'] = fb_data['id'] try: user = User.objects.get(facebook__id=fb_data['id']) except User.DoesNotExist: if self.current_user: # Connect user = self.current_user user.facebook = FacebookAccount() else: # Sign up user = User( name=' '.join([fb_data.get('first_name'), fb_data.get('last_name')]), facebook=FacebookAccount() ) user.facebook.update_fields(**fb_data) if not user.picture: user.picture = user.facebook.get_picture() if not user.email: user.email = user.facebook.email if not user.username and 'username' in fb_data: max_length = User._fields['username'].max_length username = fb_data.get('username', '')[:max_length] if (username and not User.objects.filter(username__iexact=username).count()): user.username = username if not user.location: user.location = fb_data.get('location', {}).get('name', '') user.save() sync_account.delay(user.facebook.id) self.service_connected(user) else: params = { 'scope': ','.join(settings.FACEBOOK_PERMISSIONS), 'redirect_uri': redirect_url, } if self.popup: params['display'] = 'popup' self.authorize_redirect( redirect_uri=redirect_url, client_id=settings.FACEBOOK_APP_ID, extra_params=params )