示例#1
0
def login_view():
    """Login view for authenticating using OpenID."""
    if g.user is not None:
        return redirect(openid.get_next_url())

    error = openid.fetch_error()
    if request.method == 'POST':
        oid = request.form.get('openid')
        if oid:
            return openid.try_login(
                oid,
                ask_for=['email', 'fullname', 'nickname'])
        else:
            error = 'You need to specify a valid OpenID to continue'

    return render_template(
        'login.html',
        next=openid.get_next_url(),
        error=error)
示例#2
0
def login_openid(response):
    """Login the user after a successful OpenID authentication.

    If the user is not found in the database the login will be rejected. If the
    user is found, the user will be updated with the fullkname and email
    returned by the Provider and the session will be authenticated.
    """
    user = User.query.filter(User.openid == response.identity_url).first()
    if user:
        user.name = response.fullname
        user.email = response.email
        user.save()

        g.user = user
        session["openid"] = user.openid
    else:
        flash(
            "Your account doesn't have access to this system.",
            category="error")

    return redirect(openid.get_next_url())
示例#3
0
def logout_view():
    session.pop('openid', None)
    flash('You were successfully signed out from Authz')
    return redirect(openid.get_next_url())