示例#1
0
文件: views.py 项目: rjm535/5Minutes
def login():
    """Does the login via OpenID.  Has to call into `oid.try_login`
    to start the OpenID machinery.
    """
    # if we are already logged in, go back to were we came from
    if g.user is not None:
        oid_url = oid.get_next_url()
        if oid_url.endswith('login'):
            # Don't redirect to the login page ever.
            oid_url = url_for('index')

        return redirect(oid_url)

    if request.method == 'POST':
        openid = request.form.get('openid')
        if openid:
            return oid.try_login(openid, ask_for=['email', 'fullname',
                                                  'nickname'])
    err = oid.fetch_error()
    if err:
        flash(err, 'error')

    return render_template('login.html', next=oid.get_next_url(),
                           openid_domain=app.config['OPENID_DOMAIN'],
                           id_url='https://www.google.com/accounts/o8/id')
示例#2
0
文件: views.py 项目: rjm535/5Minutes
def create_or_login(resp):
    """This is called when login with OpenID succeeded and it's not
    necessary to figure out if this is the users's first login or not.
    This function has to redirect otherwise the user will be presented
    with a terrible URL which we certainly don't want.
    """
    session['openid'] = resp.identity_url
    user = User.query.filter_by(openid=resp.identity_url).first()
    if not resp.email.endswith('@{}'.format(app.config['OPENID_DOMAIN'])):
        flash('You must be logged in to your {} Google account to continue.'.format(app.config['OPENID_DOMAIN']), 'error')
        return redirect(url_for('index'))
    if user is not None:
        flash(u'Successfully signed in', 'success')
        g.user = user
        return redirect(oid.get_next_url())
    return redirect(url_for('create_profile', next=oid.get_next_url(),
                            name=resp.fullname or resp.nickname,
                            email=resp.email))
示例#3
0
def create_or_login(resp):
    """This is called when login with OpenID succeeded and it's not
    necessary to figure out if this is the users's first login or not.
    This function has to redirect otherwise the user will be presented
    with a terrible URL which we certainly don't want.
    """
    session['openid'] = resp.identity_url
    user = User.query.filter_by(openid=resp.identity_url).first()
    if not resp.email.endswith('@britecore.com'):
        flash('You must be logged in to your britecore.com email to continue.', 'error')
        return redirect(url_for('index'))
    if user is not None:
        flash(u'Successfully signed in', 'success')
        g.user = user
        return redirect(oid.get_next_url())
    return redirect(url_for('create_profile', next=oid.get_next_url(),
                            name=resp.fullname or resp.nickname,
                            email=resp.email))
示例#4
0
def create_profile():
    """If this is the user's first login, the create_or_login function
    will redirect here so that the user can set up his profile.
    """
    if g.user is not None or 'openid' not in session:
        return redirect(url_for('index'))
    if request.method == 'POST':
        name = request.form['name']
        email = request.form['email']
        if not name:
            flash(u'Error: you have to provide a name', 'error')
        elif '@' not in email:
            flash(u'Error: you have to enter a valid email address', 'error')
        else:
            flash(u'Profile successfully created', 'success')
            user = User(name, email, session['openid'])
            user.insert()
            safe_commit()
            return redirect(oid.get_next_url())
    return render_template('create_profile.html', next_url=oid.get_next_url())
示例#5
0
def login():
    """Does the login via OpenID.  Has to call into `oid.try_login`
    to start the OpenID machinery.
    """
    # if we are already logged in, go back to were we came from
    if g.user is not None:
        oid_url = oid.get_next_url()
        if oid_url.endswith('login'):
            # Don't redirect to the login page ever.
            oid_url = url_for('index')

        return redirect(oid_url)

    if request.method == 'POST':
        openid = request.form.get('openid')
        if openid:
            return oid.try_login(openid, ask_for=['email', 'fullname',
                                                  'nickname'])
    err = oid.fetch_error()
    if err:
        flash(err, 'error')

    return render_template('login.html', next=oid.get_next_url(),
                           id_url='https://www.google.com/accounts/o8/id')