Ejemplo n.º 1
0
def reset_password_request():
    if current_user.is_authenticated:
        #已经登陆了 不需要重置密码了
        return redirect(url_for('index'))
    form = PasswordResetRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash("You will receive an email allowing you to reset your \
                    password. Please check your trash or spam if you could not find it."
                  )
            #send email in this block#
            token = user.get_jwt()
            url = 'http://127.0.0.1:5000/password_reset/{}'.format(token)
            send_email(
                subject='[Twittor] Reset your password',
                recipients=[user.email],
                text_body="please click this link to reset your password, \
                            please do not share this link with anyone. {}".
                format(url),
                html_body='<h5> please click this link to reset your password, \
                            please do not share this link with anyone. {}</h5>'
                .format(url))
        return redirect(url_for('login'))
    return render_template('password_reset_request.html', form=form)
Ejemplo n.º 2
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = PasswdResetRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash("您将收到一封允许您重置密码的电子邮件。如果找不到这封邮件,请务必检查您的垃圾邮件!")
            token = user.get_jwt()
            url_password_reset = url_for(
                'reset_password_request',
                token=token,
                _external=True  #发送的链接是完整的http链接
            )
            url_password_reset_request = url_for('reset_password_request',
                                                 _external=True)
            send_email(
                subject=current_app.config['MAIL_SUBJECT_RESET_PASSWORD'],  #主题
                recipients=[user.email],  #接收者
                text_body=render_template(
                    'email/passwd_reset.txt',
                    url_password_reset=url_password_reset,
                    url_password_reset_request=url_password_reset_request),
                html_body=render_template(
                    'email/passwd_reset.html',
                    url_password_reset=url_password_reset,
                    url_password_reset_request=url_password_reset_request))
        return redirect(url_for('login'))
    return render_template('password_reset_request.html',
                           title="重置密码",
                           form=form)
Ejemplo n.º 3
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = PasswdResetRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash('Reset password link have send to your Email Box.')
        token = user.get_jwt()
        url_password_reset = url_for('password_reset',
                                     token=token,
                                     _external=True)
        url_password_reset_request = url_for('reset_password_request',
                                             _external=True)
        send_email(subject='Twittor - Reset your password',
                   recipients=[user.email],
                   text_body=render_template(
                       'email/passwd_reset.txt',
                       url_password_reset_request=url_password_reset_request,
                       url_password_reset=url_password_reset),
                   html_body=render_template(
                       'email/passwd_reset.html',
                       url_password_reset_request=url_password_reset_request,
                       url_password_reset=url_password_reset))
        return redirect(url_for('login'))
    return render_template('password_reset_request.html', form=form)
Ejemplo n.º 4
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = PasswdResetRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash(
                "You should soon receive an email allowing you to reset your \
                password. Please make sure to check your spam and trash \
                if you can't find the email.")
            token = user.get_jwt()
            url_password_reset = url_for('password_reset',
                                         token=token,
                                         _external=True)
            url_password_reset_request = url_for('reset_password_request',
                                                 _external=True)
            url = 'http://127.0.0.1:5000/password_reset/{}'.format(token)
            send_email(
                subject=current_app.config['MAIL_SUBJECT_RESET_PASSWORD'],
                recipients=['*****@*****.**'],
                text_body=render_template(
                    'email/passwd_reset.txt',
                    url_password_reset=url_password_reset,
                    url_password_reset_request=url_password_reset_request),
                html_body=render_template(
                    'email/passwd_reset.html',
                    url_password_reset=url_password_reset,
                    url_password_reset_request=url_password_reset_request))
        else:
            raise
        return redirect(url_for('login'))
    return render_template('password_reset_request.html', form=form)
Ejemplo n.º 5
0
def send_email_for_user_activate(user):
    token = user.get_jwt()
    url_user_activate = url_for('user_activate', token=token, _external=True)
    send_email(subject=current_app.config['MAIN_SUBJECT_USER_ACTIVATE'],
               recipients=[user.email],
               text_body=render_template('email/user_activate.txt',
                                         username=user.username,
                                         url_user_activate=url_user_activate),
               html_body=render_template('email/user_activate.txt',
                                         username=user.username,
                                         url_user_activate=url_user_activate))
Ejemplo n.º 6
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = PasswdResetRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash('You will receive a verify email in your mailbox ')
            token = user.get_jwt()
            url = 'http://127.0.0.1:5000/password_reset/{}'.format(token)
            send_email(subject='Reset your password',
                       recipients=[user.email],
                       text_body=url,
                       html_body='<h1>{}</h1>'.format(url))

        else:
            raise
        return redirect(url_for('login'))
    return render_template('password_reset_request.html', form=form)
Ejemplo n.º 7
0
def reset_password_request():
    if current_user.is_authenticated: #如果當前用戶已經登入不需要重置密碼
        return redirect(url_for('index'))
    form = PasswdResetRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash("You should soon receive an email allowing you to reset your password.\
                 find te email") #以上為運用flash頁面顯示訊息
            token = user.get_jwt() #重設的編碼
            url_password_reset = url_for(
                'password_reset',
                token=token,
                _external=True #完整的連結
            )
            url_password_reset_request = url_for(
                'reset_password_request',
                _external=True
            )
            # url='http://127.0.0.1:5000/password_reset/{}'.format(token) #組合成重設網址
            send_email(
                subject=current_app.config['MAIL_SUBJECT_RESET_PASSWORD'],
                #sender='*****@*****.**',
                recipients=[user.email],
                text_body=render_template(
                    'email/passwd_reset.txt',
                    url_password_reset=url_password_reset,
                    url_password_reset_request=url_password_reset_request),
                html_body=render_template(
                    'email/passwd_reset.html',
                    url_password_reset=url_password_reset,
                    url_password_reset_request=url_password_reset_request
                )
            )
        else:
            raise
        return redirect(url_for('login'))
    return render_template('password_reset_request.html',form=form)