Example #1
0
def regenerate_token():
    try:
        return jsonify({'token': current_user.generate_token()})
    except InactiveUserException:
        raise BadRequest("Can't generate new token unless account is active.")
    except TokenGenerationLimitException as e:
        return jsonify({'error': e.message}), 429  # https://tools.ietf.org/html/rfc6585#page-3
Example #2
0
def password_reset_request():
    if not current_user.is_authenticated:
        form = ResetRequestForm()
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user is None:
                flash('该Email还没注册')
                return redirect(url_for('auth.password_reset_request'))
            token = user.generate_token()
            send_mail('重设密码',
                      user.email,
                      'auth/mail/reset_password',
                      user=user,
                      token=token)
            flash('验证邮件已发送')
        return render_template('auth/reset_password.html', form=form)
    else:
        token = current_user.generate_token()
        send_mail('重设密码',
                  current_user.email,
                  'auth/mail/reset_password',
                  user=current_user,
                  token=token)
        flash('验证邮件已发送')
        return render_template('auth/mail/reset_password.html',
                               user=current_user)
Example #3
0
def regenerate_token():
    try:
        return jsonify({'token': current_user.generate_token()})
    except InactiveUserException:
        raise BadRequest("Can't generate new token unless account is active.")
    except TokenGenerationLimitException as e:
        return jsonify({'error': e.message}), 429  # https://tools.ietf.org/html/rfc6585#page-3
Example #4
0
def measurement():
    token = current_user.generate_token(
        expiration=app.config['TOKEN_EXPIRES_IN'], token_type='bokeh')
    _request = urlencode(dict(token=token))
    script = autoload_server(model=None,
                             app_path="/_measure",
                             request=_request)
    return render_template('_bokeh/base_bokeh.html', bokeh_script=script)
Example #5
0
def reset_mail():
    token = current_user.generate_token()
    html = render_template('email/reset_mail.html',
                           token=token,
                           name=current_user.name)
    send_mail('曹旭注册验证', current_app.config['MAIL_USERNAME'],
              [current_user.email], None, html)
    return redirect(url_for('auth.unconfirm'))
Example #6
0
def change_email_request():
    token = current_user.generate_token()
    send_mail('修改Email地址',
              current_user.email,
              'auth/mail/change_email',
              user=current_user,
              token=token)
    flash('修改Email验证邮件已发送')
    return render_template('auth/mail/change_email.html', user=current_user)
Example #7
0
def resend_confirmation():
    token = current_user.generate_token(token_name='confirm')
    send_email(current_user.email,
               '确认您的邮箱',
               'auth/email/confirm',
               user=current_user,
               token=token)
    flash('我们已向您的邮箱发送了一封新的验证邮件.')
    return redirect(url_for('main.index'))
Example #8
0
def resend_confirmation():
    token = current_user.generate_token()
    send_email(current_user.email,
               'Confrim Your Account',
               'auth/email/confirm',
               user=current_user,
               token=token)
    flash('A New confirmaiton email has been sent to your mailbox.')
    return redirect(url_for('main.index'))
Example #9
0
def resend_confirmation():
    token = current_user.generate_token()
    send_mail(current_user.email,
              'Confirm your account',
              'auth/email/confirm',
              user=current_user,
              token=token)
    flash('a confirm email has been sent to your email.')
    return redirect(url_for('main.index'))
Example #10
0
def resend_confirm_email():
    """重新生成令牌并发送邮件"""
    if current_user.confirmed:
        return redirect(url_for('blog.index'))

    token = current_user.generate_token(Operations.CONFIRM)
    send_confirm_email(user=current_user, token=token)
    flash('New email sent, check your inbox.', 'info')
    return redirect(url_for('blog.index'))
Example #11
0
def resend_confirmation():
    token = current_user.generate_token('confirm')
    print(current_user)
    send_email(current_user.email,
               'Confirm Your Account',
               'mail/confirm',
               user=current_user,
               token=token)
    flash(alerts['resent_confirm_email'])
    return redirect(url_for('main.index'))
Example #12
0
def resend_confirmation():
    token = current_user.generate_token()
    send_email(current_user.email,
               'Confirm Your Account',
               'auth/email/confirm',
               user=current_user,
               token=token)
    flash('A new confirmation email has been sent to you by email.',
          category='success')
    return redirect(url_for('main.index'))
