示例#1
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'))
示例#2
0
def reset_password():
    form = Reset_Form()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        token = user.generate_token()
        send_email(user.email,
                   'Reset Your Password',
                   'reset_password',
                   enable=True,
                   user=user,
                   token=token)
        flash('We send a email to you for reseting your password.')
    return render_template('reset.html', form=form)
示例#3
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)
示例#4
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)
示例#5
0
def register():
    form = Registration_Form()
    if form.validate_on_submit():
        user = User(
            username=form.username.data,
            email=form.email.data,
            password=form.password1.data,
        )
        db.session.add(user)
        db.session.commit()
        token = user.generate_token()
        send_email(user.email,
                   'Confirm Your Account',
                   'confirm',
                   enable=False,
                   user=user,
                   token=token)
        user.confirmed = True
        flash('Regrister Successful,Now you can login.')
        return redirect(url_for('.login'))
    return render_template('register.html', form=form)