def create_or_login(response):
    '''
    This is the hook for OpenID.try_login and is being called after a response
    has been received.
    '''

    session['user'] = {}
    session['openid'] = response.identity_url

    user = g.user or User.query.filter_by(openid=response.identity_url).first()

    if user is None:
        name = response.fullname or response.nickname
        session['user']['email'] = response.email
        params = dict(next=oid.get_next_url(), name = name)
        return redirect(url_for('.first_login', **params))

    g.user = user
    identity = Identity(user.id)

    # Notify Principal of the identity change
    identity_changed.send(
        current_app._get_current_object(),
        identity = identity
    )

    if user.openid != response.identity_url:
        user.openid = response.identity_url
        db_session.commit()
        flash(u'OpenID identity changed')
    else:
        flash(u'Successfully signed in', 'hurray')

    return redirect(oid.get_next_url())
def first_login():
    if g.user is not None or 'user' not in session:
        flash(u'Something weird happened.')
        return redirect(url_for('.login'))

    if request.method == 'POST':
        if 'cancel' in request.form:
            del session['openid']
            flash(u'Login was aborted')
            return redirect(url_for('authentication.login'))

        user = User(session['openid'], request.form['name'], session['user']['email'])
        user.generate_verification_token()
        db_session.add(user)
        db_session.commit()

        mailer.send(
            UserVerificationMessage, to=user.email,
            user_id=user.id, verification_token=user.verification_token
        )
        flash(u'Successfully created profile and logged in')
        return redirect(oid.get_next_url())

    return render_template(
        'authentication/first_login.html',
        next=oid.get_next_url(),
        openid=session['openid']
    )
Beispiel #3
0
def first_login():
    if g.user is not None or 'user' not in session:
        flash(u'Something weird happened.')
        return redirect(url_for('.login'))

    if request.method == 'POST':
        if 'cancel' in request.form:
            del session['openid']
            flash(u'Login was aborted')
            return redirect(url_for('authentication.login'))

        user = User(session['openid'], request.form['name'],
                    session['user']['email'])
        user.generate_verification_token()
        db_session.add(user)
        db_session.commit()

        mailer.send(UserVerificationMessage,
                    to=user.email,
                    user_id=user.id,
                    verification_token=user.verification_token)
        flash(u'Successfully created profile and logged in')
        return redirect(oid.get_next_url())

    return render_template('authentication/first_login.html',
                           next=oid.get_next_url(),
                           openid=session['openid'])
Beispiel #4
0
def create_or_login(response):
    '''
    This is the hook for OpenID.try_login and is being called after a response
    has been received.
    '''

    session['user'] = {}
    session['openid'] = response.identity_url

    user = g.user or User.query.filter_by(openid=response.identity_url).first()

    if user is None:
        name = response.fullname or response.nickname
        session['user']['email'] = response.email
        params = dict(next=oid.get_next_url(), name=name)
        return redirect(url_for('.first_login', **params))

    g.user = user
    identity = Identity(user.id)

    # Notify Principal of the identity change
    identity_changed.send(current_app._get_current_object(), identity=identity)

    if user.openid != response.identity_url:
        user.openid = response.identity_url
        db_session.commit()
        flash(u'OpenID identity changed')
    else:
        flash(u'Successfully signed in', 'hurray')

    return redirect(oid.get_next_url())
def login():
    if g.user is not None:
        return redirect(url_for('profile.view'))

    if 'cancel' in request.form:
        flash(u'Cancelled. The OpenID was not changed.')
        return redirect(oid.get_next_url())

    openid = request.values.get('openid')

    if not openid:
        openid = COMMON_PROVIDERS.get(request.args.get('provider'))

    if openid:
        return oid.try_login(openid, ask_for=['fullname', 'email', 'language'])

    error = oid.fetch_error()
    if error:
        flash(u'Error: ' + error)

    return render_template('authentication/login.html', next=oid.get_next_url())
Beispiel #6
0
def login():
    if g.user is not None:
        return redirect(url_for('profile.view'))

    if 'cancel' in request.form:
        flash(u'Cancelled. The OpenID was not changed.')
        return redirect(oid.get_next_url())

    openid = request.values.get('openid')

    if not openid:
        openid = COMMON_PROVIDERS.get(request.args.get('provider'))

    if openid:
        return oid.try_login(openid, ask_for=['fullname', 'email', 'language'])

    error = oid.fetch_error()
    if error:
        flash(u'Error: ' + error)

    return render_template('authentication/login.html',
                           next=oid.get_next_url())