Example #13
0
def resend_link():
    token = current_user.generate_token()
    send_mail(current_user.email,
              'contact',
              'user/mail/unconfirmed',
              user=current_user,
              token=token)
    flash("A new new email with a confirmation has been sent to your email.",
          'success')
    return redirect(url_for('page.home'))
Example #14
0
def change_email_request():
    """发送更改邮箱令牌"""
    form = ChangeEmailForm()
    if form.validate_on_submit():
        new_email = form.email.data.lower()
        token = current_user.generate_token(operation=Operations.CHANGE_EMAIL, new_email=new_email)
        send_change_email_email(user=current_user, token=token, to=new_email)
        flash('Confirm email sent, check your inbox.', 'info')
        return redirect(url_for('user.index', username=current_user.username))
    return render_template('user/change_email.html', form=form)
Example #15
0
def resend_confirmation():
    token = current_user.generate_token()
    send_email(current_user.email,
               'Confirm Your Account',
               'confirm',
               enable=True,
               user=current_user,
               token=token)
    flash('A new confirmation email has been sent to you.')
    return redirect(url_for('root_bp.index'))
Example #16
0
def resend_token():
    if current_user.is_anonymous or current_user.confirmed:
        return redirect(url_for('main.index'))
    token = current_user.generate_token('confirm')
    send_email(current_user.email,
               'Confirm Your Account',
               'auth/email/confirm',
               user=current_user,
               token=token)
    flash('A new confirmation email has been sent to you.')
    return redirect(url_for('auth.unconfirmed'))
Example #17
0
def resend_confirmation():
    token = current_user.generate_token()
    send_mail(current_user.email,
              'Confirm your account',
              'auth/email/confirm.html',
              user=current_user,
              token=token)
    flash(
        'An email has been sent to {0}. It contains an activation link you must click to activate your account.'
        .format(current_user.email))
    return redirect(url_for('main.index', _external=True))
Example #18
0
def resend_confirmation():
    if current_user.confirmed:
        return redirect(url_for('main.index'))
    token = current_user.generate_token()
    send_email.delay(
        recipients=[current_user.email],
        subject=gettext('Confirm your account'),
        body=render_template('auth/email/confirm.txt', user=current_user, token=token),
        html=render_template('auth/email/confirm.html', user=current_user, token=token)
    )
    flash(lazy_gettext('A new confirmation email has been sent to you by email.'))
    return redirect(url_for('main.index'))
Example #19
0
def user_reconfirm():
    """
    When user can't receive the confirm email,app can resend the email through this view.
    """
    if current_user.confirmed:
        return render_template('auth/user_confirm.html', confirmed=True)
    else:
        token = current_user.generate_token()
        send_mail(to=current_user.email, subject="Confirm Your Account", template='auth/email/confirm',
                  token=token, user=current_user)
        flash("Register successful.Pleas log in.And a confirm message has been sent to your email.")
        return redirect(request.args.get('next') or url_for('auth.login'))
Example #20
0
def login():
    data = request.get_json()
    if not verify_auth(data.get("username"), data.get("password")):
        return jsonify({
            "code": 60204,
            "message": "Account and password are incorrect."
        })
    return jsonify({
        "code": 20000,
        "data": {
            "token": current_user.generate_token().decode()
        }
    })
Example #21
0
def resend_confirmation():
    """
    重新发送验证邮件
    :return:
    """
    token = current_user.generate_token()
    send_email(current_user.email,
               u'确认你的账户信息',
               'auth/email/confirm',
               user=current_user,
               token=token)
    flash(u'新的验证邮件已经发出')
    return redirect(url_for('main.index'))
Example #22
0
def email_bind():
    if current_user._email_bind:
        flash('禁止操作!')
        return redirect(url_for('web.personal'))
    from app.libs.helper import email_bind
    verification_code = email_bind()
    token = current_user.generate_token(verification_code=verification_code)
    send_mail(current_user.email,
              '绑定你的邮箱',
              'email/binding_email.html',
              code=verification_code)
    flash('已发送将验证码发送至邮箱: ' + str(current_user.email))
    return redirect(url_for('web.set_binding', token=token, _external=True))
Example #23
0
def resend_confirm():
    token = current_user.generate_token()
    print_debug(url_for('auth.confirm', token=token, _external=True))
    send_email(current_user.email,
               'Confirm Your Account',
               'confirm',
               '*****@*****.**',
               user=current_user,
               token=token)
    flash('A new confirmation email is sent to your email address. \
            You have 24 hours to verify your account.')
    log_message(f'user_id: {current_user.id} resent their confirmation email')
    return redirect(url_for('main.index'))
