Skip to content
Snippets Groups Projects
Select Git revision
  • 48b2b5751ef5a22638f30e292015095f564aafbb
  • master default protected
  • feat/new-image-formats
  • clickable-select-chevron
  • 2.20.0
  • 2.19.0
  • 2.18.0
  • 2.17.0
  • 2.16.1
  • 2.16.0
  • 2.15.0
  • 2.14.0
  • 2.13.0
  • 2.12.1
  • 2.11.0
  • 2.10.0
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.1
  • 2.7.0
  • 2.6.0
  • 2.5.2
  • 2.5.1
24 results

navbar.pcss

Blame
  • google.py 2.33 KiB
    """
    Google Authentication
    
    """
    
    from django.http import *
    from django.core.mail import send_mail
    from django.conf import settings
    
    import httplib2,json
    
    import sys, os, cgi, urllib, urllib2, re
    
    from oauth2client.client import OAuth2WebServerFlow
    
    # some parameters to indicate that status updating is not possible
    STATUS_UPDATES = False
    
    # display tweaks
    LOGIN_MESSAGE = "Log in with my Google Account"
    
    def get_flow(redirect_url=None):
      return OAuth2WebServerFlow(client_id=settings.GOOGLE_CLIENT_ID,
                client_secret=settings.GOOGLE_CLIENT_SECRET,
                scope='profile email',
                redirect_uri=redirect_url)
    
    def get_auth_url(request, redirect_url):
      flow = get_flow(redirect_url)
    
      request.session['google-redirect-url'] = redirect_url
      return flow.step1_get_authorize_url()
    
    def get_user_info_after_auth(request):
      flow = get_flow(request.session['google-redirect-url'])
    
      if not request.GET.has_key('code'):
        return None
      
      code = request.GET['code']
      credentials = flow.step2_exchange(code)
    
      # the email address is in the credentials, that's how we make sure it's verified
      id_token = credentials.id_token
      if not id_token['email_verified']:
        raise Exception("email address with Google not verified")
       
      email = id_token['email']
    
      # get the nice name
      http = httplib2.Http(".cache")
      http = credentials.authorize(http)
      (resp_headers, content) = http.request("https://people.googleapis.com/v1/people/me?personFields=names", "GET")
    
      response = json.loads(content)
    
      name = response['names'][0]['displayName']
      
      # watch out, response also contains email addresses, but not sure whether thsoe are verified or not
      # so for email address we will only look at the id_token
      
      return {'type' : 'google', 'user_id': email, 'name': name , 'info': {'email': email}, 'token':{}}
        
    def do_logout(user):
      """
      logout of Google
      """
      return None
      
    def update_status(token, message):
      """
      simple update
      """
      pass
    
    def send_message(user_id, name, user_info, subject, body):
      """
      send email to google users. user_id is the email for google.
      """
      send_mail(subject, body, settings.SERVER_EMAIL, ["%s <%s>" % (name, user_id)], fail_silently=False)
      
    def check_constraint(constraint, user_info):
      """
      for eligibility
      """
      pass
    
    
    #
    # Election Creation
    #
    
    def can_create_election(user_id, user_info):
      return True