def register(): if not 'user_id' in session: return redirect('/login') form = RegisterForm() if form.validate_on_submit(): user = app.db.User.get(session['user_id']) user.name = form.name.data app.db.session.commit() flash('Pleased to meet you, %s!' % form.name.data) return redirect(request.args['r']) return render('account/register.html', form=form)
if form.validate_on_submit(): realm = url_for('index', _external=True) return_to = url_for('.openid_return', r=request.args.get('r', '/home'), _external=True) try: auth_req = make_consumer().begin(form.openid.data) auth_req.addExtension(sreg.SRegRequest(optional=['nickname', 'fullname'])) return redirect(auth_req.redirectURL(realm, return_to)) except DiscoveryFailure, e: form.errors['openid'] = [e.message] return render('account/login.html', form=form) def make_consumer(): # FIXME - This will not work on Heroku. openid_store = MemcacheStore() consumer = Consumer(session, openid_store) return consumer def set_session_user(user): session['user_id'] = user.id session.permanent = True @bp.route('/openid-return') def openid_return(): return_to = url_for('.openid_return', _external=True) result = make_consumer().complete(request.args, return_to)