示例#1
0
def reset_password(data=None):
    if utils.get_config('no_emails'):
        return redirect(url_for('auth.login'))
    logger = logging.getLogger('logins')

    if data is not None:
        try:
            s = TimedSerializer(app.config['SECRET_KEY'])
            name = s.loads(utils.base64decode(data, urldecode=True),
                           max_age=1800)
        except BadTimeSignature:
            return render_template('reset_password.html',
                                   errors=['Your link has expired'])
        except (BadSignature, TypeError, base64.binascii.Error):
            return render_template('reset_password.html',
                                   errors=['Your reset token is invalid'])

        if request.method == "GET":
            return render_template('reset_password.html', mode='set')
        if request.method == "POST":
            team = Teams.query.filter_by(name=name).first_or_404()
            team.password = bcrypt_sha256.encrypt(
                request.form['password'].strip())
            db.session.commit()
            logger.warn(
                "[{date}] {ip} -  successful password reset for {username}".
                format(date=time.strftime("%m/%d/%Y %X"),
                       ip=utils.get_ip(),
                       username=team.name.encode('utf-8')))
            db.session.close()
            return redirect(url_for('auth.login'))

    if request.method == 'POST':
        email = request.form['email'].strip()
        team = Teams.query.filter_by(email=email).first()

        errors = []

        if utils.can_send_mail() is False:
            return render_template(
                'reset_password.html',
                errors=[
                    'Email could not be sent due to server misconfiguration'
                ])

        if not team:
            return render_template(
                'reset_password.html',
                errors=[
                    'If that account exists you will receive an email, please check your inbox'
                ])

        utils.forgot_password(email, team.name)

        return render_template(
            'reset_password.html',
            errors=[
                'If that account exists you will receive an email, please check your inbox'
            ])
    return render_template('reset_password.html')
示例#2
0
def reset_password(data=None):
    logger = logging.getLogger('logins')

    if data is not None:
        try:
            s = TimedSerializer(app.config['SECRET_KEY'])
            name = s.loads(utils.base64decode(data, urldecode=True),
                           max_age=1800)
        except BadTimeSignature:
            return render_template('reset_password.html',
                                   errors=['您的密码重置链接已经过期'])
        except (BadSignature, TypeError, base64.binascii.Error):
            return render_template('reset_password.html',
                                   errors=['您的密码重置令牌已经失效'])

        if request.method == "GET":
            return render_template('reset_password.html', mode='set')
        if request.method == "POST":
            team = Teams.query.filter_by(name=name).first_or_404()
            team.password = bcrypt_sha256.encrypt(
                request.form['password'].strip())
            db.session.commit()
            logger.warn(
                "[{date}] {ip} -  successful password reset for {username}".
                format(date=time.strftime("%m/%d/%Y %X"),
                       ip=utils.get_ip(),
                       username=team.name.encode('utf-8')))
            db.session.close()
            return redirect(url_for('auth.login'))

    if request.method == 'POST':
        email = request.form['email'].strip()
        team = Teams.query.filter_by(email=email).first()

        errors = []

        if utils.can_send_mail() is False:
            return render_template('reset_password.html',
                                   errors=['邮件信息配置异常,无法发送邮件,请联系管理员'])

        if not team:
            return render_template('reset_password.html',
                                   errors=['如果邮箱有效,将会收到一封密码重置邮件,请注意查收'])

        utils.forgot_password(email, team.name)

        return render_template('reset_password.html',
                               errors=['如果邮箱有效,将会收到一封密码重置邮件,请注意查收'])
    return render_template('reset_password.html')
示例#3
0
def reset_password(data=None):
    logger = logging.getLogger('logins')

    if data is not None:
        try:
            s = TimedSerializer(app.config['SECRET_KEY'])
            name = s.loads(utils.base64decode(data, urldecode=True),
                           max_age=1800)
        except BadTimeSignature:
            return render_template('reset_password.html',
                                   errors=[get_tip('LINK_EXPIRED')])
        except (BadSignature, TypeError, base64.binascii.Error):
            return render_template('reset_password.html',
                                   errors=[get_tip('INVIDE_RESET_TOKEN')])

        if request.method == "GET":
            return render_template('reset_password.html', mode='set')
        if request.method == "POST":
            team = Teams.query.filter_by(name=name).first_or_404()
            team.password = bcrypt_sha256.encrypt(
                request.form['password'].strip())
            db.session.commit()
            logger.warn(
                get_tip('PASS_HAVE_RESET').format(
                    date=time.strftime("%m/%d/%Y %X"),
                    ip=utils.get_ip(),
                    username=team.name.encode('utf-8')))
            db.session.close()
            return redirect(url_for('auth.login'))

    if request.method == 'POST':
        email = request.form['email'].strip()
        team = Teams.query.filter_by(email=email).first()

        errors = []

        if utils.can_send_mail() is False:
            return render_template('reset_password.html',
                                   errors=[get_tip('EMAIL_NOT_CONFIG')])

        if not team:
            return render_template('reset_password.html',
                                   errors=[get_tip('FORGOT_PASS_NOTICE')])

        utils.forgot_password(email, team.name)

        return render_template('reset_password.html',
                               errors=[get_tip('FORGOT_PASS_NOTICE')])
    return render_template('reset_password.html')