示例#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=gettext('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(
                gettext(
                    'A confirmation link has been sent to {}.'.format(
                        new_email), 'warning'))
            return redirect(url_for('main.index'))
        else:
            flash(gettext('Invalid email or password.'), 'form-error')
    return render_template('account/change_email.html', form=form)
示例#2
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)
            user = current_user._get_current_object()
            user.__dict__.pop("storage_files")
            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=user,
                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)
示例#3
0
文件: views.py 项目: lml0608/blog
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_email1(new_email,
                        'Confirm you 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)
示例#4
0
def change_email_request():
    user = User.query.filter_by(email=current_user.email).first()
    form = EditProfileAdminForm(user=user)
    base = 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.entries'))
        else:
            flash('Invalid email or password.')
    form.name.data = user.name
    form.email.data = user.email
    form.confirmed.data = user.confirmed
    form.role.data = user.role_id
    form.location.data = user.location
    form.about_me.data = user.about_me
    return render_template("auth/change_email.html",
                           form=form,
                           user=user,
                           base=base)
示例#5
0
文件: auth.py 项目: Y-Lab/Y-System
def change_email_request():
    '''auth.change_email_request()'''
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = form.email.data.strip().lower()
            token = current_user.generate_email_change_token(new_email)
            send_email(
                recipient=new_email,
                subject='确认您的邮箱账户',
                template='auth/mail/change_email',
                user=current_user._get_current_object(),
                token=token
            )
            flash('一封确认邮件已经发送至您的邮箱', category='info')
            add_user_log(
                user=current_user._get_current_object(),
                event='请求修改邮箱为:{}'.format(new_email),
                category='auth'
            )
            return redirect(url_for('auth.change_email_request'))
        flash('无效的用户名或密码', category='error')
        return redirect(url_for('auth.change_email_request'))
    return minify(render_template(
        'auth/change_email.html',
        form=form
    ))
示例#6
0
文件: views.py 项目: zgfhill/flas
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_email_change_token(form.email.data)
            flash(url_for('.change_email_request') + '/' + token)
            return redirect(url_for('main.index'))
        flash('Invalid email or Wrong password')
    return render_template('auth/change_email_request.html', form=form)
示例#7
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        new_email = form.email.data
        token = current_user.generate_email_change_token(new_email)
        return redirect(url_for('main.index'))
    else:
        flash('Invalid email or password.')
    return render_template('auth/change_email.html',form=form)
示例#8
0
def send_email_confirm():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_email_change_token(form.email.data)
            send_email(form.email.data, 'Confirm Your New Email', 'auth/mail/confirm_email', token=token)
            flash('Instructions for confirming your new email have been sent to %s.' % (form.email.data))
            return redirect(url_for('main.index'))
        flash('Email not found.')
    return render_template('auth/template.html', form=form, title='change Your Email')
示例#9
0
def change_email_request():
    '''这是修改邮箱的视图'''
    form=ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token=current_user.generate_email_change_token(form.email.data)
            send_email(form.email.data,'修改邮箱','auth/email/change_email',user=current_user,token=token)
            flash('已经向您的新邮箱发送了邮件,请尽快查收并完成邮箱修改')
        else:
            flash('密码错误')
    return render_template('auth/change_email_request.html',form=form)
示例#10
0
def change_email_request():
    next = request.args.get('next')
    if next is None or not next.startswith('/'):
        next = url_for('main.index')
    token = current_user.generate_email_change_token()
    send_email(current_user.email,
               '验证你的邮箱',
               'auth/email/change_email',
               user=current_user,
               token=token)
    return redirect(next)  #到当前也页面
示例#11
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_email_change_token(new_email=form.email.data)
            send_email(to=form.email.data, subject='Change email', template='auth/email/change_email',
                       user=current_user, token=token)
            flash('Change email request have been sent to your new email.')
            return redirect(url_for('auth.login'))
        else:
            flash('Invalid password')
    return render_template('auth/change_email.html', form=form)
示例#12
0
def change_email_request():
    form = ChangeEmailRequestForm()
    if form.validate_on_submit():
        token = current_user.generate_email_change_token()
        send_email(to=form.new_email.data,
                   subject='Reset your password',
                   template='auth/email/reset_password',
                   token=token,
                   user=current_user)
        flash('A email has send to your new email.')
        return redirect(url_for('main.index'))
    return render_template('auth/change_email.html', form=form)
示例#13
0
def index():
    formChangePassword = ChangePasswordForm()
    formChangeUserName = ChangeUserNameForm()
    formUpdateProfile = UpdateProfileForm()
    formChangeEmail = ChangeEmailForm()

    if formChangePassword.type.data == 'formChangePassword':
        if formChangePassword.validate_on_submit():
            if current_user.verify_password(
                    formChangePassword.old_password.data):
                current_user.password = formChangePassword.password.data
                db.session.add(current_user)
                flash('You password has been changed.')
                send_email(current_user.email,
                           'You Password has Changed',
                           'profile/email/password_changed',
                           user=current_user)
                return redirect(url_for('profile.index'))
            else:
                flash('Invalid password.')
            return redirect(url_for('profile.index'))
    if formChangeUserName.type.data == 'formChangeUserName':
        if formChangeUserName.validate_on_submit():
            current_user.username = formChangeUserName.username.data
            db.session.add(current_user)
            flash('formChangeUserName')
            return redirect(url_for('profile.index'))
    if formUpdateProfile.type.data == 'formUpdateProfile':
        if formUpdateProfile.validate_on_submit():
            current_user.full_name = formUpdateProfile.full_name.data
            db.session.add(current_user)
            flash('formUpdateProfile')
            return redirect(url_for('profile.index'))
    if formChangeEmail.type.data == 'formChangeEmail':
        if formChangeEmail.validate_on_submit():
            if current_user.verify_password(formChangeEmail.password.data):
                new_email = formChangeEmail.email.data
                token = current_user.generate_email_change_token(new_email)
                send_email(new_email,
                           'Confirm your email address',
                           'profile/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('profile.index'))
            else:
                flash('Invalid email address or password.')
    return render_template('profile/index.html',
                           formChangePassword=formChangePassword,
                           formChangeUserName=formChangeUserName,
                           formUpdateProfile=formUpdateProfile,
                           formChangeEmail=formChangeEmail)
示例#14
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, u'确认你的新邮箱地址', 'auth/email/change_email', user=current_user, token=token)
            flash(u'一封修改邮箱的确认邮件已经发给你了呦!')
            return redirect(url_for('main.index'))
        else:
            flash(u'无效的邮箱或者密码')
    return render_template("auth/change_email.html", form=form)
示例#15
0
文件: views.py 项目: TaiyuanHot/blog
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('main.index'))
        else:
            flash('无效的邮箱或密码')
    return render_template('auth/change_email.html', form=form)
