Пример #1
0
    def any(self, provider_name):

        # Log the user in.
        result = authomatic.login(Webapp2Adapter(self), provider_name)

        if result:
            if result.user:
                result.user.update()
                self.response.write('<h1>Hi {}</h1>'.format(result.user.name))

                # Save the user name and ID to cookies that we can use it in other handlers.
                self.response.set_cookie('user_id', result.user.id)
                self.response.set_cookie('user_name',
                                         urllib.quote(result.user.name))

                if result.user.credentials:
                    # Serialize credentials and store it as well.
                    serialized_credentials = result.user.credentials.serialize(
                    )
                    self.response.set_cookie('credentials',
                                             serialized_credentials)

            elif result.error:
                self.response.set_cookie('error',
                                         urllib.quote(result.error.message))

            self.redirect('/')
Пример #2
0
def login(provider_name):
    response = make_response()
    result = authomatic.login(WerkzeugAdapter(request, response), provider_name)

    if result:
        response.data += fixtures.render_login_result(result)

    return response
Пример #3
0
def login(provider_name):
    response = make_response()
    result = authomatic.login(WerkzeugAdapter(request, response),
                              provider_name)

    if result:
        response.data += fixtures.render_login_result('flask', result).encode()

    return response
Пример #4
0
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
Пример #5
0
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
Пример #6
0
 def any(self, provider_name):
     result = authomatic.login(Webapp2Adapter(self), provider_name)
     if result:
         apis = []
         if result.user:
             result.user.update()
             if result.user.credentials:
                 apis = config.config.get(provider_name, {}).get('_apis', {})
         
         nice_provider_name = config.config.get(provider_name, {}).get('_name') or provider_name.capitalize()
         
         render(self, result, result.popup_js(custom=dict(apis=apis, provider_name=nice_provider_name)))
Пример #7
0
def login(provider_name):
    response = make_response()
    result = authomatic.login(WerkzeugAdapter(request, response), provider_name)
    if result:
        if result.user:
            result.user.update()
        user_properties = config.PROVIDERS.values()[0]['user'].keys()
        return render_template('login.html', result=result,
                               providers=config.PROVIDERS.keys(),
                               user_properties=user_properties)
    
    # Don't forget to return the response.
    return response
Пример #8
0
    def any(self, provider_name):
        result = authomatic.login(Webapp2Adapter(self), provider_name)
        if result:
            apis = []
            if result.user:
                result.user.update()
                if result.user.credentials:
                    apis = config.config.get(provider_name,
                                             {}).get('_apis', {})

            nice_provider_name = config.config.get(
                provider_name, {}).get('_name') or provider_name.capitalize()

            render(
                self, result,
                result.popup_js(
                    custom=dict(apis=apis, provider_name=nice_provider_name)))
Пример #9
0
 def login(self, provider_name):
     
     result = authomatic.login(Webapp2Adapter(self),
                               provider_name,
                               callback=self.callback)
     
     if result:
         if result.user:
             user_response = result.user.update()
             if user_response:
                 self.response.write('<br /><br />status = {}<br />'.format(user_response.status))
             
             self.response.write('<br /><br />Hi {}<br />'.format(result.user.name))
             self.response.write('your ID is {}<br />'.format(result.user.id))
             self.response.write('your email is {}<br />'.format(result.user.email))
         elif result.error:
             self.response.write('ERROR {}<br />'.format(result.error.message))
Пример #10
0
def login(provider_name):
    # We need response object for the WerkzeugAdapter.
    response = make_response()
    # Log the user in, pass it the adapter and the provider name.
    result = authomatic.login(
        WerkzeugAdapter(request, response),
        provider_name,
        session=session,
        session_saver=lambda: app.save_session(session, response))
    # If there is no LoginResult object, the login procedure is still pending.
    if result:
        if result.user:
            if provider_name == "google":
                # We need to update the user to get more info.
                result.user.update()
                session['email'] = result.user.email
                session['username'] = result.user.name
                session['token'] = result.user.id
            elif provider_name == "reddit":
                result.user.update()
                session['username'] = result.user.username
                session['token'] = result.user.id
                session['email'] = result.user.id + "@temp.com"
        # The rest happens inside the template.
        if mongo.db.users.find_one({'email': session['email']}):
            result = mongo.db.users.find_one({'email': session['email']})
            return render_template("dns.html",
                                   user=session['username'],
                                   message="Welcome back, {}".format(
                                       session["username"]),
                                   fqdns=result['fqdns'],
                                   UUID=session['token'])
        else:
            mongo.db.users.insert_one({
                "username": session['username'],
                "email": session['email'],
                "token": session['token']
            })
            return render_template("dns.html",
                                   message="Welcome back, {}".format(
                                       session["username"]),
                                   user=session['username'],
                                   UUID=session['token'])

    # Don't forget to return the response.
    return response
