def post(self, request, *args, **kwargs): error, errors = "", "" form = ChangePasswordForm(request.POST, user=request.user) if form.is_valid(): user = request.user user.set_password(request.POST.get('Newpassword')) user.is_active = True user.save() return HttpResponseRedirect('inventory:landing_index') else: errors = form.errors return render(request, "change_password.html", {'error': error, 'errors': errors, 'change_password_form': form})
def post(self, request, *args, **kwargs): error, errors = "", "" form = ChangePasswordForm(request.POST) if form.is_valid(): user = request.user if not check_password(request.POST.get('CurrentPassword'), user.password): error = "Invalid old password" else: user.set_password(request.POST.get('Newpassword')) user.is_active = True user.save() return HttpResponseRedirect('/') else: errors = form.errors return render(request, "change_password.html", {'error': error, 'errors': errors})
def change_pass(request): error, errors = "", "" form = ChangePasswordForm() if request.method == 'POST': form = ChangePasswordForm(request.POST) if form.is_valid(): user = request.user if not check_password(request.POST['CurrentPassword'], user.password): error = "Invalid old password" else: user.set_password(request.POST.get('Newpassword')) user.is_active = True user.save() return HttpResponseRedirect('/') else: errors = form.errors return render(request, "change_password.html", {'error': error, 'errors': errors})