Exemplo n.º 1
0
    def test_add_existing_user_to_association(self, user):
        session = Client().session()

        association = Association(name='prancing ponies')
        session.add(association)
        session.flush()
        session.add(UserAssociation(user_id=user.user_id,
                                    association_id=association.association_id))
        other_user = User(email_verified_at=utcnow(), email='*****@*****.**')
        session.add(other_user)
        session.flush()

        response = self.app.post(
            '/association/{0}/invite_user'.format(association.association_id),
            data={'email': '*****@*****.**'})
        eq_(response.status_code, 200, response.data)
        body = json.loads(response.data)
        eq_(body, {'status': 'ok', 'action': 'added'})

        user_associations = session.query(
            UserAssociation.user_id, UserAssociation.association_id).\
            all()
        eq_(user_associations, [
            (user.user_id, association.association_id),
            (other_user.user_id, association.association_id),
            ])
Exemplo n.º 2
0
def token_url():
    token = request.form['token']
    api_params = {
        'token': token,
        'apiKey': os.environ['ENGAGE_API_KEY'],
        'format': 'json',
    }

    response = requests.get('https://rpxnow.com/api/v2/auth_info',
                            params=api_params)
    auth_info = json.loads(response.text)
    if 'profile' not in auth_info:
        return make_response('An error occurred interacting with your '
                             'identity provider. Since that does not '
                             'usually happen unless you are a radlibs '
                             'developer, here is the error in all its '
                             'terrible beauty: ' + response.text)
    identifier = auth_info['profile']['identifier']
    email = auth_info['profile'].get('email')
    redirect_uri = request.form.get('redirect_uri', '/')

    db_session = Client().session()
    try:
        user = db_session.query(User).\
            filter(User.identifier == identifier).\
            one()
    except NoResultFound:
        if email:
            existing_users = db_session.query(User).\
                filter(User.email == email).\
                all()
            if existing_users:
                provider = provider_for_identifier(
                    existing_users[0].identifier)
                return render_template(
                    'identifier_mismatch.html.jinja',
                    existing_provider=provider)
            user = User(email=email,
                        identifier=identifier,
                        email_verified_at=utcnow())
            db_session.add(user)
        else:
            session['partial_user'] = {'identifier': identifier}
            return redirect(url_for('show_registration',
                                    redirect_uri=redirect_uri))

    session['user'] = {'identifier': identifier, 'email': email}
    return redirect(redirect_uri)
Exemplo n.º 3
0
def verify_email(token):
    db_session = Client().session()
    try:
        verification_token = db_session.query(EmailVerificationToken).\
            filter(EmailVerificationToken.token == token).\
            one()

        user = db_session.query(User).\
            filter(User.user_id == verification_token.user_id).\
            one()
    except NoResultFound:
        abort(404)
    user.email_verified_at = utcnow()
    db_session.add(user)
    db_session.delete(verification_token)

    return render_template('verification_complete.html.jinja')
Exemplo n.º 4
0
def accept_invitation(token):
    if not g.user:
        return render_template('invitation_registration.html.jinja')
    session = Client().session()
    try:
        invite = session.query(AssociationInvite).\
            filter(AssociationInvite.token == token).\
            one()
    except NoResultFound:
        abort(404)
    if invite.email != g.user.email:
        raise StandardError('Logged-in user had email {0} and a token for an '
                            'invite for {1}'.format(g.user.email, invite.email))
    session.add(UserAssociation(association_id=invite.association_id,
                                user_id=g.user.user_id))
    session.delete(invite)

    if g.user.email_verified_at is None:
        g.user.email_verified_at = utcnow()
        session.add(g.user)
    return redirect(url_for('manage_association',
                            association_id=invite.association_id))
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super(Rad, self).__init__(*args, **kwargs)
     if self.created_at is None:
         self.created_at = utcnow()