コード例 #1
0
def list_contacts():
    session_id = request.cookies.get('sessionID')
    if not session_id or session_id == '':
        return jsonify(dict(success=False, error='unauthorized'))
    user = Session.get_by_id(session_id)
    if not user:
        return jsonify(dict(success=False, error='unauthorized'))

    email = user.email
    # logging.info('email : {}'.format(email))
    cursor = request.args.get('cursor')
    if not cursor: cursor = None
    cursor = Cursor(urlsafe=cursor)
    query = Contacts.query(Contacts.owner == email).order(Contacts.name_lc)
    contacts, next_cursor, more = query.fetch_page(10, start_cursor=cursor)
    # logging.info('cursor: {} more: {}'.format(next_cursor, more))
    if next_cursor:
        cursor = next_cursor.urlsafe()
    else:
        cursor = None
    data = [contact.to_dict() for contact in contacts]

    return jsonify({
        'cursor': cursor,
        'more': more,
        'contacts': data,
        'success': True
    })
コード例 #2
0
def import_contacts():
    uuid = request.cookies.get('sessionID')
    entity = Session.get_by_id(uuid)

    if entity:
        email = entity.email
    else:
        return redirect('/')

    if (request.args.get('error') == 'access_denied'):
        return 'You denied the access'

    token_data = fetch_access_token(request.args.get('code'),
                                    config.get("CONTACTS_REDIRECT_URI"))

    user = User.get_by_id(email)
    user.set_token(token_data)
    user.import_status = "importing"
    user.put()
    taskqueue.add(url='/fetch-contacts',
                  params={
                      'email': email,
                      'access_token': token_data.get('access_token')
                  },
                  method='GET')

    return render_template('popup.html', success='true')
コード例 #3
0
def logout():
    uuid = request.cookies.get('sessionID')
    if uuid:
        entity = Session.get_by_id(uuid)
        if entity:
            entity.key.delete()
    res = redirect('/')
    res.set_cookie('sessionID', '')
    return res
コード例 #4
0
def index():
    sessionID = request.cookies.get('sessionID')
    if sessionID and sessionID != '':
        entity = Session.get_by_id(sessionID)
        if entity:
            email = entity.email
            user = User.get_by_id(email)
            if not user: return render_template('signin.html')
            import_status = user.import_status
            return render_template('index.html', import_status=import_status)
    return render_template('signin.html')
コード例 #5
0
def import_status():
    session_id = request.cookies.get('sessionID')
    if not session_id:
        return jsonify({'error': 'login_required'})

    entity = Session.get_by_id(session_id)
    if not entity:
        return jsonify({'error': 'login_required'})

    user = User.get_by_id(entity.email)
    if user:
        return jsonify({'import_status': user.import_status})
    else:
        return jsonify({'error': 'login_required'})
コード例 #6
0
ファイル: views.py プロジェクト: Grazen21/EngagementPlus
def get_session():
    user = validate_auth(request.headers.get('Authorization'))
    response = {}

    if user:
        payload = request.get_json()
        session_id = payload['session_id']

        main_graph = []
        face_count_graph = []
        raw = get_raw(user, session_id)
        session = Session.get_by_id(session_id)
        sum_of_emotions = {
            'anger': 0,
            'fear': 0,
            'disgust': 0,
            'contempt': 0,
            'neutral': 0,
            'sadness': 0,
            'happiness': 0,
            'surprise': 0
        }

        for record in raw:
            main_graph.append({
                'id': record['id'],
                'eng': calculate_engagement(record)
            })
            face_count_graph.append({
                'id': record['id'],
                'face_count': record['face_count']
            })
            sum_of_emotions = {
                key: sum_of_emotions[key] + record[key]
                for key in set(sum_of_emotions)
            }

        response['main'] = main_graph
        response['face_count'] = face_count_graph
        response['raw_emotions'] = sum_of_emotions
        response['session'] = {
            'title': session.title,
            'session_type': session.session_type,
            'description': session.description,
            'date': session.created_at
        }
        return jsonify(response), 200

    return response, 204
コード例 #7
0
def contacts_oauth():
    uuid = request.cookies.get('sessionID')
    entity = Session.get_by_id(uuid)
    if entity:
        email = entity.email
    else:
        return redirect('/')

    user = User.get_by_id(email)
    if user.import_status == "importing": return ""

    params = {
        'client_id': config.get("CLIENT_ID"),
        'scope': config.get("CONTACT_SCOPE"),
        'redirect_uri': config.get("CONTACTS_REDIRECT_URI"),
        'access_type': 'offline',
        'response_type': 'code',
        'prompt': 'consent'
    }

    return redirect('{}?{}'.format(config.get("OAUTH_ENDPOINT"),
                                   urlencode(params)))