Ejemplo n.º 1
0
def reset_password_request():
    if current_user.is_authenticated:
        flash('You are already logged in.')
        return redirect(url_for('index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = studentList.find_one({'email': form.email.data})
        student = Student()
        student.buildFromDict(user)
        if user is not None:
            send_password_reset_email(student)
        flash('Check your email for the instructions to reset your password')
        return redirect(url_for('login'))
    return render_template('reset_password_request.html',
                           title='Reset Password',
                           form=form)
Ejemplo n.º 2
0
def login():
    if current_user.is_authenticated:
        flash('You are already logged in.')
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = studentList.find_one({'email': form.email.data})
        student = Student()
        student.buildFromDict(user)
        if user is None or not student.check_password(
                form.password.data):  #checks that password matches input
            flash('Invalid email or password')
            return redirect(url_for('login'))
        login_user(student, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html', title='Sign In', form=form)
Ejemplo n.º 3
0
def reset_password(token):
    if current_user.is_authenticated:
        flash('You are already logged in. No need to reset your password.')
        return redirect(url_for('index'))
    user = Student.verify_reset_password_token(token)
    if user is None:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        student = Student()
        student.buildFromDict(user)
        student.set_password(form.password.data)
        studentList.find_one_and_update(
            {'email': student.email},
            {'$set': {
                'password_hash': student.password_hash
            }})
        flash('Your password has been reset')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)