Пример #11
0
def login(provider_name):
    global userid
    # We need response object for the WerkzeugAdapter.
    response = make_response()
    # Log the user in, pass it the adapter and the provider name.
    result = authomatic.login(WerkzeugAdapter(request, response),
                              provider_name)
    # If there is no LoginResult object, the login procedure is still pending.
    if result:
        if result.user:
            # We need to update the user to get more info.
            result.user.update()
            userid = result.user.id
            exist = int(
                requests.get("http://192.168.37.129:5000/api/user/exist/" +
                             userid).content)
            if exist != 0:
                ##Gebruiker bestaat al
                info = requests.get(
                    "http://192.168.37.129:5000/api/user/number/" +
                    userid).json()
                cn = info['_id']
                adc = info['address']['city']
                ads = info['address']['street']
                adz = info['address']['zipcode']
                mail = info['email']
                fn = info['name']['first_name']
                ln = info['name']['last_name']
                return render_template('login.html',
                                       result=result,
                                       customernumber=cn,
                                       city=adc,
                                       street=ads,
                                       zipcode=adz,
                                       email=mail,
                                       firstname=fn,
                                       lastname=ln)
            else:
                #Gebruiker bestaat nog niet
                return redirect('/register')
        # The rest happens inside the template.

    # Don't forget to return the response.
    return response
Пример #12
0
    def login(self, provider_name):

        result = authomatic.login(Webapp2Adapter(self),
                                  provider_name,
                                  callback=self.callback)

        if result:
            if result.user:
                user_response = result.user.update()
                if user_response:
                    self.response.write('<br /><br />status = {}<br />'.format(
                        user_response.status))

                self.response.write('<br /><br />Hi {}<br />'.format(
                    result.user.name))
                self.response.write('your ID is {}<br />'.format(
                    result.user.id))
                self.response.write('your email is {}<br />'.format(
                    result.user.email))
            elif result.error:
                self.response.write('ERROR {}<br />'.format(
                    result.error.message))
Пример #13
0
 def any(self, provider_name):
     
     # Log the user in.
     result = authomatic.login(Webapp2Adapter(self), provider_name)
     
     if result:
         if result.user:
             result.user.update()
             self.response.write('<h1>Hi {}</h1>'.format(result.user.name))
             
             # Save the user name and ID to cookies that we can use it in other handlers.
             self.response.set_cookie('user_id', result.user.id)
             self.response.set_cookie('user_name', urllib.quote(result.user.name))
             
             if result.user.credentials:
                 # Serialize credentials and store it as well.
                 serialized_credentials = result.user.credentials.serialize()
                 self.response.set_cookie('credentials', serialized_credentials)
                 
         elif result.error:
             self.response.set_cookie('error', urllib.quote(result.error.message))
         
         self.redirect('/')
Пример #14
0
def login(provider_name):
	"""This is the login route for all OAuth providers.

	This route logs a user in with facebook, gets their information from their
	facebook profile, and stores the user in our session. Once the user is logged in,
	they are redirected to their profile page.	
	"""
	# If one were to add a second provider 
	# (i.e. Twitter, Google), more logic could be added to this method by
	# checkingthe "provider_name" variable
	response = make_response()
	result = authomatic.login(WerkzeugAdapter(request, response), provider_name)

	if result:
		# If we've received a user from Facebook...
		if result.user:
			# Get the user's profile data and look for it in our database
			result.user.update()
			facebook_id = result.user.id
			user = dbsession.query(User).filter_by(facebookid = facebook_id).first()

			# If we don't find the user in our database, add it!
			if not user:
				profilepic = "http://graph.facebook.com/"+ facebook_id +"/picture?type=large"
				user = User(facebookid = facebook_id, email=result.user.email, name=result.user.name, profilepic=profilepic)
				dbsession.add(user)
				dbsession.commit()

			# Store the user in our session, logging them in 
			login_user(user)
			current_user.last_log_in = datetime.datetime.now()
			dbsession.commit()

		# Redirect somewhere after log in. In this case, the homepage
		return redirect('/profile')

	return response
