Ejemplo n.º 1
0
def create_or_login(resp):
    app.logger.info('>>> OpenID Response: openid=%s, provider=%s',
                    resp.identity_url, session['openid_provider'])
    session['current_openid'] = resp.identity_url
    # TODO: 当使用新的OPENID登陆时,通过邮箱判定该用户以前是否注册过,邮箱未注册时,允许用户自己登陆以绑定帐号
    user_openid = UserOpenID.query.filter_by(openid=resp.identity_url).first()
    if user_openid:
        flash(u'登陆成功')
        app.logger.info(u'Logging with user: '******'user.signup', next=oid.get_next_url(),
                                           email=resp.email,
                                           nickname=resp.nickname or resp.fullname))
Ejemplo n.º 2
0
def signin():
    if current_user.is_authenticated():
        return redirect(url_for('user.profile'))

    form = SigninForm(csrf_enabled=False, next=oid.get_next_url())
    app.logger.info('>>> Signin user: '******'******')))
    
    if form.is_submitted() and form.openid_identifier.data:
        session['openid_provider'] = form.openid_provider.data
        session['openid_identifier'] = form.openid_identifier.data
        return oid.try_login(form.openid_identifier.data, ask_for=['email', 'nickname', 'fullname'])

    if form.validate_on_submit():
        login.login_user(LoginUser(form.user), remember=form.remember)
        flash(u'登陆成功')
        # 如果指定了 next ,跳转到 next 页面
        # 如果用户注册了 slug ,则跳转到 slug  的profile 页面,否则跳转到 userid 的 profile 页面
        return redirect(form.next.data or url_for('user.profile'))
    else:
        return render_template('user/signin.html', form=form, openid_error=oid.fetch_error())