Exemplo n.º 1
0
def register():
    form = RegisterForm()
    openid_form=OpenIDForm()
    if openid_form.validate_on_submit():
        return oid.try_login(
            openid_form.openid.data,
            ask_for=['nickname','email'],
            ask_for_optional=['fullname']
        )
    if form.validate_on_submit():
        new_user = User()
        new_user.username = form.username.data
        new_user.nickname = form.nickname.data
        new_user.sex = form.sex.data
        new_user.set_password(form.password.data)
        db.session.add(new_user)
        db.session.commit()
        flash("注册成功,请登录!", category="success")
        return redirect(url_for('.login'))

    openid_errors=oid.fetch_error()
    if openid_errors:
        flash(openid_errors,category="danger")

    return render_template('register.html', form=form , openid_form=openid_form)
Exemplo n.º 2
0
def login():
    form = LoginForm()
    openid_form = OpenIDForm()
    if openid_form.validate_on_submit():
        return oid.try_login(
            openid_form.openid.data,
            ask_for=['nickname','email'],
            ask_for_optional=['fullname']
        )

    if form.validate_on_submit():
        user=User.query.filter_by(username=form.username.data).first()
        login_user(user,remember=form.remember.data)

        identity_changed.send(
            current_app._get_current_object(),
            identity=Identity(user.id)
        )
        flash("登录成功!", category="success")
        return redirect(url_for('blog.home'))

    openid_errors=oid.fetch_error()
    if openid_errors:
        flash(openid_errors,category="danger")
    form.remember.data=True
    return render_template('login.html', form=form,openid_form=openid_form)
Exemplo n.º 3
0
def register():
    form = RegisterForm()
    openid_form = OpenIDForm()

    if openid_form.validate_on_submit():
        return oid.try_login(openid_form.openid.data,
                             ask_for=['nickname', 'email'],
                             ask_for_optional=['fullname'])

    if form.validate_on_submit():
        new_user = User(form.username.data)
        new_user.set_password(form.password.data)

        db.session.add(new_user)
        db.session.commit()

        flash('Your user have been created, please login.', category='success')

        return redirect(url_for('.login'))

    openid_errors = oid.fetch_error()
    if openid_errors:
        flash(openid_errors, category='danger')

    return render_template('register.html', form=form, openid_form=openid_form)
Exemplo n.º 4
0
def login():
    form = LoginForm()

    openid_form = OpenIDForm()

    if openid_form.validate_on_submit():
        return oid.try_login(openid_form.openid.data,
                             ask_for=['nickname', 'email'],
                             ask_for_optional=['fullname'])

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).one()
        login_user(user, remember=form.remember.data)
        """
        # Add user's name to the cookie
        session['username'] = form.username.data
        """
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.id))

        flash('You have been logged in.', category='success')
        return redirect(url_for('blog.home'))

    openid_errors = oid.fetch_error()
    if openid_errors:
        flash(openid_errors, category='danger')
    return render_template('login.html', form=form, openid_form=openid_form)
Exemplo n.º 5
0
def register():
    form = RegisterForm()
    openid_form = OpenIDForm()

    if openid_form.validate_on_submit():
        return oid.try_login(
                openid_form.openid.data,
                ask_for=['nickname', 'email'],
                ask_for_optional=['fullname']
                )

        if form.validate_on_submit():
            new_user = User( form.username.data )
        new_user.set_password( form.password.data )

        db.session.add(new_user)
        db.session.commit()

        flash("Your user has been created, please login.", category="success")

        return redirect(url_for('.login'))

    openid_errors = oid.fetch_erros()
    if openid_errors:
        flash(openid_errors, category="danger")
    return render_template('register.html', form=form, openid_form=openid_form)
Exemplo n.º 6
0
def login():
    form = LoginForm()
    openid_form = OpenIDForm()

    if openid_form.validate_on_submit():
        return oid.try_login(
                openid_form.openid.data,
                ask_for=['nickname', 'email'],
                ask_for_optional=['fullname']
                )

        if form.validate_on_submit():
            flash("You have been logged in.", category="success")
        return redirect(url_for('blog.home', page=1))

    openid_errors = oid.fetch_error()
    if openid_errors:
        flash(openid_errors, category="danger")

    return render_template('login.html', form=form, openid_form = openid_form)