Пример #1
0
def _user_get():
    """Enforce authenticated user"""
    uid = session.get('uid')
    user = _user.find_one({'uid': uid})
    if not user and 'uid' in session:
        session.pop('uid')
    return user
Пример #2
0
def userinfo():
    import pprint

    uid = session.get('uid')
    user = None
    migrate_data = None

    if uid:
        user = _user.find_one({'uid': uid})
        if user:
            if not user['migrated']:
                migrate_data = google.drive_get_migration_diagnostics(user)

            del user['_id']
            try:
                del user['google']['credentials']
            except KeyError:
                pass
            user = pprint.pformat(user, indent=4)
            migrate_data = pprint.pformat(migrate_data, indent=4)

    return render_template('userinfo.html',
                           uid=uid,
                           user=user,
                           migrate_data=migrate_data)
Пример #3
0
def google_auth_verify():
    """Finalize google authorization"""
    try:
        if 'error' in request.args:
            raise Exception(
                _format_err('Error getting authorization',
                            request.args.get('error')))

        code = _request_get_required('code')

        flow = OAuth2WebServerFlow(settings.GOOGLE_CLIENT_ID,
                                   settings.GOOGLE_CLIENT_SECRET,
                                   _GOOGLE_OAUTH_SCOPES,
                                   redirect_uri=_build_oauth_redirect(
                                       request, url_for('google_auth_verify')))
        credentials = flow.step2_exchange(code)
        # ^ this is an oauth2client.client.OAuth2Credentials object

        # Get user info
        userinfo = google.get_userinfo(
            google.get_userinfo_service(credentials))
        if not userinfo:
            raise Exception('Could not get Google user info')

        info = {
            'id': userinfo.get('id'),
            'name': userinfo.get('name'),
            'credentials': credentials.to_json()
        }
        if not info['id']:
            raise Exception('Could not get Google user ID')

        if 'storymap.knilab.com' in domains and not info['id'] in allowed_ids:
            print('User id not in ALLOWED_IDS:  %s ' % info['id'])
            raise Exception(
                'You are not authorized to access this page. Please send the following information to [email protected]: storymap.knilab.com unauthorized %s'
                % info['id'])

        # Upsert user record
        uid = _get_uid('google:' + info['id'])

        user = _user.find_one({'uid': uid})
        if user:
            user['google'] = info
        else:
            user = {'uid': uid, 'migrated': 0, 'storymaps': {}, 'google': info}
        user['uname'] = info['name']
        _user.save(user)

        # Update session
        session['uid'] = uid
        url = url_for('select')

        app.logger.info("google_auth_verify url: {}".format(url))
        return redirect(url)
    except Exception, e:
        traceback.print_exc()
        return jsonify({'error': str(e)})
Пример #4
0
def _user_get():
    """Enforce authenticated user"""
    uid = session.get('uid')
    user = _user.find_one({'uid': uid})
    # google data field in user record no longer used
    if 'google' in user:
        del user['google']
    if not user and 'uid' in session:
        session.pop('uid')
    return user
Пример #5
0
def check_test_user():
    if settings.TEST_MODE:
        if not _user.find_one({ 'uid': 'test' }):
            _user.insert({
                'uid': 'test',
                'migrated': 1,
                'storymaps': {},
                'google': { 'name': 'Test User' }
            })
        session['uid'] = 'test'
Пример #6
0
def _user_get():
    """Enforce authenticated user"""
    uid = session.get("uid")
    if not uid:
        return redirect(url_for("select"))
    user = _user.find_one({"uid": uid})
    if not user:
        session.pop("uid")
        return redirect(url_for("select"))
    return user
Пример #7
0
def _user_get():
    """Enforce authenticated user"""
    uid = session.get('uid')
    if not uid:
        return redirect(url_for('select'))
    user = _user.find_one({'uid': uid})
    if not user:
        session.pop('uid')
        return redirect(url_for('select'))
    return user
Пример #8
0
def _user_get():
    """Enforce authenticated user"""
    uid = session.get('uid')
    user = _user.find_one({'uid': uid})
    # google data field in user record no longer used
    if 'google' in user:
        del user['google']
    if not user and 'uid' in session:
        session.pop('uid')
    return user
Пример #9
0
def check_test_user():
    if settings.TEST_MODE:
        if not _user.find_one({ 'uid': 'test' }):
            _user.insert({
                'uid': 'test',
                'migrated': 1,
                'storymaps': {},
                'google': { 'name': 'Test User' }
            })
        session['uid'] = 'test'
