Exemplo n.º 1
0
def send_drift(gid):
    form = DriftForm(request.form)
    current_gift = Gift.query.get_or_404(gid)

    if current_gift.is_yourself_gift(current_user.id):
        flash('这本书是你自己的^_^, 不能向自己索要书籍噢')
        return redirect(url_for('web.book_detail', isbn=current_gift.isbn))

    if not current_user.can_send_gift():
        return render_template("not_enough_beans.html",
                               beans=current_user.beans)
    gifter = current_gift.user.summary
    if request.method == "POST" and form.validate():
        drift = Drift()
        drift.save_drift(form, current_gift)
        send_email(current_gift.user.email,
                   '有人想要一本书',
                   'email/get_gift.html',
                   wisher=current_user,
                   gift=current_gift)
        return redirect(url_for("web.pending"))
    return render_template("drift.html",
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=form)
Exemplo n.º 2
0
def send_drift(gid):
    '''发起一次交易请求。'''
    current_gift = Gift.query.get_or_404(gid)

    # 防止用户自己向自己发起交易
    if current_gift.is_yourself_gift(current_user.id):
        flash('这本书是你自己的,不能向自己索要书籍喔~')
        return redirect(url_for('web.book_detail', isbn=current_gift.isbn))

    # 判断拾光豆等条件是否满足
    if not current_user.can_send_drift():
        return render_template('web/not_enough_beans.html',
                               beans=current_user.beans)

    form = DriftForm(request.form)
    if request.method == 'POST' and form.validate():
        save_drift(form, current_gift)
        send_email(current_gift.user.email,
                   '有人想要一本书',
                   'email/get_gift.html',
                   wisher=current_user,
                   gift=current_gift)
        return redirect(url_for('web.pending'))

    gifter = current_gift.user.summary
    return render_template('web/drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=form)
Exemplo n.º 3
0
def send_drift(gid):  # gid:礼物id
    # filter_by(id=gid, launched=True)没有下面这条语句好。下面的语句可以多判断一种状态
    current_gift = Gift.query.get_or_404(gid)
    if current_gift.is_yourself_gift(current_user.id):
        flash('这本书是你自己的^_^, 不能向自己索要书籍噢')
        return redirect(url_for('web.book_detail', isbn=current_gift.isbn))
    # can = current_user.can_satisfied_wish()
    can = current_user.can_send_drift()
    if not can:
        return render_template('not_enough_beans.html',
                               beans=current_user.beans)

    form = DriftForm(request.form)
    if request.method == 'POST' and form.validate():
        save_drift(form, current_gift)
        send_email(current_gift.user.email,
                   '有人想要一本书',
                   'email/get_gift.html',
                   wisher=current_user,
                   gift=current_gift)
        return redirect(url_for('web.pending'))

    gifter = current_gift.user.summary
    return render_template('drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=form)
Exemplo n.º 4
0
def send_drift(gid):
    """
    点击「向他们请求此书」跳转到此函数,发起一个索要书的申请
    """
    current_gift = Gift.query.get_or_404(gid)
    gifter = current_gift.user

    if current_gift.is_yourself_gift(current_user.id):
        flash('这本书是你自己的')
        return redirect(url_for('web.book_detail', isbn=current_gift.isbn))

    can = current_user.can_send_drift()
    if not can:
        return render_template('not_enough_beans.html',
                               beans=current_user.beans)

    form = DriftForm(request.form)
    if request.method == 'POST' and form.validate():
        sava_drift(form, current_gift)
        send_email(current_gift.user.email,
                   '有人想要一本书',
                   'email/get_gift.html',
                   wisher=current_user,
                   gift=current_gift)  # 后面这些是 **kwargs
        return redirect(url_for('web.pending'))

    return render_template('drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=form)
Exemplo n.º 5
0
def send_drift(gid):
    gift = Gift.query.get_or_404(gid)
    # 对礼物进行检查
    if gift.is_yours_gift(current_user.id):
        flash("自己不能向自己请求书籍")
        return redirect(url_for('web.book_detail', gift.isbn))
    # 对用户进行检查
    can = current_user.can_save_drift()
    if not can:
        return render_template('not_enough_beans.html',
                               beans=current_user.beans)
    # 请求页面信息准备
    form = DriftForm(request.form)
    if request.method == 'POST' and form.validate():
        save_drift(form, gift)
        send_email(gift.user.email,
                   '有人想要一本书',
                   'email/get_gift.html',
                   wisher=current_user,
                   gift=gift)
        return redirect(url_for('web.pending'))
    gifter = gift.user.summary
    return render_template('drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans)
Exemplo n.º 6
0
def send_drift(gid):
    current_gift = Gift.query.get_or_404(gid)

    if current_gift.is_yourself_gift(current_user.id):
        flash("这本书是你自己的,不能向自己索要书籍哦~")
        return redirect(url_for("web.book_detail", isbn=current_gift.isbn))

    can = current_user.can_send_drift()
    if not can:
        return render_template("not_enough_beans.html",
                               beans=current_user.beans)

    form = DriftForm(request.form)
    if request.method == "POST" and form.validate():
        save_drift(form, current_gift)
        # 发送邮件提醒
        send_email(current_gift.user.email,
                   "有人向你请求一本书",
                   "email/get_gift.html",
                   wisher=current_user,
                   gift=current_gift)
        return redirect(url_for("web.pending"))

    gifter = current_gift.user.summary
    yushu_book = YuShuBook()
    yushu_book.search_by_isbn(current_gift.isbn)
    book = BookViewModel(yushu_book.first)
    return render_template("drift.html",
                           gifter=gifter,
                           book=book,
                           user_beans=current_user.beans,
                           form=form)
Exemplo n.º 7
0
def send_drift(gid):
    current_gift = Gift.query.get_or_404(gid)

    if current_gift.is_yourself_gift(current_user.id):
        flash('不可以向自己索要书籍')
        return redirect(url_for('web.book_detail', isbn=current_gift.isbn))
    can = current_user.can_send_drift()
    if not can:
        return render_template('not_enough_beans.html',
                               beans=current_user.beans)

    form = DriftForm(request.form)
    if request.method == 'POST' and form.validate():
        save_drift(form, current_gift)
        send_email(current_gift.user.email,
                   '有人想要一本书',
                   'email/get_gift.html',
                   wisher=current_user,
                   gift=current_gift)
    return redirect(url_for('web.pending'))

    gifter = current_gift.user.summary
    return render_template('drift.html',
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=form)
Exemplo n.º 8
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == "POST" and form.validate():
        user = db.session.query(User).filter(User.email == form.email.data).first_or_404()
        send_email(form.email.data, "重置你的密码", "email/reset_password.html", user=user, token=user.generate_token())
        flash("邮件已发送,请在邮箱中查看~")
    return render_template("auth/forget_password_request.html")
Exemplo n.º 9
0
    def save_a_drift(cls, drift_form, current_gift):
        with db.auto_commit():
            book = BookViewModel(current_gift.book.first)

            drift = Drift()
            drift_form.populate_obj(drift)
            drift.gift_id = current_gift.id
            drift.requester_id = current_user.id
            drift.requester_nickname = current_user.nickname
            drift.gifter_nickname = current_gift.user.nickname
            drift.gifter_id = current_gift.user.id
            drift.book_title = book.title
            drift.book_author = book.author
            drift.book_img = book.image
            drift.isbn = book.isbn
            # 当请求生成时,不需要让这个礼物处于锁定状态
            # 这样赠送者是可以收到多个索取请求的,由赠送者选择送给谁
            # current_gift.launched = True
            # 请求者鱼豆-1
            current_user.beans -= 1
            # 但是赠送者鱼豆不会立刻+1
            # current_gift.user.beans += 1
            db.session.add(drift)
        send_email(current_gift.user.email,
                   '有人想要一本书',
                   'email/get_gift',
                   wisher=current_user,
                   gift=current_gift)
Exemplo n.º 10
0
def send_drift(gid):
    current_gift = Gift.query.get_or_404(gid)

    if current_gift.is_your_own_book(current_user.id):
        flash('这本书是你自己的...')
        return redirect(url_for('web.book_detail', isbn=current_gift.isbn))

    has_given_enough_books = current_user.can_send_drift()
    if not has_given_enough_books:
        flash('鱼豆不足或者你需要送出一本书!')
        return render_template('not_enough_beans.html',
                               beans=current_user.beans)

    form = DriftForm(request.form)
    if request.method == 'POST' and form.validate():
        save_drift(form, current_gift)
        send_email(current_gift.user.email,
                   '有人想要一本书',
                   'email/get_gift.html',
                   wisher=current_user,
                   gift=current_gift)
        return redirect(url_for('web.pending'))
    return render_template('drift.html',
                           gifter=current_gift.user.summary,
                           user_beans=current_user.beans,
                           form=form)
Exemplo n.º 11
0
def show_post(post_id):
    post = Post.query.filter_by(id=post_id).first_or_404()
    page = request.args.get('page', default=1, type=int)
    per_page = current_app.config['BRBLOG_COMMENT_PER_PAGE']
    pagination = Comment.query.with_parent(post).filter_by(
        reviewed=True).order_by(Comment.timestamp.asc()).paginate(
            page, per_page)
    comments = pagination.items

    if current_user.is_authenticated:  # 已经登录使用管理员表单
        form = AdminCommentForm()
        form.author.data = current_user.name
        form.email.data = current_app.config['MAIL_USERNAME']
        form.site.data = url_for('.index')
        from_admin = True
        reviewed = True
    else:  # 未登录使用普通表单
        form = CommentForm()
        from_admin = False
        reviewed = False

    if form.validate_on_submit():
        author = form.author.data
        email = form.email.data
        site = form.site.data
        body = form.body.data
        comment = Comment(author=author,
                          email=email,
                          site=site,
                          body=body,
                          from_admin=from_admin,
                          post=post,
                          reviewed=reviewed)
        # 如果是回复评论
        replied_id = request.args.get('reply')
        if replied_id:
            replied_comment = Comment.query.get_or_404(replied_id)
            comment.replied = replied_comment
            send_email(replied_comment.email,
                       '有新回复',
                       'email/replied.html',
                       post=post,
                       comment=comment)
        db.session.add(comment)
        db.session.commit()
        if current_user.is_authenticated:  # 管理员直接提交评论
            flash('回复成功', 'success')
        else:
            flash('感谢回复,您的评论稍后显示', 'info')
            send_email(current_app.config['MAIL_USERNAME'],
                       '有新评论',
                       'email/commented.html',
                       post=post,
                       comment=comment)  # 非管理员评论会发送邮件给管理者
        return redirect(url_for('.show_post', post_id=post_id))
    return render_template('blog/post.html',
                           post=post,
                           pagination=pagination,
                           form=form,
                           comments=comments)
Exemplo n.º 12
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User.query.filter_by(email=form.email.data).first_or_404()
        send_email(form.email.data, '重置您的密码', 'email/reset_password',
                   user=user, token=user.generate_token())
        flash('一份邮件已经发送到'+form.email.data+'中,请注意查收')
        # return redirect(url_for('web.login'))
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 13
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == "POST":
        if form.validate():
            account = form.email.data
            user_obj = User.query.filter_by(email=account).first_or_404()
            send_email(account, "重置密码", "email/reset_password.html",
                       user=user_obj, token=user_obj.generate_token())
            flash("密码重置邮件已发送至邮箱【" + account + "】 请注意查收!")
    return render_template("auth/forget_password_request.html", form=form)
Exemplo n.º 14
0
def satisfy_wish(wid):
    wish = Wish.query.get_or_404(wid)
    gift = Gift.query.filter_by(uid=current_user.id, isbn=wish.isbn).first()
    if not gift:
        flash("你还没有上传此书,请点击‘赠送此书’以后再向他人赠送。")
    else:
        send_email(wish.user.email, "有人向你赠送书籍",
                   "email/satisify_wish.html", wish=wish, gift=gift)
        flash("已成功向ta发送一封邮件,如果ta愿意接受赠送,你将会收到一个鱼漂。")
    return redirect(url_for("web.book_detail", isbn=gift.isbn))
Exemplo n.º 15
0
def satisfy_wish(wid):
    wish = Wish.query.get_or_404(wid)
    gift = Gift.query.filter_by(uid = current_user.id, isbn = Wish.isbn).first()
    if not gift :
        flash('not added, please add')
    else:
        send_email(wish.user.email,
                  '有人像送你一本书','email/satisify_wish', wish = wish, gift = gift)
        flash('email sent and you will got a drift. ')
    return redirect(url_for('web.book_detail',isbn = wish.isbn))
Exemplo n.º 16
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST':
        if form.validate():
            account_email = form.email.data
            user = User.query.filter_by(email=account_email).first_or_404()
            from app.libs.email import send_email
            send_email(form.email.data, '重置你的密码', 'email/reset_password.html', user=user, token=user.generate_token())
            flash('重置密码邮件已发送到邮箱' + account_email + ', 请及时查收')
            # return redirect(url_for('web.login'))
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 17
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST' and form.validate():
        account_email = form.email.data
        user = User.query.filter_by(email=account_email).first_or_404()
        send_email(to=account_email,
                   subject="重置您的密码",
                   template="email/reset_password.html",
                   user=user,
                   token=user.generate_token())
        flash("重置密码邮件已发送到您的注册邮箱,请查收!")
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 18
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST':
        if form.validate():
            account_email = form.email.data
            user = User.query.filter_by(email=account_email).first_or_404()
            send_email(form.email.data,
                       '重置你的密码',
                       'email/reset_password.html',
                       user=user,
                       token=user.generate_token())
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 19
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST':
        if form.validate():
            account_email = form.email.data
            # 找不到数据时候,fisrt_or_404会抛出一个异常(异常抛出后面代码不执行),通过try可以自己定义返回页面
            # 这里采用AOP思想,集中处理404异常,(web/__init__.py下面定义)
            user = User.query.filter_by(email=account_email).first_or_404()
            send_email(form.email.data, '重置你的密码',
                       'email/reset_password.html', user=user, token=user.generate_token())
            flash('一封邮件已发送到邮箱'+account_email+', 请及时查收')
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 20
0
def satisfy_wish(wid):
    wish = Wish.query.get_or_404(wid)
    gift = Gift.query.filter_by(uid=current_user.id, isbn=wish.isbn).first()
    if not gift:
        flash('你还没有上传此书,请点击“加入到赠送清单”添加此书。添加前,请确保自己可以赠送此书')
    else:
        send_email(wish.user.email,
                   '有人想送你一本书',
                   'email/satisify_wish.html',
                   wish=wish,
                   gift=gift)
        flash('已向他/她发送了一封邮件,如果他/她愿意接受你的赠送,你将收到一个鱼漂')
    return redirect(url_for('web.book_detail', isbn=wish.isbn))
Exemplo n.º 21
0
def forget_password_request():
    form = EmailForms(request.form)
    if request.method == 'POST':
        if form.validate():
            # first_or_404 自动抛出异常,不用手动raise exception,可用try定制自己的404页面
            # try:
                user = User.query.filter_by(email=form.email.data).first_or_404()
            # except Exception as e:
            #     return render_template('404.html')
                if user:
                    send_email(to=form.email.data, subject='重置你的密码', template='email/reset_password.html',
                               user=user, token=user.generate_token())
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 22
0
def satisfy_wish(wid):
    wish = Wish.query.get_or_404(wid)
    gift = Gift.query.filter_by(uid=current_user.id, isbn=wish.isbn).first()
    if not gift:
        flash('您还没有上传此书,请先点击加入赠书清单')
    else:
        send_email(wish.user.email,
                   '有人想送你一本书',
                   'email/satisify_wish.html',
                   wish=wish,
                   gift=gift)
        flash('已向他/她发送了一封邮件')
    return redirect(url_for('web.book_detail', isbn=wish.isbn))
Exemplo n.º 23
0
def satisfy_wish(wid):
    wish = Wish.query.get_or_404(wid)
    gift = Gift.query.filter_by(uid=current_user.id,
                                isbn=wish.isbn).first_or_404()
    if not gift:
        flash('你还没有上传本书,请点击"加入到赠送清单"添加此书.添加前,请确保自己可以赠送此书')
    else:
        send_email(wish.user.email,
                   "有人想送你一本书",
                   "email/satisfy_wish.html",
                   gift=gift,
                   wish=wish)
        flash("已向他/她发送了一封邮件,如果他/她愿意接收你的赠送,你将收到一个鱼漂。")
    return redirect(url_for("web.book_detail", isbn=wish.isbn))
Exemplo n.º 24
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST':
        if form.validate():
            account_email = form.email.data
            user = User.query.filter_by(email=account_email).first_or_404()
            # if not user:
            #     raise Exception()
            send_email(form.email.data, '重置你的密码',
                       'email/reset_password', user=user,
                       token=user.generate_token())
            flash('一封邮件已发送到邮箱' + account_email + ',请及时查收')
            return redirect(url_for('web.login'))
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 25
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST':
        if form.validate():
            account_email = form.email.data
            # 这里如果使用first_or_404, 如果email不存在,那就抛404异常,后续代码不会走
            user = User.query.filter_by(email=account_email).first_or_404()
            # 尝试把发邮件放入异步线程中执行
            send_email(form.email.data,
                       '重置你的密码',
                       'email/reset_password.html',
                       user=user,
                       token=user.generate_token())
            flash('一封邮件已经发送到邮箱' + account_email + '请及时查看')
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 26
0
def satisfy_wish(wid):  #向他人赠送此书(满足愿望,赠送书籍)
    wish = Wish.query.get_or_404(wid)
    gift = Gift.query.filter_by(isbn=wish.isbn, uid=current_user.id).first()
    if not gift:
        flash('你还没有上传此书,请点击“加入到赠送清单”添加此书,添加前,请确保自己可以赠送此书')

    else:
        send_email(wish.user.email,
                   '赠送你书',
                   'email/satisify_wish.html',
                   wish=wish,
                   gift=gift)
        flash('已发送成功')

    return redirect(url_for('web.book_detail', isbn=wish.isbn))
Exemplo n.º 27
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST':
        if form.validate():
            account_email = form.email.data
            user = User.query.filter_by(email=account_email).first_or_404()
            #没有user,会抛出异常,不会执行后面代码,
            from app.libs.email import send_email
            send_email(form.email.data,
                       'Reset Your password',
                       'email/reset.html',
                       user=user,
                       token=user.generate_token())
            flash('一封邮件已送达信箱' + account_email + ', 请及时查收')
            # return redirect(url_for('web.login'))
    return render_template("auth/forget_password_request.html", form=form)
Exemplo n.º 28
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST':

        if form.validate():
            account_email = form.email.data
            user = User.query.filter_by(email=account_email).first_or_404()

            send_email(form.email.data,
                       'reset your password',
                       'email/reset_password',
                       user=user,
                       token=user.generate_token())
            flash('email sent to your mail box' + account_email +
                  'please check in time')
            return redirect(url_for('web.login'))
    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 29
0
def forget_password_request():
    """
    用户提出重置密码的请求,在表单中读取电子邮件地址,发送重置链接
    """
    form = EmailForm(request.form)
    if request.method == 'POST':
        if form.validate():
            account_email = form.email.data
            user = User.query.filter_by(email=account_email).first_or_404()
            send_email(form.email.data,
                       '重置你的密码',
                       'email/reset_password.html',
                       user=user,
                       token=user.generate_token())
            flash('一封邮件已发送到邮箱:' + account_email + ' 请及时查收')
            # return redirect(url_for('web.login'))

    return render_template('auth/forget_password_request.html', form=form)
Exemplo n.º 30
0
def send_drift(gid):  #该方法是索要书籍
    current_gift = Gift.query.get_or_404(gid)
    if current_gift.is_yourself_gift(current_user.id):
        flash('这本书是自己的,不能向自己索要书籍')
        return redirect(url_for('web.book_detail', isbn=current_gift.isbn))

    can = current_user.can_send_drift()
    if not can:
        return render_template('not_enough_coins.html', coins=current_user.coins)

    form = DriftForm(request.form)
    if request.method == 'POST' and form.validate():
        save_drift(form, current_gift)    #赠送书籍页面保存信息
        #交易通知的方式,邮箱,短信
        send_email(current_gift.user.email, '有人想要这本书', 'email/get_gift.html', wisher=current_user, gift=current_gift)
        return redirect(url_for('web.pending'))
    gifter = current_gift.user.summary    #id没用, 是relationship来操作另一个表

    return render_template('drift.html', gifter=gifter, user_coins=current_user.coins, form=form)