コード例 #1
0
ファイル: app.py プロジェクト: vbraun/sagepad
def create_or_login(resp):
    openid = resp.identity_url
    print 'create_or_login', resp, openid
    if not isinstance(openid, basestring):
        flash(u'Incorrect or invalid OpenID, could not sign in')
        return redirect(url_for('index'))
    flask.session['openid'] = openid
    try:
        user = User.lookup(resp.identity_url)
        flask.g.user = user
        flash(u'Welcome back, '+user.fullname())
    except UserInvalidId:
        print request.form
        fullname = resp.fullname
        nickname = resp.nickname
        email = resp.email
        user = User.make(openid, fullname, nickname, email)
        flask.g.user = user
        flask.session.permanent = True
        flash(u'Thank you for signing in, '+user.fullname())
    return redirect(url_for('index'))
コード例 #2
0
ファイル: app.py プロジェクト: vbraun/sagepad
def lookup_current_user():
    try:
        user = flask.g.user
        return
    except AttributeError:
        pass
    # find user
    try:
        openid = flask.session['openid']
    except KeyError:
        try:
            openid = flask.session['anonymous_openid']
        except KeyError:
            openid = None
    #print 'lookup: '+str(openid)
    try:
        user = User.lookup(openid)
    except UserInvalidId:
        user = User.anonymous()
        flask.session.pop('openid', None)
        flask.session['anonymous_openid'] = user.get_id()
    flask.g.user = user