2014-10-30 106 views
0

我正在關注本教程here。登錄頁面顯示登錄頁面。當我點擊任何提供者時,點擊提交按鈕,頁面會被重定向回登錄頁面。我在這裏做錯了什麼?我在views.py頁燒瓶對重定向的懷疑

@app.route('/login', methods=['GET', 'POST']) 
@oid.loginhandler 
def login(): 
    if g.user is not None and g.user.is_authenticated(): 
    return redirect(url_for('index')) 
    form = LoginForm() 
    if form.validate_on_submit(): 
    session['remember_me'] = form.remember_me.data 
    return oid.try_login(form.openid.data, ask_for=['nickname', 'email']) 
    return render_template('login.html', 
         title='Sign In', 
         form=form, 
         providers=app.config['OPENID_PROVIDERS']) 

@oid.after_login 
def after_login(resp): 
    if resp.email is None or resp.email=="": 
      flash('Invalid login. Please try again') 
      return redirect(url_for('login')) 
    user=User.query.filter_by(email=resp.email).first() 
    if user is None: 
      nickname= resp.nickname 
      if nickname is None or nickname == "": 
        nickname=resp.email.split('@')[0] 
      user= User(nickname=nickname, email=resp.email) 
      db.session.add(user) 
      db.session.commit() 
    remember_me=False 
    if 'remember_me' in session: 
      remember_me=session['remember_me'] 
      session.pop('remember_me', None) 
    login_user(user, remember = remember_me) 
    return redirect(request.args.get('next') or url_for('index')) 
+0

你在哪裏分配如下代碼'g.user'? – dirn 2014-10-30 12:29:12

回答

1

您需要設置應用程序配置

app.config['SECURITY_POST_LOGIN_VIEW'] = '/post_login_page' 
app.config['SECURITY_POST_REGISTER_VIEW'] = '/register_complete'