Beispiel #1
0
def send_drift(gid):
    """
    想他人请求礼物
    :param gid:
    :return:
    """
    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)
    gifter = current_gift.user.summary
    form = DriftForm(request.form)
    if request.method == 'POST' and form.validate():
        save_drift(form, current_gift)
        send_mail(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)
Beispiel #2
0
def send_drift(gid):
    from app.models.gift import Gift
    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_mail(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)
Beispiel #3
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_mail(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,
                           form=form,
                           user_beans=current_user.beans)
Beispiel #4
0
def satisfy_wish(wid):
    wish = Wish.query.filter_by(id=wid, launched=False).first_or_404()
    gift = Gift.query.filter_by(uid=current_user.id, isbn=wish.isbn).first()
    if not gift:
        flash('你还没有上传此书,请点击赠送清单添加此书,添加前,请确保自己可以赠送此书')
    else:
        send_mail(wish.user.email, '有人想要送你一本书', 'email/satisify_wish.html', wish=wish, gift=gift)
        flash('已向他/她发送了一封邮件,如果她/他愿意接受你的赠送,你将收到一个鱼漂')
        return redirect(url_for('web.book_detail', isbn=wish.isbn))
Beispiel #5
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()
        if user:
            from app.libs.mail import send_mail
            send_mail(form.email.data,
                      '重置你的密码',
                      'email/reset_password.html',
                      user=user,
                      token=user.generate_token())
    return render_template('/auth/forget_password_request.html')
Beispiel #6
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()
            token = user.generate_password()
            send_mail(account_email,'请重置您的密码', 'email/reset_password.html', user=user,token=token)
            flash('一封邮件已发送到'+account_email +',请注意查收')
            pass
        pass
    return render_template('auth/forget_password_request.html',form=form)
Beispiel #7
0
def forget_password_request():
    if request.method == 'POST':
        form = EmailForm(request.form)
        if form.validate():
            account_email = form.email.data
            user_account = User.query.filter_by(
                email=account_email).first_or_404()
            from app.libs.mail import send_mail
            send_mail(user_account,
                      "重置密码",
                      "email/reset_password.html",
                      user=current_user,
                      token='12345')
    return render_template('auth/forget_password_request.html')
Beispiel #8
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.mail import send_mail
            send_mail(account_email,
                      '重置你的密码',
                      'email/reset_password.html',
                      user=user,
                      token=user.generate_token())
            flash("邮件已经发送,请注意查收")
    return render_template('auth/forget_password_request.html', form=form)
Beispiel #9
0
def forget_password_request():
    form = EmailForm(request.form)
    if request.method == 'POST':
        if form.validate():
            account_email = form.email.data
            ## 如果user中未查询到数据,则抛出异常
            user = User.query.filter_by(email=account_email).first_or_404()
            from app.libs.mail import send_mail
            send_mail(form.email.data,
                      '重置您的密码',
                      'email/reset_password.html',
                      user=user,
                      token=user.generate_token())
            flash('电子邮件已发送,请到您的电子邮箱中查收')
    return render_template('auth/forget_password_request.html', form=form)
Beispiel #10
0
def forget_password_request():
    email_form = EmailForm(request.form)
    if request.method == "POST":
        if email_form.validate():
            user = User.query.filter_by(email = email_form.email.data).first_or_404() # 使用first_or_404()系统会自己抛出异常
            # if not user:
            #     raise  Exception()
            print(user.nickname)
            send_mail(email_form.email.data, "重置密码",
                      "email/reset_password.html",user=user,
                      token=user.generation_token())
            flash("一封邮件已发送到邮箱" + email_form.email.data + ",请及时查收")


    return render_template('auth/forget_password_request.html',form = email_form)
Beispiel #11
0
def satisfy_wish(wid):
    wish = Wish.query.filter_by(id=wid, uid=current_user.id).first_or_404()
    # 查询我是否把它加入到了gift中
    gift = Gift.query.filter_by(uid=current_user.id, isbn=wish.isbn).first()
    if not gift:
        flash("你还没有上次此书,请点击'加入到赠送清单'添加此书,添加前请确保自己可以赠送此书")

    else:
        send_mail(wish.user.email,
                  "有人想送你一本书",
                  "email/satisify_wish.html",
                  wish=wish,
                  gift=gift)
        flash("已向他/她发送了通知,如果同意,你将收到一个鱼漂")
    redirect(url_for("web.book_detail", isbn=wish.isbn))
Beispiel #12
0
def satisfy_wish(wid):
    """
            向想要这本书的人发送一封邮件
            注意,这个接口需要做一定的频率限制
            这接口比较适合写成一个ajax接口
        """
    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_mail(wish.user.email,
                  '有人想送你一本书',
                  'email/satisify_wish',
                  wish=wish,
                  gift=gift)
        flash('已向他/她发送了一封邮件,如果他/她愿意接受你的赠送,你将收到一个鱼漂')
    return redirect(url_for('web.book_detail', isbn=wish.isbn))
Beispiel #13
0
def send_drift(gid):
    current_gift = Gift.query.get_or_404(gid)
    if current_gift.send_drift_by_myself(current_user.id):
        flash("这本书是你自己的,不能向自己索要书籍")
    can = current_user.can_send_drift(current_gift)
    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_mail(current_gift.user.email,
                  "有人想要一本书",
                  "email/get_gift.html",
                  wisher=current_user,
                  gift=current_gift)

    gifter = current_gift.user.summary
    return render_template("drift.html",
                           gifter=gifter,
                           user_beans=current_user.beans,
                           form=form)