def login(request, provider_name): response = HttpResponse() result = authomatic.login(DjangoAdapter(request, response), provider_name) if result: return HttpResponse( fixtures.render_login_result('django', result).encode()) return response
def login(request, provider_name): response = HttpResponse() result = authomatic.login(DjangoAdapter(request, response), provider_name) if result: res = {} if result.error: # Login procedure finished with an error. response.write('<h2>Damn that error: {0}</h2>'.format( result.error.message)) elif result.user: if not (result.user.name and result.user.id): result.user.update() # Welcome the user. response.write(u'<h1>Hi {0}</h1>'.format(result.user.name)) response.write(u'<h2>Your id is: {0}</h2>'.format(result.user.id)) response.write(u'<h2>Your email is: {0}</h2>'.format( result.user.email)) name = result.user.name id = result.user.id email = result.user.email #pdb.set_trace() pic = result.user.picture response.write(""" <script type="text/javascript"> window.onload = function() {{ alert('hello World') }}; function closePopup() {{ window.opener.$("#user_id").html('{0}'); window.opener.$("#user_name").html('{1}'); window.opener.$("#user_email").html('{2}'); window.opener.$("#user_pic").attr('src','{3}'); if(window.opener.login_callback != undefined){{ window.opener.login_callback('{0}','{1}','{2}','{3}'); }} else{{ console.log('Please Implement login_callback() ' ); }} // Close the popup window.close(); }} closePopup(); </script> """.format(id, name, email, pic)) return response ################## END OF SOCIAL USER #####################################
def login(request, provider_name): response = HttpResponse() result = authomatic.login(DjangoAdapter(request, response), provider_name) if result: #we have a result, so the login procedure has finished, and we should render a result if result.user: #we have the user logged in, we should verify the id and name result.user.update() response=render_to_response('simple/user.html', {'username':result.user.name, 'profile_pic':result.user.picture, 'user_id':result.user.id}) elif result.error: #there was an error logging in response=render_to_response('simple/login_error.html') return response
def oauth(request, provider): response = HttpResponse() authomatic = Authomatic(get_setting(settings.AUTHOMATIC_CONFIG, request), get_setting(settings.SECRET_KEY, request)) result = authomatic.login(DjangoAdapter(request, response), provider) if result: if result.error: messages.error( request, 'There was an error signing you in. Please try again') return HttpResponseRedirect(reverse('sign_in')) if result.user: # Then user is being redirected back from provider with their data # # OAuth 2.0 and OAuth 1.0a provide only limited user data on login, # We need to update the user to get more info. if not (result.user.name and result.user.id): result.user.update() provider = result.provider.name user = KagisoUser.get_user_from_auth_db(result.user.email) if user: _social_login(request, user.email, provider) return HttpResponseRedirect('/') else: gender = result.user.gender if gender: # Form constants (region, gender) are in uppercase gender = gender.upper() data = { 'provider': provider, 'email': result.user.email, 'first_name': result.user.first_name, 'last_name': result.user.last_name, 'gender': gender, 'birth_date': result.user.birth_date, } request.session['oauth_data'] = data return HttpResponseRedirect(reverse('sign_up')) # If result.user is None then user will be redirected to provider # to authenticate themselves, prior to being redirected back to this view. return response
def login(request, provider_name): response = HttpResponse() result = authomatic.login(DjangoAdapter(request, response), provider_name) if result: response.write('<a href="/accounts/loggedin">Home</a>') if result.error: response.write('<h2>Error: {0}</h2>'.format(result.error.message)) elif result.user: if not (result.user.name and result.user.id): result.user.update() response.write(u'<h1>Hi {0}</h1>'.format(result.user)) request.session['user'] = result.user.name if 'user' in request.session: return render_to_response('loggedin.html', {'result': request.session['user']}) else: return response
def login(request, provider_name): response = HttpResponse() result = authomatic.login(DjangoAdapter(request, response), provider_name) if result: #response.write('<a href="..">Home</a>') if result.error: response.write('<h2>Damn that error: {}</h2>'.format(result.error.message)) elif result.user: #data = result.provider.access(url) if not (result.user.name and result.user.id): result.user.update() print pprint.pformat(vars(result.user)) print pprint.pformat(vars(request.session)) request.session['user'] = result.user.to_dict() request.session['user']['avatar'] = result.user.picture return HttpResponseRedirect(request.GET.get('next', '/')) else: print "Sorry Authentication Failed! for ", provider_name return response
def get_social_media_id(request): ''' Gets users social media IDs for use in signup for information integration. :param request: :return: ''' # TODO: Add social media functionality apart from facebook # We we need the response object for the adapter. html_response = HttpResponse() result = authomatic.login(DjangoAdapter(request, html_response), 'fb') # If there is no result, the login procedure is still pending. # Don't write anything to the response if there is no result! if result: # If there is result, the login procedure is over and we can write to response. #html_response.write('<a href="..">Home</a>') if result.error: # Login procedure finished with an error. html_response.write('<p>Error: {0}</p>'.format(result.error.message)) elif result.user: # Hooray, we have the user! # OAuth 2.0 and OAuth 1.0a provide only limited user data on login, # We need to update the user to get more info. if not (result.user.name and result.user.id): result.user.update() # Welcome the user. # html_response.write(u'<p>Hi {0}</p>'.format(result.user.name)) html_response.write(u'<h2>Your Facebook id is: {0}</h2>'.format(result.user.id)) else: html_response.write('Auth Returned no Response.') return html_response
def login(request, provider_name): # We we need the response object for the adapter. response = HttpResponse() # Start the login procedure. result = authomatic.login(DjangoAdapter(request, response), provider_name) # If there is no result, the login procedure is still pending. # Don't write anything to the response if there is no result! if result: # If there is result, the login procedure is over and we can write to response. response.write('<a href="..">Home</a>') if result.error: # Login procedure finished with an error. response.write('<h2>Damn that error: {0}</h2>'.format( result.error.message)) elif result.user: # Hooray, we have the user! # OAuth 2.0 and OAuth 1.0a provide only limited user data on login, # We need to update the user to get more info. if not (result.user.name and result.user.id): result.user.update() # Welcome the user. response.write(u'<h1>Hi {0}</h1>'.format(result.user.name)) response.write(u'<h2>Your id is: {0}</h2>'.format(result.user.id)) response.write(u'<h2>Your email is: {0}</h2>'.format( result.user.email)) # Seems like we're done, but there's more we can do... # If there are credentials (only by AuthorizationProvider), # we can _access user's protected resources. if result.user.credentials: # Each provider has it's specific API. if result.provider.name == 'fb': response.write('Your are logged in with Facebook.<br />') # We will access the user's 5 most recent statuses. url = 'https://graph.facebook.com/{0}?fields=feed.limit(5)' url = url.format(result.user.id) # Access user's protected resource. access_response = result.provider.access(url) if access_response.status == 200: # Parse response. statuses = access_response.data.get('feed').get('data') error = access_response.data.get('error') if error: response.write( u'Damn that error: {0}!'.format(error)) elif statuses: response.write( 'Your 5 most recent statuses:<br />') for message in statuses: text = message.get('message') date = message.get('created_time') response.write(u'<h3>{0}</h3>'.format(text)) response.write(u'Posted on: {0}'.format(date)) else: response.write('Damn that unknown error!<br />') response.write(u'Status: {0}'.format(response.status))
def login(request,provider_name): response=HttpResponse() result= authomatic.login(DjangoAdapter(request, response),provider_name)
def login(request, group_id): # We we need the response object for the adapter. html_response = HttpResponse() result = authomatic.login(DjangoAdapter(request, html_response), 'fb') # If there is no result, the login procedure is still pending. # Don't write anything to the response if there is no result! if result: # If there is result, the login procedure is over and we can write to response. html_response.write('<a href="..">Home</a>') if result.error: # Login procedure finished with an error. html_response.write('<h2>Error: {0}</h2>'.format(result.error.message)) elif result.user: # Hooray, we have the user! #course_code = request.GET.get('course_code') #platform = request.GET.get('platform') # OAuth 2.0 and OAuth 1.0a provide only limited user data on login, # We need to update the user to get more info. if not (result.user.name and result.user.id): result.user.update() # Welcome the user. html_response.write(u'<p>Hi {0}</p>'.format(result.user.name)) # response.write(u'<h2>Your id is: {0}</h2>'.format(result.user.id)) # response.write(u'<h2>Your email is: {0}</h2>'.format(result.user.email)) # If there are credentials (only by AuthorizationProvider), # we can _access user's protected resources. if result.user.credentials: # Each provider has it's specific API. if result.provider.name == 'fb': # Construct Facebook group Graph API call #group_id = request.GET.get('group_id') url = 'https://graph.facebook.com/'+group_id+'/feed' unit_offering = UnitOffering.objects.filter(facebook_groups=group_id) #request.GET.get('course_code') course_code = unit_offering[0].code # Access user's protected resource. access_response = result.provider.access(url) #print access_response #print access_response.data.get('data') #fb_json = json.loads(access_response.data.get('data')) #pprint(access_response.data.get('data')) fb_feed = access_response.data.get('data') paging = access_response.data.get('paging') #pprint(paging) #pprint(fb_json) #t = LearningRecord.objects.filter(platform='Facebook',course_code=course_code).delete() injest_facebook(fb_feed, paging, course_code) #injest_twitter("#clatest", "cla101") top_content = get_top_content_table("Facebook", course_code) active_content = get_active_members_table("Facebook", course_code) cached_content, created = CachedContent.objects.get_or_create(course_code=course_code, platform="Facebook") cached_content.activitytable = active_content cached_content.htmltable = top_content cached_content.save() #perform sentiment classification sentiment_classifier(course_code) html_response.write('Updating Facebook for ' + course_code) ''' if access_response.status == 200: # Parse response. data = access_response.data.get('data') paging = access_response.data.get('paging') error = access_response.data.get('error') if error: html_response.write(u'Error: {0}!'.format(error)) elif data: #result = send_data_to_lrs.delay(data, paging, html_response) send_data_to_lrs(data, paging, html_response) #print result.id #html_response.write('<p>Data is being collected from the Facebook Page with an ID of ' + group_id + '</p>') #html_response.write('<p>View your task status <a href="http://localhost:5555/' # 'task/'+result.id+'">here.</a></p>') html_response.write('<p>Data was collected from the Facebook Page with an ID of ' + group_id + '</p>') else: html_response.write('Unknown error<br />') html_response.write(u'Status: {0}'.format(html_response.status)) ''' else: html_response.write('Auth Returned no Response.') return html_response
def login(request, provider_name): # We we need the response object for the adapter. response = HttpResponse() # Start the login procedure. result = authomatic.login(DjangoAdapter(request, response), provider_name) # If there is no result, the login procedure is still pending. # Don't write anything to the response if there is no result! if result: # If there is result, the login procedure is over and we can write to response. response.write('<a href="..">Home</a>') if result.error: # Login procedure finished with an error. response.write('<h2>Damn that error: {0}</h2>'.format(result.error.message)) elif result.user:# We need to update the user to get more info. if not (result.user.name and result.user.id): result.user.update() # Welcome the user. response.write(u'<h1>Hi {0}</h1>'.format(result.user.name)) response.write(u'<h2>Your id is: {0}</h2>'.format(result.user.id)) response.write(u'<h2>Your email is: {0}</h2>'.format(result.user.email)) # Seems like we're done, but there's more we can do... # If there are credentials (only by AuthorizationProvider), # we can _access user's protected resources. if result.user.credentials: # Each provider has it's specific API. if result.provider.name == 'fb': response.write('Your are logged in with Facebook.<br />') # We will access the user's 5 most recent statuses. url = 'https://graph.facebook.com/{0}?fields=feed.limit(5)' url = url.format(result.user.id) # Access user's protected resource. access_response = result.provider.access(url) if access_response.status == 200: # Parse response. statuses = access_response.data.get('feed').get('data') error = access_response.data.get('error') if error: response.write(u'Damn that error: {0}!'.format(error)) elif statuses: response.write('Your 5 most recent statuses:<br />') for message in statuses: text = message.get('message') date = message.get('created_time')response.write(u'<h3>{0}</h3>'.format(text)) response.write(u'Posted on: {0}'.format(date)) else: response.write('Damn that unknown error!<br />') response.write(u'Status: {0}'.format(response.status)) if result.provider.name == 'tw': response.write('Your are logged in with Twitter.<br />') # We will get the user's 5 most recent tweets. url = 'https://api.twitter.com/1.1/statuses/user_timeline.json' # You can pass a dictionary of querystring parameters. access_response = result.provider.access(url, {'count': 5}) # Parse response. if access_response.status == 200: if type(access_response.data) is list: # Twitter returns the tweets as a JSON list. response.write('Your 5 most recent tweets:') for tweet in access_response.data: text = tweet.get('text') date = tweet.get('created_at') response.write(u'<h3>{0}</h3>'.format(text)) response.write(u'Tweeted on: {0}'.format(date)) elif response.data.get('errors'): response.write(u'Damn that error: {0}!'.\ format(response.data.get('errors'))) else: response.write('Damn that unknown error!<br />') response.write(u'Status: {0}'.format(response.status)) return response
def get_social_media_id(request): ''' Gets users social media IDs for use in signup for information integration. :param request: :return: ''' # TODO: Add social media functionality apart from facebook # We we need the response object for the adapter. html_response = HttpResponse() if (request.GET.get('context') is not None): request.GET = request.GET.copy() state_dict = request.GET.pop('context') state_dict = state_dict[0] state_dict = json.loads(state_dict) #print str(state_dict) request.session['platform'] = state_dict['platform'] #request.session['course_code'] = state_dict['course_code'] #request.session['group_id'] = state_dict['group'] #print 'Data stored in session: %s, %s, %s' % (request.session['platform'], request.session['course_code'], request.session['group_id']) platform = request.session['platform'] #Facebook endpoints break on GET variables..... #platform = request.GET.get('platform') if (platform in settings.DATAINTEGRATION_PLUGINS_INCLUDEAUTHOMATIC): di_plugin = settings.DATAINTEGRATION_PLUGINS[platform] authomatic = Authomatic(di_plugin.authomatic_config_json, di_plugin.authomatic_secretkey) result = authomatic.login(DjangoAdapter(request, html_response), di_plugin.authomatic_config_key, report_errors=True) # If there is no result, the login procedure is still pending. # Don't write anything to the response if there is no result! if result: # If there is result, the login procedure is over and we can write to response. #html_response.write('<a href="..">Home</a>') if result.error: # Login procedure finished with an error. html_response.write('<p>Error: {0}</p>'.format( result.error.message)) elif result.user: # Hooray, we have the user! # OAuth 2.0 and OAuth 1.0a provide only limited user data on login, # We need to update the user to get more info. if not (result.user.name and result.user.id): result.user.update() # Welcome the user. # html_response.write(u'<p>Hi {0}</p>'.format(result.user.name)) html_response.write( u'<h2>Your Facebook id is: {0}</h2>'.format( result.user.id)) else: html_response.write('Auth Returned no Response.') return html_response
def dipluginauthomaticlogin(request): if request.GET.get('context') is not None: request.GET = request.GET.copy() state_dict = request.GET.pop('context') state_dict = state_dict[0] state_dict = json.loads(state_dict) request.session['platform'] = state_dict['platform'] request.session['unit'] = state_dict['unit'] request.session['group_id'] = state_dict['group'] platform = request.session['platform'] html_response = HttpResponse() if (platform in settings.DATAINTEGRATION_PLUGINS_INCLUDEAUTHOMATIC): di_plugin = settings.DATAINTEGRATION_PLUGINS[platform] authomatic = Authomatic(di_plugin.authomatic_config_json, di_plugin.authomatic_secretkey) result = authomatic.login(DjangoAdapter(request, html_response), di_plugin.authomatic_config_key, report_errors=True) # If there is no result, the login procedure is still pending. # Don't write anything to the response if there is no result! if result: # If there is result, the login procedure is over and we can write to response. html_response.write( '<a href="/dashboard/myunits/">Go back to dashboard</a>') if result.error: # Login procedure finished with an error. html_response.write('<h2>Error: {0}</h2>'.format( result.error.message)) elif result.user: # Hooray, we have the user! # OAuth 2.0 and OAuth 1.0a provide only limited user data on login, # We need to update the user to get more info. if not (result.user.name and result.user.id): result.user.update() # Welcome the user. # html_response.write(u'<p>Hi {0}</p>'.format(result.user.name)) # response.write(u'<h2>Your id is: {0}</h2>'.format(result.user.id)) # response.write(u'<h2>Your email is: {0}</h2>'.format(result.user.email)) # If there are credentials (only by AuthorizationProvider), # we can _access user's protected resources. if result.user.credentials: group_id = request.session['group_id'] unit_id = request.session['unit'] unit = UnitOffering.objects.get(id=unit_id) if result.provider.name == 'fb': di_plugin.perform_import(group_id, unit, result) post_smimport(unit, xapi_settings.PLATFORM_FACEBOOK) #Remove all data stored in session for this view to avoid cache issues del request.session['platform'] del request.session['unit'] del request.session['group_id'] html_response.write( '<h2>Facebook data import is complete.</h2>') else: html_response.write('Auth Returned no Response.') return html_response
def login(request, provider_name=None): # if user session exists redirect to the app.html page if 'user' in request.session: return app(request) # provider_name = request.GET['provider_name'] # We we need the response object for the adapter. response = HttpResponse() # Start the login procedure. result = authomatic.login(DjangoAdapter(request, response), provider_name) # If there is no result, the login procedure is still pending. # Don't write anything to the response if there is no result! if result: if result.error: # If there is result, the login procedure is over and we can write to response. response.write('<a href="..">Go to Home</a>') # Login procedure finished with an error. response.write('<h2>Error occured: {0}</h2>'.format( result.error.message)) elif result.user: # we have the user! returned # OAuth 2.0 and OAuth 1.0a provide only limited user data on login, # If there are credentials (only by AuthorizationProvider), # we can _access user's protected resources. if not (result.user.name and result.user.id): result.user.update() if result.user.credentials: # create a url to call the graph api # Get date 2 months before now date_two_months_old = datetime.today() - timedelta(days=60) date_today = datetime.today() url = 'https://graph.facebook.com/v2.7/{0}/posts?since={1}&until={2}'.format( result.user.id, date_two_months_old.date(), date_today.date()) kwargs = { "userappid": result.user.id, "email": result.user.email, "username": result.user.name, "providername": provider_name, "accesstoken": result.provider.access_token_response.data['access_token'] } chart_vars = { "startdate": date_two_months_old, "enddate": date_today } if check_if_user_is_registered(result.user.id, provider_name): if check_if_user_has_data(result.user.id, provider_name): # get data from until todays date get_updated_post_and_comments( result.user.id, provider_name, date_two_months_old.date(), date_today.date(), result) print "use is registered and has data" else: get_post_data_by_url_recursively( result, url, result.user.id, provider_name) get_comments_from_posts(result.provider, result.user.id, provider_name) print "user is registered and we received data" # Todo:goto app user_obj_from_db = Users.objects( app_specific_id=result.user.id, app_name=provider_name) print user_obj_from_db[0] user_id = user_obj_from_db[0].id kwargs['userid'] = user_id print kwargs request.session['user'] = kwargs return app(request) else: register_user(result.user.id, result.user.name, provider_name) get_post_data_by_url_recursively(result, url, result.user.id, provider_name) get_comments_from_posts(result.provider, result.user.id, provider_name) # Todo:goto app user_obj_from_db = Users.objects( app_specific_id=result.user.id, app_name=provider_name) user_id = user_obj_from_db[0].id kwargs['userid'] = user_id request.session['user'] = kwargs return app(request) else: response.write('<a href="..">Go to Home</a>') response.write( 'Error occured while accessing your personal details! Make sure you have given enough permission to the app<br />' ) response.write(u'Status: {0}'.format(response.status)) return response
"""Relevant result:write""" from django.http import HttpResponse from authomatic import Authomatic from authomatic.adapters import DjangoAdapter from config import CONFIG authomatic = Authomatic(CONFIG, 'a super secret random string') def login(request, provider_name): response = HttpResponse() result = authomatic.login(DjangoAdapter(request, response), provider_name) if result: Response.
def login(request, provider_name): # We we need the response object for the adapter. name = 'flag' email = 'flag' fbid = 'flag' response = HttpResponse() if 'fbid' in request.session: response.write(request.session['fbid'] + ' logged in as ' + request.session['name']) # Start the login procedure. result = authomatic.login(DjangoAdapter(request, response), provider_name) frend_ids = '' # If there is no result, the login procedure is still pending. # Don't write anything to the response if there is no result! if result: # If there is result, the login procedure is over and we can write to response. response.write('<a href="..">Home</a>') if result.error: # Login procedure finished with an error. response.write('<h2>Damn that error: {0}</h2>'.format( result.error.message)) elif result.user: # Hooray, we have the user! # OAuth 2.0 and OAuth 1.0a provide only limited user data on login, # We need to update the user to get more info. if not (result.user.name and result.user.id): result.user.update() # Welcome the user. name = result.user.name fbid = result.user.id email = result.user.email response.write(u'<h1>Hi {0}</h1>'.format(result.user.name)) response.write(u'<h2>Your id is: {0}</h2>'.format(result.user.id)) response.write(u'<h2>Your email is: {0}</h2>'.format( result.user.picture)) response.write(dir(result.user)) request.session['fbid'] = fbid request.session['name'] = name #request.session[''] # Seems like we're done, but there's more we can do... # If there are credentials (only by AuthorizationProvider), # we can _access user's protected resources. if result.user.credentials: # Each provider has it's specific API. if result.provider.name == 'fb': response.write('Your are logged in with Facebook.<br />') # frens url = 'https://graph.facebook.com/v2.0/me/friends' url = url.format(result.user.id) # Access user's protected resource. access_response = result.provider.access(url) response.write(url) #return response if access_response.status == 200: # Parse response. #statuses = access_response.data.get('feed').get('data') error = access_response.data.get('error') frens = access_response.data.get('data') #response.write(access_response.data); #return response if error: response.write( u'Damn that error: {0}!'.format(error)) elif frens: frend_ids = '' for message in frens: text = message.get('name') frend_fbid = message.get('id') frend_ids += frend_fbid + ',' #response.write(u'<h3>{0}</h3>'.format(text)) #response.write(u'Posted on: {0}'.format(date)) else: response.write('Damn that unknown error!<br />') #response.write(u'Status: {0}'.format(response.status)) #response.write(frend_ids) response.write(result) #return response; if name == 'flag' or fbid == 'flag' or name == '' or fbid == '': return response if User.objects.filter(fbid=fbid).count() > 0: user = User.objects.get(fbid=fbid) else: user = User.objects.create() #response.write("Check345564567"); #return response; user.fbid = fbid user.friendlist = frend_ids user.name = name user.email = email user.save() #response.write("Check34556"); #return response return redirect(home)