Ejemplo n.º 1
0
def submit_new_book():
    form = SubmitNewBookForm()
    if form.validate_on_submit():
        start_spider.queue(form.url.data)
        flash('任务已经提交到队列,这本书或许需要一些时间才能被搜索到', 'is-success')
    else:
        flash_errors(form)
    return render_template('submit_new_book.html', form=form)
Ejemplo n.º 2
0
def settings():
    form = SettingForm()
    if form.validate_on_submit():
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('资料修改成功', 'is-success')
    elif request.method == 'GET':
        form.about_me.data = current_user.about_me
    else:
        flash_errors(form)
    return render_template('settings.html', form=form)
Ejemplo n.º 3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('恭喜,您已注册成功!', 'is-success')
        return redirect(url_for('auth.login'))
    else:
        flash_errors(form)
    return render_template('auth/register.html', title='注册', form=form)
Ejemplo n.º 4
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('密码重置成功', 'is-success')
        return redirect(url_for('auth.login'))
    else:
        flash_errors(form)
    return render_template('auth/reset_password.html', form=form)
Ejemplo n.º 5
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email.queue(user)
            flash('请点击邮箱中的链接完成密码重置,如果没有收到邮件,请检查垃圾箱', 'is-success')
        else:
            flash('邮箱不存在', 'is-danger')
        return redirect(url_for('auth.login'))
    else:
        flash_errors(form)
    return render_template('auth/reset_password_request.html', title='重置密码', form=form)
Ejemplo n.º 6
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('用户名或密码不正确', 'is-danger')
            return redirect(url_for('auth.login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
             next_page = url_for('main.index')
        return redirect(next_page)
    else:
        flash_errors((form))
    return render_template('auth/login.html', title='登入', form=form)
Ejemplo n.º 7
0
def comment():
    form = CommentForm()
    if form.validate_on_submit():
        u = User.query.get(form.user_id.data)
        b = Book.query.get(form.book_id.data)
        if u and b:
            c = Comment.query.filter_by(user=u, book=b).first()
            if c:
                c.body = form.body.data
                c.score = form.score.data
                c.timestamp = arrow.utcnow()
                flash('修改成功!', 'is-success')
            else:
                c = Comment(user=u, book=b, body=form.body.data, score=form.score.data)
                db.session.add(c)
                flash('评论成功', 'is-success')
            b.set_avg()
            db.session.commit()
        else:
            flash('该用户或书籍不存在', 'is-danger')
            return redirect(url_for('main.index'))
    else:
        flash_errors(form)
    return redirect(url_for('book.index', book_id=form.book_id.data))