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})
def get_context_data(self, **kwargs): context = super(ChangePasswordView, self).get_context_data(**kwargs) context["change_password_form"] = ChangePasswordForm() return context
def get_context_data(self, **kwargs): context = super(ChangePasswordView, self).get_context_data(**kwargs) context["TITLE"] = settings.TITLE ## Added for easilt Changeable Title context["change_password_form"] = ChangePasswordForm() return context