Exemple #1
0
def change_email_request():
    """Respond to existing user's request to change their email."""
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            change_email_link = url_for('account.change_email',
                                        token=token,
                                        _external=True)
            get_queue().enqueue(
                send_email,
                recipient=new_email,
                subject='Confirm Your New Email',
                template='account/email/change_email',
                # current_user is a LocalProxy, we want the underlying user
                # object
                user=current_user._get_current_object(),
                change_email_link=change_email_link)
            flash('A confirmation link has been sent to {}.'.format(new_email),
                  'warning')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.', 'form-error')
    return render_template('account/manage.html', form=form)
Exemple #2
0
def user(username):
    form = ChangePasswordForm()
    if form.validate_on_submit():
        current_user.set_password(form.new_pass.data)
        db.session.commit()
        flash('Password changed.')
    form2 = ChangeEmailForm()
    if form2.validate_on_submit():
        current_user.email = form2.new_email.data
        db.session.commit()
        flash('Email updated.')
    user = User.query.filter_by(username=username).first_or_404()
    subs = (Paper.query.filter_by(subber=user).order_by(
        Paper.timestamp.desc()))[:10]
    vols = (Paper.query.filter_by(volunteer=user).order_by(
        Paper.timestamp.desc()))[:10]
    ups = (Upload.query.filter_by(uploader=user).order_by(
        Upload.timestamp.desc()))[:10]
    return render_template('main/user.html',
                           user=user,
                           form=form,
                           subs=subs,
                           showsub=False,
                           form2=form2,
                           ups=ups,
                           vols=vols,
                           current_user=current_user)
Exemple #3
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.email == form.new_email.data.lower():
            return redirect(url_for('main.index'))
        send_change_email_mail(current_user, form.new_email.data)
        flash(_('Bitte kontrolliere deine Emails für weitere anweisungen'))
        return redirect(url_for('main.index'))
    return render_template('auth/change_email.html', form=form)
Exemple #4
0
def forget_password():
    form = ChangeEmailForm(2)
    if form.validate_on_submit():
        tmpuser = user.query.filter_by(email=form.email.data).first()
        sendmail("Demo小站:重置密码", form.email.data,
                 "email/reset_forget_password.html",
                 ForgetPwdUser.generator_forgetpwd_token(tmpuser.id))
        flash("已向你的注册邮箱发送重置密码链接,请前往重置密码(有效期10分钟)")
        return redirect(url_for("auth.login"))
    return render_template("auth/email_form.html", form=form)
Exemple #5
0
def change_email():
    form = ChangeEmailForm(1)
    if form.validate_on_submit():
        current_user.new_email = form.email.data
        sendmail(
            "Demo小站:新邮箱激活", current_user.new_email,
            "/email/change_email_model.html",
            current_user.generator_confirmed_token(
                email=current_user.new_email))
        flash("已向新邮箱发送激活链接,在激活之前,新邮箱不可用,激活有效期1小时")
        return redirect(url_for("main.index"))
    return render_template("auth/email_form.html", form=form)
Exemple #6
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(
                new_email, "Confirm your email address", "auth/email/change_email", user=current_user, token=token
            )
            flash("An email with instructions to confirm your new email " "address has been sent to you.")
            return redirect(url_for("main.index"))
        else:
            flash("Invalid email or password.")
    return render_template("auth/change_email.html", form=form)
Exemple #7
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data.lower()
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email, 'Confirm your email address',
                       'auth/email/change_email',
                       user=current_user, token=token)
            flash('An email with instructions to confirm your new email '
                  'address has been sent to you.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.')
    return render_template("auth/change_email.html", form=form)
Exemple #8
0
def profile():
    """账户邮箱设置"""
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email, 'Confirm your email address',
                       'auth/email/change_email',
                       user=current_user, token=token)
            flash(constant.SEND_EMIAL)
            return redirect(url_for('auth.profile'))
        else:
            flash(constant.WRONG_PWD)
    return render_template("email_settings.html", user=current_user, form=form, base64=base64)
Exemple #9
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data.lower().strip()
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email, 'Confirm your email address',
                       'auth/email/change_email',
                       user=current_user, token=token)
            flash('An email with instructions to confirm your new email '
                  'address has been sent to you.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.')
    return render_template("auth/change_email.html", form=form)
Exemple #10
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       '确认新邮箱地址',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('确认邮箱地址的邮件已经发送, 请检查收件箱')
            return redirect(url_for('home.index'))
        else:
            flash('无效邮箱或密码')
    return render_template('auth/change_email.html', form=form)
Exemple #11
0
def reset_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_confirmation_token(
                new_email=new_email)
            send_email(new_email,
                       '修改邮箱',
                       'auth/email/change_email',
                       user=current_user,
                       token=token,
                       next=request.args.get('next'))
        flash('修改邮箱链接已发到您的新邮箱,请您查收')
        return redirect(url_for('auth.login'))
    return render_template('auth/change_email.html', form=form)
Exemple #12
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data
            # 将新设的邮箱账号保存到令牌中
            token = current_user.generate_email_change_token(new_email)
            EmailUtil.send_change_email_email(new_email,
                                              user=current_user,
                                              token=token,
                                              next=request.args.get(next))
            flash(_('An email with instructions to confirm your '
                    'new email address has been sent to you.'), 'info')
            return redirect(url_for('main.index'))
        else:
            flash(_('Invalid email or password'), 'warning')
    return render_template('/auth/change_email.html', form=form)
Exemple #13
0
def change_email_request():
    form = ChangeEmailForm(current_user)

    if form.validate_on_submit():
        if form.email.data.lower().strip() != current_user.email:
            new_email = form.email.data.lower().strip()
            token = current_user.generate_email_change_token(new_email)
            send_email(
                new_email, "Confirm Your Email Address",
                render_template("email/confirm-change-email.html",
                                user=current_user,
                                token=token))

            flash(
                "To finish updating your email address, please click the link "
                "that we just sent to your new address")
        return redirect(url_for("auth.portal"))

    form.email.data = current_user.email
    return render_template("auth.html",
                           form_title="Change Your Email",
                           form=form)