Пример #15
0
 def any(self, provider_name):
             
     # It all begins with login.
     result = authomatic.login(Webapp2Adapter(self), provider_name)
     
     # Do not 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.
         self.response.write('<a href="..">Home</a>')
         
         if result.error:
             # Login procedure finished with an error.
             self.response.write('<h2>Damn that error: {}</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.
             self.response.write('<h1>Hi {}</h1>'.format(result.user.name))
             self.response.write('<h2>Your id is: {}</h2>'.format(result.user.id))
             self.response.write('<h2>Your email is: {}</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':
                     self.response.write('Your are logged in with Facebook.<br />')
                     
                     # We will access the user's 5 most recent statuses.
                     url = 'https://graph.facebook.com/{}?fields=feed.limit(5)'
                     url = url.format(result.user.id)
                     
                     # Access user's protected resource.
                     response = result.provider.access(url)
                     
                     if response.status == 200:
                         # Parse response.
                         statuses = response.data.get('feed').get('data')
                         error = response.data.get('error')
                         
                         if error:
                             self.response.write('Damn that error: {}!'.format(error))
                         elif statuses:
                             self.response.write('Your 5 most recent statuses:<br />')
                             for message in statuses:
                                 
                                 text = message.get('message')
                                 date = message.get('created_time')
                                 
                                 self.response.write('<h3>{}</h3>'.format(text))
                                 self.response.write('Posted on: {}'.format(date))
                     else:
                         self.response.write('Damn that unknown error!<br />')
                         self.response.write('Status: {}'.format(response.status))
                     
                 if result.provider.name == 'tw':
                     self.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.
                     response = result.provider.access(url, {'count': 5})
                                             
                     # Parse response.
                     if response.status == 200:
                         if type(response.data) is list:
                             # Twitter returns the tweets as a JSON list.
                             self.response.write('Your 5 most recent tweets:')
                             for tweet in response.data:
                                 text = tweet.get('text')
                                 date = tweet.get('created_at')
                                 
                                 self.response.write('<h3>{}</h3>'.format(text))
                                 self.response.write('Tweeted on: {}'.format(date))
                                 
                         elif response.data.get('errors'):
                             self.response.write('Damn that error: {}!'.\
                                                 format(response.data.get('errors')))
                     else:
                         self.response.write('Damn that unknown error!<br />')
                         self.response.write('Status: {}'.format(response.status))
Пример #16
0
 def any(self, provider_name):
     
     result = authomatic.login(Webapp2Adapter(self), provider_name)
     
     if result:
         self.response.write("""<!DOCTYPE html><html>
         <head>
             <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=sunburst"></script>
         </head>
         """)
         
         self.response.write('<body>')
         self.response.write('<a href="..">Home</a> | ')
         self.response.write('<a href="../login/{}">Retry</a>'.format(provider_name))
         
         if result.error:
             self.response.write('<h4>ERROR: {}</h4>'.format(result.error.message))
             
             self.response.write('<h3>error to dict</h3>')
             self.response.write('<pre class="prettyprint">{}</pre>'.format(result.error.to_dict()))
         
         elif result.user:
             response = result.user.update()
             if response:
                 self.response.write('<h3>User refresh status: {}</h3>'.format(response.status))
                 self.response.write('<pre class="prettyprint">{}</pre>'.format(response.content))
                 
                 self.response.write('<h3>Access-Control-Allow-Origin</h3>')
                 self.response.write('<pre class="prettyprint">{}</pre>'.format(response.getheader('Access-Control-Allow-Origin')))
                 
                 self.response.write('<h3>User headers</h3>')
                 self.response.write('<pre class="prettyprint">{}</pre>'.format(response.getheaders()))
             
             
             self.response.write('<h3>User</h3>')
             if result.user.picture:
                 self.response.write('<img src="{}" width="100" height="100" />'.format(result.user.picture))
             
             loop(self, result.user)
             
             if result.user.credentials:
                 # loop through credentials attrs
                 self.response.write('<h3>Credentials</h3>')
                 self.response.write('<h5>expiration time: {}</h5>'.format(result.user.credentials.expiration_time))
                 self.response.write('<h5>expiration date: {}</h5>'.format(result.user.credentials.expiration_date))
                 loop(self, result.user.credentials)
                 
                 self.response.write('<h3>Serialized credentials</h3>')
                 serialized_credentials = result.user.credentials.serialize()
                 endpoint_url = '/login/?type=elements&url=http://example.com&credentials=' + serialized_credentials
                 self.response.write('<a href="{}" target="_blank">{}</a>'.format(endpoint_url, serialized_credentials))
                 
                 json_input = """
                 {{"credentials": "{}",
                 "url": "http://example.com",
                 "method": "GET",
                 "params": {{"a": 1, "b": 2}},
                 "headers": {{"c": 3, "d": 4}}}}
                 """.format(result.user.credentials.serialize())
                 
                 self.response.write('<h3>JSON Request elements</h3>')
                 re = authomatic.request_elements(json_input=json_input, return_json=True)
                 self.response.write('<pre class="prettyprint">{}</pre>'.format(re))
                 
                 # refresh credentials
                 response = result.user.credentials.refresh(force=True)
                 
                 if response:
                     self.response.write('<h3>Refresh status: {}</h3>'.format(response.status))
                     self.response.write('<pre class="prettyprint">{}</pre>'.format(response.content))
             
             self.response.write('<pre id="ui" class="prettyprint">{}</pre>'.format(cgi.escape(result.user.content or '')))
             
             self.response.write("""
             <script type="text/javascript">
                 ui = document.getElementById('ui');
                 try {{
                     ui.innerHTML = JSON.stringify({0}, undefined, 4);
                 }} catch(e) {{
                     console.log('XML');
                 }}
                     
             </script>
             """.format(result.user.content.replace('\n', ' ')) if result.user.content else '')
         
         self.response.write('<h3>Result js callback HTML</h3>')
         self.response.write('<pre class="prettyprint">{}</pre>'\
                             .format(cgi.escape(result.js_callback('callback', indent=4,
                                                                   custom=dict(foo='bar', baz="bing")))))
             
         
         self.response.write('</body></html>')
Пример #17
0
    def any(self, provider_name):

        result = authomatic.login(Webapp2Adapter(self), provider_name)

        if result:
            self.response.write("""<!DOCTYPE html><html>
            <head>
                <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=sunburst"></script>
            </head>
            """)

            self.response.write('<body>')
            self.response.write('<a href="..">Home</a> | ')
            self.response.write(
                '<a href="../login/{}">Retry</a>'.format(provider_name))

            if result.error:
                self.response.write('<h4>ERROR: {}</h4>'.format(
                    result.error.message))

                self.response.write('<h3>error to dict</h3>')
                self.response.write('<pre class="prettyprint">{}</pre>'.format(
                    result.error.to_dict()))

            elif result.user:
                response = result.user.update()
                if response:
                    self.response.write(
                        '<h3>User refresh status: {}</h3>'.format(
                            response.status))
                    self.response.write(
                        '<pre class="prettyprint">{}</pre>'.format(
                            response.content))

                    self.response.write('<h3>Access-Control-Allow-Origin</h3>')
                    self.response.write(
                        '<pre class="prettyprint">{}</pre>'.format(
                            response.getheader('Access-Control-Allow-Origin')))

                    self.response.write('<h3>User headers</h3>')
                    self.response.write(
                        '<pre class="prettyprint">{}</pre>'.format(
                            response.getheaders()))

                self.response.write('<h3>User</h3>')
                if result.user.picture:
                    self.response.write(
                        '<img src="{}" width="100" height="100" />'.format(
                            result.user.picture))

                loop(self, result.user)

                if result.user.credentials:
                    # loop through credentials attrs
                    self.response.write('<h3>Credentials</h3>')
                    self.response.write('<h5>expiration time: {}</h5>'.format(
                        result.user.credentials.expiration_time))
                    self.response.write('<h5>expiration date: {}</h5>'.format(
                        result.user.credentials.expiration_date))
                    loop(self, result.user.credentials)

                    self.response.write('<h3>Serialized credentials</h3>')
                    serialized_credentials = result.user.credentials.serialize(
                    )
                    endpoint_url = '/login/?type=elements&url=http://example.com&credentials=' + serialized_credentials
                    self.response.write(
                        '<a href="{}" target="_blank">{}</a>'.format(
                            endpoint_url, serialized_credentials))

                    json_input = """
                    {{"credentials": "{}",
                    "url": "http://example.com",
                    "method": "GET",
                    "params": {{"a": 1, "b": 2}},
                    "headers": {{"c": 3, "d": 4}}}}
                    """.format(result.user.credentials.serialize())

                    self.response.write('<h3>JSON Request elements</h3>')
                    re = authomatic.request_elements(json_input=json_input,
                                                     return_json=True)
                    self.response.write(
                        '<pre class="prettyprint">{}</pre>'.format(re))

                    # refresh credentials
                    response = result.user.credentials.refresh(force=True)

                    if response:
                        self.response.write(
                            '<h3>Refresh status: {}</h3>'.format(
                                response.status))
                        self.response.write(
                            '<pre class="prettyprint">{}</pre>'.format(
                                response.content))

                self.response.write(
                    '<pre id="ui" class="prettyprint">{}</pre>'.format(
                        cgi.escape(result.user.content or '')))

                self.response.write("""
                <script type="text/javascript">
                    ui = document.getElementById('ui');
                    try {{
                        ui.innerHTML = JSON.stringify({0}, undefined, 4);
                    }} catch(e) {{
                        console.log('XML');
                    }}
                        
                </script>
                """.format(result.user.content.replace('\n', ' ')) if result.
                                    user.content else '')

            self.response.write('<h3>Result js callback HTML</h3>')
            self.response.write('<pre class="prettyprint">{}</pre>'\
                                .format(cgi.escape(result.js_callback('callback', indent=4,
                                                                      custom=dict(foo='bar', baz="bing")))))

            self.response.write('</body></html>')