示例#16
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 instruction 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)   
示例#17
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('mian.index'))
        else:
            flash('无效的邮箱或者密码')
    return render_template('auth/change_email.html', form=form)
示例#18
0
文件: views.py 项目: bean-jelly/blog
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_mail(new_email, '确认', 'auth/email/change_email', user=current_user, token=token)
            flash('请打开邮箱确认')
            return redirect(url_for('main.index'))
        else:
            flash('邮箱或密码错误')
    return render_template('auth/change_email.html', form=form)
示例#19
0
def change_email_request():
    if current_user.verify_password(request.form.get('password')):
        new_email = request.form.get('email')
        token = current_user.generate_email_change_token(new_email)
        message_text = render_template('email/change_email.html',
                                       user=current_user,
                                       token=token)
        send_async_email.apply_async(args=[
            new_email,
            make_subject('Confirm Your New Email'), message_text
        ])
        return jsonify(True)
示例#20
0
def change_email():
    form = EmailChangeForm()
    if form.validate_on_submit():
        new_email = form.data.get('email')
        token = current_user.generate_email_change_token(new_email)
        send_email(new_email,
                   '重置邮箱地址',
                   'auth/email/change_email',
                   user=current_user,
                   token=token)
        flash('a change-email email has sent to you by email')
        redirect(url_for('main.index'))
    return render_template('auth/change_email.html', form=form)