Example #24
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        new_email = form.new_email.data.lower()
        token = current_user.generate_token(new_email=new_email)
        send_email.delay(
            recipients=[new_email],
            subject=gettext('Confirm your new email'),
            body=render_template('auth/email/confirm_new_email.txt', user=current_user, token=token),
            html=render_template('auth/email/confirm_new_email.html', user=current_user, token=token)
        )
        flash(lazy_gettext('A confirmation email has been sent to your new email.'))
        return redirect(request.args.get('next') or url_for('main.index'))
    return render_template('auth/change_email.html', form=form)
Example #25
0
def change_email():
    form = ChangeEmail()
    if form.validate_on_submit():
        current_user.new_email = form.email.data
        token = current_user.generate_token(purpose='change_email')
        db.session.commit()
        send_email(current_user.email,
                   'Email address change',
                   'auth/email/change-email',
                   token=token)
        flash('An email with password reset link has been sent to you.')
    return render_template('auth/single-form.html',
                           form=form,
                           page_title="Change email")
Example #26
0
def change_email():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        newemail = form.newemail.data
        token = current_user.generate_token('email', newemail)
        send_email(newemail,
                   'Change Your Email Address',
                   'auth/email/confirm',
                   user=current_user,
                   token=token)
        logout_user()
        flash('A confirmation email has been sent to you by your new email,'
              'please login again.')
        return redirect((url_for('.login')))
    return render_template('auth/change_email.html', form=form)
Example #27
0
def send_reset_password():
    update_mail_config()

    # 配置邮件模板
    template = html.unescape(get_config("MAIL_VALIDATION_TEMPLATE"))
    template = render_template_string(template, user=current_user, token=current_user.generate_token())

    msg = Message(subject='郝明宸的个人博客来信', sender=get_config("MAIL_SMTP_USER"), recipients=[current_user.email],
                  html=template)
    thread = Thread(target=send_async_email, args=[app, msg])
    thread.start()
    return json.dumps({
        "code": 1,
        "message": "发送成功"
    })
Example #28
0
def check_old_email():
    form = Email_Form()
    if form.validate_on_submit():
        token = current_user.generate_token()
        if form.email.data == current_user.email:
            send_email(form.email.data,
                       'Check Your Old Email',
                       'check_old_email',
                       enable=True,
                       token=token,
                       user=current_user)
            flash('We have sent a email to you for checking your old email.')
            return redirect(url_for('root_bp.index'))
        else:
            flash('Invalid Email')
    return render_template('reset.html', form=form)
Example #29
0
def change_email_request():
    form = ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            token = current_user.generate_token(token_name='change_email',
                                                new_email=form.email.data)
            send_email(form.email.data,
                       '确认您的新邮箱',
                       'auth/email/change_email',
                       user=current_user,
                       token=token)
            flash('我们已向您的邮箱发送了一封邮件,请在邮件指示下确认新邮箱')
            return redirect(url_for('main.index'))
        else:
            flash('密码错误.')
    return render_template("auth/change_email_request.html", form=form)
Example #30
0
def check_new_email(token):
    form = Change_Email_Form()
    if form.validate_on_submit():
        if current_user.confirm(token):
            new_token = current_user.generate_token()
            send_email(form.email.data,
                       'Change New Email',
                       'change_new_email',
                       enable=True,
                       token=new_token,
                       user=current_user)
            current_user.email = form.email.data
            current_user.avatar_hash = hashlib.md5(
                current_user.email.encode('utf-8')).hexdigest()
            if form.email.data == current_app.config.get('MAIL_USERNAME'):
                current_user.role = Role.query.filter_by(
                    permissions=0xff).first()
            flash('Your email has changed to {}'.format(form.email.data))
        return redirect(url_for('root_bp.index'))
    return render_template('reset.html', form=form)
Example #31
0
def generate_token():
    current_user.generate_token()
    return redirect('user/{}'.format(current_user.name))
Example #32
0
def resend_email():
    token = current_user.generate_token()
    html = render_template('email/email_confirm.html', token=token, name=current_user.name)
    send_async_main(subject='本杰明社区', recvers=[current_user.email], html=html, body=None)
    flash('邮件已经重新发送')
    return redirect(url_for('main.user_info',id=current_user.id))