예제 #1
0
def reset_with_token(token):
    try:
        password_reset_serializer = URLSafeTimedSerializer(
            app.config['SECRET_KEY'])
        email = password_reset_serializer.loads(token,
                                                salt='password-reset-salt',
                                                max_age=3600)
    except:
        flash('The password reset link is invalid or has expired.', 'error')
        return redirect(url_for('users.login'))

    form = PasswordForm()

    if form.validate_on_submit():
        try:
            user = User.query.filter_by(email=email).first_or_404()
        except:
            flash('Invalid email address!', 'error')
            return redirect(url_for('users.login'))

        user.password = form.password.data
        db.session.add(user)
        db.session.commit()
        flash('Your password has been updated!', 'success')
        return redirect(url_for('users.login'))

    return render_template('reset_password_with_token.html',
                           form=form,
                           token=token)
예제 #2
0
def password_edit(request):
    user = request.user
    email = user.email
    player = Player.objects.get(user=user)
    if request.method == 'POST':
        form = PasswordForm(request.POST)
        if form.is_valid():
            # print form.cleaned_data
            password = form.cleaned_data['password']
            user.set_password()
            user.save()
            player.save()
            return HttpResponseRedirect('/')
    else:
        player = Player.objects.get(user=user)
    form = PasswordForm()
예제 #3
0
파일: views.py 프로젝트: fyelles/courtside
def password_edit(request):
    user = request.user
    email = user.email
    player = Player.objects.get(user=user)
    if request.method == 'POST':
        form = PasswordForm(request.POST)
        if form.is_valid():
            # print form.cleaned_data
            password = form.cleaned_data['password']
            user.set_password()
            user.save()
            player.save()
            return HttpResponseRedirect('/')
    else:
        player = Player.objects.get(user=user)
    form = PasswordForm()
예제 #4
0
파일: index.py 프로젝트: pako535/melvil
def reset_with_token(token):
    try:
        password_reset_serializer = URLSafeTimedSerializer(
            DevConfig.SECRET_KEY)
        email = password_reset_serializer.loads(token,
                                                salt='password-reset-salt',
                                                max_age=3600)
    except RuntimeError:
        message_body = 'The password reset link is invalid or has expired.'
        message_title = 'Error!'
        return render_template('message.html',
                               message_title=message_title,
                               message_body=message_body)

    form = PasswordForm()

    if form.validate_on_submit():
        try:
            user = User.query.filter_by(email=email).first_or_404()
        except ValueError:
            message_body = 'Invalid email address!'
            message_title = 'Error!'
            return render_template('message.html',
                                   message_title=message_title,
                                   message_body=message_body)

        user.password_hash = generate_password_hash(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Your password has been updated!', 'success')
        return redirect(url_for('library.login'))

    return render_template('reset_password_with_token.html',
                           form=form,
                           token=token,
                           error=form.errors)