示例#21
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.check_password(form.password.data):
            new_email = form.email.data
            token = current_user.generate_email_change_token(new_email)
            send_email(current_user, new_email, 'change_email', token)
            flash(
                'An email instructions to confirm your new email '
                'address has been sent to you.', 'success')
            return redirect(url_for('.index', user_id=current_user.id))
        flash('Invalid email or password.', 'warning')
    return render_template('user/change_email.html', form=form)
示例#22
0
 def post(self):
     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('main.index'))
         else:
             flash('无效的邮箱或密码!')
     return render_template('auth/change_email.html', form=form)
示例#23
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, u'确认你的email地址', 'auth.email.change_email',
            #            user=current_user, token=token)
            flash(u'一封带着确认链接的邮件已经发送到你的邮箱.')
            return redirect(url_for('main.index'))
        else:
            flash(u'Invalid request.无效的请求')
        return redirect(url_for('main.index'))
示例#24
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, u'变更邮箱确认',
                       'auth/email/change_email',
                       user=current_user, token=token)
            flash(u'已向您发送一封包含变更邮箱指示的邮件,请查阅')
            return redirect(url_for('main.index'))
        else:
            flash(u'无效邮箱或密码')
    return render_template("auth/change_email.html", form=form)
示例#25
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, '确认邮箱',
                       'change_email',
                       user=current_user, token=token)
            flash('用于确认邮箱的邮件已发送至您的邮箱!')
            return redirect(url_for('main.index'))
        else:
            flash('无效邮箱或密码!')
    return render_template("auth/change_email.html", form=form)
示例#26
0
def change_email_request():
    if request.method == 'POST':
        new_email = request.form.get('new_email')
        password = request.form.get('password')
        if current_user.verify_password(password):
            token = current_user.generate_email_change_token(new_email)
            send_email([new_email], '确认你的邮箱地址',
                       'mail/auth/change_email.html',
                       user=current_user, token=token)
            flash('确认邮箱地址已发送')
            return redirect(url_for('index'))
        else:
            flash('无效的密码或者邮箱.')
    return render_template("auth/change_email.html")
示例#27
0
文件: views.py 项目: wakanow/my_blog
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)
            print(token)
            send_email(new_email, '认证你的邮箱', 'auth/email/change_email',
                       user=current_user, token=token)
            flash('一封指导你认证的邮件已经发送到你的邮箱', 'success')
            return redirect(url_for('main.index'))
        else:
            flash('无效的邮箱或密码', 'warning')
    return render_template('auth/change_email.html', form=form)
示例#28
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('咱寄出了一封帮忙更换邮件地址的电子邮件呐~去看看汝新邮箱的的收件箱呗.')
            return redirect(url_for('main.index'))
        else:
            flash('( ̄ε(# ̄)☆╰╮( ̄▽ ̄///) 邮件地址或密码不对~.')
    return render_template("auth/change_email.html", form=form)
示例#29
0
def change_email_request():
    """请求更改邮箱"""
    form = ChangeEmailForm()
    new_email = form.new_email.data
    if form.validate_on_submit():
        if not current_user.verify_password(form.password.data):
            flash("您输入的密码错误!请重新输入!")
            return redirect(url_for('auth.change_email_request'))
        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('main.index'))
    return render_template('auth/change_email.html', form=form)
示例#30
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, current_time=datetime.now(tz.gettz('CST')).strftime("%B %d, %Y %H:%M CST"))
            flash('An email with instructions to confirm your new email address has been sent to ' + new_email + '.',
                  'alert-info')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.', 'alert_danger')
    return render_template('auth/change_email.html', form=form)
