Пример #1
0
def auth_google_after(resp):
    if resp is None:
        return 'Access denied: ' \
               'reason={0.error_reason} error={0.error_description}' \
            .format(request.args)
    elif isinstance(resp, OAuthException):
        return redirect(url_for('.auth_google'))
    id_token = decode_jwt(resp['id_token'])
    user_key = id_token['user_id']
    s = get_session()
    try:
        cred = s.query(GoogleOAuth2).filter_by(key=user_key).one()
    except NoResultFound:
        # 회원가입
        token = (resp['access_token'], '')
        r = google_oauth2.get('oauth2/v3/userinfo', token=token)
        userinfo = r.data
        user = User(None, userinfo['name'], status=UserStatus.unregistered)
        user.emails.append(Email(userinfo['email'], verified=True))
        user.primary_email = userinfo['email']
        cred = GoogleOAuth2(user, resp, user_key=user_key)
        s.add(user)
        s.add(cred)
        s.commit()
    if cred.user.status == UserStatus.unregistered:
        return register_form(cred.user)
    else:
        # 로그인
        cred.token = resp
        s.commit()
        flask.ext.login.login_user(cred.user)
        next_url = request.values.get('next', resource_url(cred.user))
        return redirect(next_url)
Пример #2
0
def user(app):
    with app.app_context():
        session = get_session()
        user = User(u"eunchongyu", u"유은총", (u"*****@*****.**",), status=UserStatus.active)
        session.add(user)
        session.commit()
        return user.get_id()
Пример #3
0
def auth_google_after(resp):
    if resp is None:
        return "Access denied: " "reason={0.error_reason} error={0.error_description}".format(request.args)
    elif isinstance(resp, OAuthException):
        return redirect(url_for(".auth_google"))
    id_token = decode_jwt(resp["id_token"])
    user_key = id_token["user_id"]
    s = get_session()
    try:
        cred = s.query(GoogleOAuth2).filter_by(key=user_key).one()
    except NoResultFound:
        # 회원가입
        token = (resp["access_token"], "")
        r = google_oauth2.get("oauth2/v3/userinfo", token=token)
        userinfo = r.data
        user = User(None, userinfo["name"], status=UserStatus.unregistered)
        user.emails.append(Email(userinfo["email"], verified=True))
        user.primary_email = userinfo["email"]
        cred = GoogleOAuth2(user, resp, user_key=user_key)
        s.add(user)
        s.add(cred)
        s.commit()
    if cred.user.status == UserStatus.unregistered:
        return register_form(cred.user)
    else:
        # 로그인
        cred.token = resp
        s.commit()
        flask.ext.login.login_user(cred.user)
        next_url = request.values.get("next", resource_url(cred.user))
        return redirect(next_url)
Пример #4
0
def user(app):
    with app.app_context():
        session = get_session()
        user = User(u'eunchongyu',
                    u'유은총', (u'*****@*****.**', ),
                    status=UserStatus.active)
        session.add(user)
        session.commit()
        return user.get_id()
Пример #5
0
def test_user(session):
    """Check that users can be created and can set their password"""
    u = User(u'testuser', u'Test User', status=UserStatus.active)
    # Check authentication/permissions
    assert u.is_authenticated()
    assert u.active
    assert not u.pk
    session.add(u)
    session.commit()
    assert isinstance(u.pk, uuid.UUID)
Пример #6
0
def test_user(session):
    """Check that users can be created and can set their password"""
    u = User(u'testuser', u'Test User', status=UserStatus.active)
    # Check authentication/permissions
    assert u.is_authenticated()
    assert u.active
    assert not u.pk
    session.add(u)
    session.commit()
    assert isinstance(u.pk, uuid.UUID)
Пример #7
0
def test_basic_group(session):
    u1 = User(u'test1', u'Testimonial', status=UserStatus.active)
    u2 = User(u'test2', u'Testifier', status=UserStatus.active)
    session.add(u1)
    session.add(u2)
    group = Group(u'Recommended', users=[u1])
    session.add(group)
    assert u1 in {u.user for u in group.users}
    assert u2 not in {u.user for u in group.users}
    assert group in {g.group for g in u1.group_assocs}
    assert group not in {g.group for g in u2.group_assocs}
Пример #8
0
def test_get_picture_url():
    user = User(u'eunchong', u'은총', ['*****@*****.**'],
                status=UserStatus.active)
    url = user.picture_url()
    assert url.startswith('http')
Пример #9
0
def test_get_picture_url():
    user = User(u'eunchong',
                u'은총', ['*****@*****.**'],
                status=UserStatus.active)
    url = user.picture_url()
    assert url.startswith('http')