Example #1
0
 def test_confirm_is_required(self):
     data = {
         "old": "old",
         "new": "new",
     }
     form = ChangePasswordForm(data)
     self.assertFalse(form.is_valid())
Example #2
0
 def test_form_is_valid(self):
     data = {
         "old": "old",
         "new": "new",
         "confirm": "new",
     }
     form = ChangePasswordForm(data)
     self.assertTrue(form.is_valid())
Example #3
0
def change_password_post():
    form = ChangePasswordForm(request.form)
    user = g.user
    if form.validate():
        if check_password_hash(user.password, form.old_password.data):
            password = generate_password_hash(form.password.data)
            user.password = password
            db.session.commit()
            flash('Hasło zostało zmienione', 'success')
            return redirect(url_for('auth.dashboard'))
    return render_template('pages/change_password.html', form=form)
Example #4
0
File: views.py Project: ZAS0RIN/lbt
def profile():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        print 'f1'
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.commit()
            flash('Ваш пароль был изменен.')
            return redirect(url_for('events'))
        else:
            flash('Не верный пароль.')
    return render_template('profile.html', form=form)
Example #5
0
def change_password(request):
    """ Module for changing the password of the user """

    redis_obj = Redis()
    user_id = get_userId(request)
    username = get_username(redis_obj, user_id)

    if request.method == "POST":

        change_password_form = ChangePasswordForm(data=request.POST)
        if change_password_form.is_valid():

            change_password_form_cleaned = change_password_form.cleaned_data
            old_password = encrypt_password(change_password_form_cleaned["old_password"])
            new_password = encrypt_password(change_password_form_cleaned["new_password"])

            if get_password(redis_obj, user_id) == old_password:
                store_password(redis_obj, user_id, new_password)
                return HttpResponseRedirect("/home")

            return render_to_response(
                CHANGE_PASSWORD_TEMPLATE_PATH,
                {
                    "change_password_form": change_password_form,
                    "change_password_error": "Password you gave is incorrect",
                    "username": username,
                },
                context_instance=RequestContext(request),
            )

        return render_to_response(
            CHANGE_PASSWORD_TEMPLATE_PATH,
            {
                "change_password_form": change_password_form,
                "change_password_error": "Invalid password entries",
                "username": username,
            },
            context_instance=RequestContext(request),
        )

    change_password_form = ChangePasswordForm()
    return render_to_response(
        CHANGE_PASSWORD_TEMPLATE_PATH,
        {"change_password_form": change_password_form, "username": username},
        context_instance=RequestContext(request),
    )
Example #6
0
def change_password():
    form = ChangePasswordForm(obj=g.user)
    return render_template('pages/change_password.html', form=form)