示例#31
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('main.index'))
        else:
            flash('不合法的邮箱地址或密码.')
    return render_template("auth/change_email.html", form=form)
示例#32
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_mail(new_email, 'Confirm your email address',
					   'auth/email/change_email',
					   user=current_user, token=token)
			flash('一封确认您新邮件地址的邮件已经发给您的邮箱了.')
			return redirect(url_for('main.index'))
		else:
			flash('无效的邮箱或密码.')
	return render_template("auth/change_email.html", form=form)
示例#33
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('blog.index'))
        else:
            flash('无效的邮箱或密码')
    return render_template("auth/change_email.html", form=form)
示例#34
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        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', category='info')
        return redirect(session.get('previous_url', url_for('main.index')))
    if request.method == 'GET':
        session['previous_url'] = request.referrer
    return render_template('auth/change_email.html', form=form)
示例#35
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, '认证您的邮箱地址',
                       'auth/email/change_email',
                       user=current_user, token=token)
            flash('已向您发送一封电子邮件,其中包含确认您的新电子邮件地址的说明')
            return redirect(url_for('main.index'))
        else:
            flash('邮箱或密码错误')
    return render_template("auth/change_email.html", form=form)
示例#36
0
文件: views.py 项目: zkwolf/zk-blog
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("重置密码的邮件已邮递到您的信箱.")
            return redirect(url_for("main.index"))
        else:
            flash("无效的邮箱或密码.")
    return render_template("auth/change_email.html", form=form)
示例#37
0
文件: views.py 项目: dannyX21/twittec
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, 'Confirma tu direccion de Email',
                       'auth/email/change_email',
                       user=current_user, token=token)
            flash('Se envio un correo con instrucciones para confirmar tu cuenta.')
            return redirect(url_for('main.index'))
        else:
            flash('Usuario o contrasena invalida.')
    return render_template("auth/change_email.html", form=form)
示例#38
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, u'邮箱验证',
                       'auth/email/change_email',
                       user=current_user, token=token)
            flash(u'邮箱更改链接已发送到您所要更改到邮箱')
            return redirect(url_for('user.account'))
        else:
            flash(u'邮箱或密码错误')
    return render_template("auth/change_email.html", form=form)
示例#39
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)
            rendered_content = render_template(
                        'auth/email/change_email.html',
                        user=current_user, token=token)
            send_email.delay(
                    new_email, u'更换邮箱确认'.encode('utf-8'), rendered_content)
            flash(u'确认新邮箱地址的链接已经发送到你的邮箱')
            return redirect(url_for('main.index'))
        else:
            flash(u'非法邮箱地址或者密码')
    return render_template("auth/change_email.html", form=form)
示例#40
0
文件: views.py 项目: chris-zh/qb
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)
            try:
                send_email(new_email, 'Confirm your email address',
                           'auth/email/change_email',
                           user=current_user, token=token)
                flash('一封确认邮件已经发送至你的邮箱.')
            except:
                flash('发送邮件失败,请查看日志.')
            return redirect(url_for('main.index'))
        else:
            flash('邮箱或密码错误.')
    return render_template("auth/change_email.html", form=form)
示例#41
0
def change_email_request():
    '''
    @note: 更改邮箱
    '''
    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('已发送一封包含确认您的新电子邮件地址的说明的电子邮件。','info')
            return render_template("auth/change_email.html", form=form)
        else:
            flash('无效的邮箱或密码','danger')
    return render_template("auth/change_email.html", form=form)
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(
                to=new_email,
                subject='Confirm your email address',
                template='auth/email/change_email',
                user=current_user,
                token=token,
            )
            flash('An email with the instructions to confirm your new email'
                  ' has been sent.')
        else:
            flash('Invalid password')
    return render_template('auth/change_email.html', form=form)
示例#43
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)