Пример #10
0
def google_auth_verify():
    """Finalize google authorization"""
    try:
        if 'error' in request.args:
            raise Exception(_format_err(
                'Error getting authorization', request.args.get('error')))

        code = _request_get_required('code')

        flow = OAuth2WebServerFlow(
            settings.GOOGLE_CLIENT_ID,
            settings.GOOGLE_CLIENT_SECRET,
            _GOOGLE_OAUTH_SCOPES,
            redirect_uri='https://'+request.host+url_for('google_auth_verify')
        )
        credentials = flow.step2_exchange(code)
        # ^ this is an oauth2client.client.OAuth2Credentials object

        # Get user info
        userinfo = google.get_userinfo(
            google.get_userinfo_service(credentials))
        if not userinfo:
            raise Exception('Could not get Google user info')

        info = {
            'id': userinfo.get('id'),
            'name': userinfo.get('name'),
            'credentials': credentials.to_json()
        }
        if not info['id']:
            raise Exception('Could not get Google user ID')

        # Upsert user record
        uid = _get_uid('google:'+info['id'])

        user = _user.find_one({'uid': uid})
        if user:
            user['google'] = info
        else:
            user = {
                'uid': uid,
                'migrated': 0,
                'storymaps': {},
                'google': info
            }
        user['uname'] = info['name']
        _user.save(user)

        # Update session
        session['uid'] = uid

        return redirect(url_for('select'))
    except Exception, e:
        traceback.print_exc()
        return jsonify({'error': str(e)})
Пример #11
0
def userinfo():
    import pprint

    uid = session.get('uid')
    user = None

    if uid:
        user = _user.find_one({'uid': uid})
        if user:
            del user['_id']
            user = pprint.pformat(user, indent=4)

    return render_template('userinfo.html', uid=uid, user=user)
Пример #12
0
def _user_get():
    """Enforce authenticated user"""
    uid = session.get('uid')
    user = _user.find_one({'uid': uid})
    # google data field in user record no longer used
    if not user:
        try:
            session.pop('uid')
        except KeyError: pass
        return None
    if 'google' in user:
        del user['google']
    return user
Пример #13
0
def userinfo():
    import pprint
    
    uid = session.get('uid')
    user = None
    
    if uid:
        user = _user.find_one({'uid': uid})
        if user:
            del user['_id']
            user = pprint.pformat(user, indent=4)            
            
    return render_template('userinfo.html',
        uid=uid, user=user)
Пример #14
0
def select():
    try:
        uid = session.get("uid")
        if not uid:
            return render_template("select.html")

        user = _user.find_one({"uid": uid})
        if not user:
            _session_pop("uid")
            return render_template("select.html")
        del user["_id"]

        return render_template("select.html", user=user)
    except Exception, e:
        traceback.print_exc()
        return render_template("select.html", error=str(e))
Пример #15
0
def select():
    try:
        uid = session.get('uid')
        if not uid:
            return render_template('select.html')

        user = _user.find_one({'uid': uid})
        if not user:
            _session_pop('uid')
            return render_template('select.html')
        del user['_id']

        return render_template('select.html', user=user)
    except Exception, e:
        traceback.print_exc()
        return render_template('select.html', error=str(e))
Пример #16
0
def google_auth_verify():
    """Finalize google authorization"""
    try:
        if "error" in request.args:
            raise Exception(_format_err("Error getting authorization", request.args.get("error")))

        code = _request_get_required("code")

        flow = OAuth2WebServerFlow(
            settings.GOOGLE_CLIENT_ID,
            settings.GOOGLE_CLIENT_SECRET,
            _GOOGLE_OAUTH_SCOPES,
            redirect_uri="https://" + request.host + url_for("google_auth_verify"),
        )
        credentials = flow.step2_exchange(code)
        # ^ this is an oauth2client.client.OAuth2Credentials object

        # Get user info
        userinfo = google.get_userinfo(google.get_userinfo_service(credentials))
        if not userinfo:
            raise Exception("Could not get Google user info")

        info = {"id": userinfo.get("id"), "name": userinfo.get("name"), "credentials": credentials.to_json()}
        if not info["id"]:
            raise Exception("Could not get Google user ID")

        # Upsert user record
        uid = _get_uid("google:" + info["id"])

        user = _user.find_one({"uid": uid})
        if user:
            user["google"] = info
        else:
            user = {"uid": uid, "migrated": 0, "storymaps": {}, "google": info}
        user["uname"] = info["name"]
        _user.save(user)

        # Update session
        session["uid"] = uid

        return redirect(url_for("select"))
    except Exception, e:
        traceback.print_exc()
        return jsonify({"error": str(e)})
Пример #17
0
def userinfo():
    import pprint
    
    uid = session.get('uid')
    user = None
    migrate_data = None
    
    if uid:
        user = _user.find_one({'uid': uid})
        if user:
            if not user['migrated']:
                migrate_data = google.drive_get_migration_diagnostics(user)
 
            del user['_id']
            user = pprint.pformat(user, indent=4) 
            migrate_data = pprint.pformat(migrate_data, indent=4) 
            
            
    return render_template('userinfo.html',
        uid=uid, user=user, migrate_data=migrate_data)
Пример #18
0
def userinfo():
    import pprint

    uid = session.get("uid")
    user = None
    migrate_data = None

    if uid:
        user = _user.find_one({"uid": uid})
        if user:
            if not user["migrated"]:
                migrate_data = google.drive_get_migration_diagnostics(user)

            del user["_id"]
            try:
                del user["google"]["credentials"]
            except KeyError:
                pass
            user = pprint.pformat(user, indent=4)
            migrate_data = pprint.pformat(migrate_data, indent=4)

    return render_template("userinfo.html", uid=uid, user=user, migrate_data=migrate_data)