예제 #1
0
def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')
     
    if checkEmail(me.data['email'])== False :
      url = "http://graph.facebook.com/"+ me.data['location']['id']
      result = urllib2.urlopen(url).read()
      result = json.loads(result)

      addUser(me.data['id'],me.data['username'], me.data['email'], 'abcde',me.data['location']['name'],resp['access_token'],"facebook",str(result['location']['longitude']),str(result['location']['latitude']))
      session['email'] = me.data['email'] 
      return redirect(url_for('profile'))      
    else:
      if userType(me.data['email']) == "facebook":
        session['email'] = me.data['email']
        return redirect(url_for('profile'))
      else:
        form = SigninForm()
        form.email.errors = ["Wrong Account Type"]
        return render_template('signin.html', form=form)
예제 #2
0
def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'], request.args['error_description'])
    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')

    if checkEmail(me.data['email']) == False:
        url = "http://graph.facebook.com/" + me.data['location']['id']
        result = urllib2.urlopen(url).read()
        result = json.loads(result)

        addUser(me.data['id'], me.data['username'], me.data['email'], 'abcde',
                me.data['location']['name'], resp['access_token'], "facebook",
                str(result['location']['longitude']),
                str(result['location']['latitude']))
        session['email'] = me.data['email']
        return redirect(url_for('profile'))
    else:
        if userType(me.data['email']) == "facebook":
            session['email'] = me.data['email']
            return redirect(url_for('profile'))
        else:
            form = SigninForm()
            form.email.errors = ["Wrong Account Type"]
            return render_template('signin.html', form=form)
예제 #3
0
def signup():
  form = SignupForm()

  if 'email' in session:
    return redirect(url_for('profile'))
   
  if request.method == 'POST':
    if form.validate() == False:
      return render_template('signup.html', form=form)
    else:

      addUser(None,form.username.data,form.email.data.lower(),form.password.data,form.location.data,"","Normal", form.lng.data , form.lat.data)

      session['email'] = form.email.data.lower()
      return redirect(url_for('profile'))

  elif request.method == 'GET':
    return render_template('signup.html', form=form)
예제 #4
0
def signup():
    form = SignupForm()

    if 'email' in session:
        return redirect(url_for('profile'))

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('signup.html', form=form)
        else:

            addUser(None, form.username.data, form.email.data.lower(),
                    form.password.data, form.location.data, "", "Normal",
                    form.lng.data, form.lat.data)

            session['email'] = form.email.data.lower()
            return redirect(url_for('profile'))

    elif request.method == 'GET':
        return render_template('signup.html', form=form)
예제 #5
0
    headers = {'Authorization': 'OAuth '+access_token}
    req = Request('https://www.googleapis.com/oauth2/v1/userinfo',
                  None, headers)
    try:
        res = urlopen(req)
    except URLError, e:
        if e.code == 401:
            # Unauthorized - bad token
            session.pop('access_token', None)
            return redirect(url_for('glogin'))

    res = json.load(res)
    if checkEmail(res['email'])== False :

      addUser(res['id'],res['name'],res['email'],"123",None, access_token , "google",None, None)
      session['email'] = res['email']

      return  redirect(url_for('profile'))    
    else:
      if userType(res['email']) == "google":
        session['email'] = res['email']

        return  redirect(url_for('profile'))
      else:
        form = SigninForm()
        form.email.errors = ["Wrong Account Type"]
        return render_template('signin.html', form=form)

@google.tokengetter
def get_access_token():
예제 #6
0
    headers = {'Authorization': 'OAuth ' + access_token}
    req = Request('https://www.googleapis.com/oauth2/v1/userinfo', None,
                  headers)
    try:
        res = urlopen(req)
    except URLError, e:
        if e.code == 401:
            # Unauthorized - bad token
            session.pop('access_token', None)
            return redirect(url_for('glogin'))

    res = json.load(res)
    if checkEmail(res['email']) == False:

        addUser(res['id'], res['name'], res['email'], "123", None,
                access_token, "google", None, None)
        session['email'] = res['email']

        return redirect(url_for('profile'))
    else:
        if userType(res['email']) == "google":
            session['email'] = res['email']

            return redirect(url_for('profile'))
        else:
            form = SigninForm()
            form.email.errors = ["Wrong Account Type"]
            return render_template('signin.html', form=form)


@google.tokengetter