Example #1
0
def idplogin():
    """Does the login via OpenID.  Has to call into `oid.try_login`
    to start the OpenID machinery.
    """
    # log('%s:%d:login g.user = %s' % (__file__,__LINE__(),g.user) )
    di.d3('login g.user = %s' % (g.user) )
    # if we are already logged in, go back to were we came from
    if g.user is not None:
        return redirect(oid.get_next_url())
    if request.method == 'POST':
        openid = request.form.get('openid')
        source = request.form.get('source')
        # log('%s:%d:login with open ID "%s", source = "%s"' % (__file__,__LINE__(),openid, source))
        di.d3('login with open ID "%s", source = "%s"' % (openid, source))
        if openid:
            pape_req = pape.Request([])
            return oid.try_login(openid, ask_for=['email', 'nickname'],
                                         ask_for_optional=['fullname','dob'],
                                         extensions=[pape_req])
        if source:
            #openid = sources[source]
            openid = ei_dict[source]['discovery-url']
            #print >> sys.stderr, 'source = %s, openid = %s' % ( source, openid )
            # log('%s:%d:login with open ID "%s", source = "%s"' % (__file__,__LINE__(),openid, source))
            di.d3('login with open ID "%s", source = "%s"' % (openid, source))
            pape_req = pape.Request([])
            return oid.try_login(openid, ask_for=['email', 'nickname'],
                                         ask_for_optional=['fullname','dob'],
                                         extensions=[pape_req])
    return render_template('cpslogin.html', next=oid.get_next_url(),
                           error=oid.fetch_error(), items=ei_dict)
    """The following strings can be used in the ask_for and 
Example #2
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('idp_page.index'))
    if request.method == 'POST':
        for k in request.form:
            di.d3("form[%s] = %s" % (k,request.form[k]))
        username = request.form['name']
        fname = None
        lname = None
        email = request.form['email']
        affiliation = None
        password = '******'
        credit = 50
        uuid = None
        openid = session['openid']
        di.d3("username = %s" % username)
        di.d3("not username = %s" % (not username))
        if not username:
            flash(u'Error: you have to provide a name')
        elif '@' not in email:
            flash(u'Error: you have to enter a valid email address')
        else:
            di.d2('Profile successfully created')
            flash(u'Profile successfully created')
            create_user(username, fname, lname, email, affiliation, password, credit, uuid, openid)
            #db_session.add(new_user)
            #db_session.commit()
            return redirect(oid.get_next_url())
    return render_template('cpscreate_profile.html', next_url=oid.get_next_url())
Example #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
    if 'pape' in resp.extensions:
        pape_resp = resp.extensions['pape']
        session['auth_time'] = pape_resp.auth_time
    user = User.query.filter_by(openid=resp.identity_url).first()
    if user is not None:
        flash(u'Successfully signed in')
        g.user = user
        return redirect(oid.get_next_url())
    for key in flask_openid.COMMON_PROVIDERS:
        val = flask_openid.COMMON_PROVIDERS[key]
        di.d3("COMMON_PROVIDER %s => %s" % (key, val))
    di.d3("oid.get_next_url() = %s " % (oid.get_next_url()))
    #for key in resp:
    #    val = resp.key
    #    di.d3("resp.%s = %s" % (key, val))
    return redirect(url_for('idp_page.create_profile', next=oid.get_next_url(),
                            name='F '+resp.fullname or 'N '+resp.nickname,
                            dob=resp.date_of_birth or 'dob?',
                            date_of_birth=resp.date_of_birth or 'date_of_birth?',
                            email=resp.email))
    return redirect(url_for('idp_page.create_profile', next=oid.get_next_url(),
                            name=resp.fullname or resp.nickname,
                            email=resp.email))
Example #4
0
def Xidplogin():
    log("%s:%d:Gotcha: /idplogin" % (__file__,__LINE__() ))
    #log( pprint.pformat ( request.environ['wsgi.errors'] ) )
    res = "<html><head><title>Success</title></head><body>IDP-test geslaagd</body></html>"
    #global oid
    try:
#        from cpsdirector import app
#        oid = OpenID(app, safe_roots=[], extension_responses=[pape.Response])
        log("%s:%d:next = %s" % (__file__,__LINE__(), oid.get_next_url() ) )
        log("%s:%d:ei_dict = %s" % (__file__,__LINE__(),  pprint.pformat(ei_dict) ) )
        #res = render_template('cpslogin.html', items=ei_dict, next='blah', error='foutje')
        res = render_template('cpslogin.html', next=oid.get_next_url(), error=oid.fetch_error(), items=ei_dict)
    except BuildError as error:
        log ("%s:%d:error = %s" % (__file__,__LINE__(), error) )
        res = "<html><head><title>Failure</title></head><body>IDP-test mislukt:<br> BuildError: %s </body></html>" % error
    return build_response( res )
Example #5
0
def logout():
    session.pop('openid', None)
    flash(u'You have been signed out')
    return redirect(oid.get_next_url())