def change_password(request): if request.is_ajax(): user = User.objects.get(id=request.user.id) response = {"status": True, "errors": []} if request.method == "POST": form = ChangePasswordForm(request.user, request.POST or None, use_required_attribute=False) if form.is_valid(): form.save() update_session_auth_hash(request, user) messages.add_message( request, messages.INFO, "Password has been updated successfully! Please Login again" ) else: response["status"] = False for key, value in form.errors.items(): tmp = {'key': key, 'error': value.as_text()} response['errors'].append(tmp) return HttpResponse(json.dumps(response))
def change_password(request): if request.method == 'POST': form = ChangePasswordForm(user=request.user, data=request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('logout')) else: form = ChangePasswordForm(user=request.user) results = { 'form': form, 'request': request, } return render(request, 'accounts/change_password.html', results)
def change_password(request): temp_name = "accounts/accounts-header.html" if request.method == 'POST': form = ChangePasswordForm(user=request.user, data=request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('user_list')) else: form = ChangePasswordForm(user=request.user) kwargs = { 'form': form, 'request': request, 'temp_name': temp_name, } return render(request, 'accounts/change_password.html', kwargs)
def change_password(request): if not request.user.is_authenticated: messages.error(request, "로그인 하셔야 합니다.") context = {} return redirect('accounts:login') else: if request.method == "POST": change_password_form = ChangePasswordForm(request.user, request.POST) if change_password_form.is_valid(): user = change_password_form.save() update_session_auth_hash(request, user) messages.info(request, '비밀번호 변경 완료') return redirect('accounts:view_profile') else: messages.error(request, '비밀번호 변경 실패') else: change_password_form = ChangePasswordForm(request.user) context = { 'password_change_form': change_password_form, } return render(request, 'accounts/password_change.html', context=context)
def change_password(request): if request.method == 'POST': JSON_RESULT = {'status': 200, 'message': '', 'error': '', 'data': []} forms = ChangePasswordForm(request, data=request.POST) if forms.is_valid(): forms.save() auth.update_session_auth_hash(request, request.user) JSON_RESULT['message'] = '修改成功' return JsonResponse(JSON_RESULT) JSON_RESULT['status'] = 201 JSON_RESULT['error'] = forms.errors.as_json() return JsonResponse(JSON_RESULT) else: forms = ChangePasswordForm(request) html_title = '修改密码' cancel = reverse('accounts:user-list') return render(request, 'accounts/change_password.html', locals())
def post(self, request): form = ChangePasswordForm(request.user, request.POST) if form.is_valid(): user = form.save() update_session_auth_hash(request, user) messages.success( request, 'Udało sie zmienić hasło. Proszę zalogować się ponownie, nowym hasłem.' ) return redirect('url_login') return render(request, 'change-password.html', {'form': form})
def change_password(request): message = '' if request.method == 'POST': form = ChangePasswordForm(request.user, request.POST) form_help = PasswordChangeForm(request.user) if form.is_valid(): user = form.save() update_session_auth_hash(request, user) # Important! message = 'Hasło zmienione poprawnie!' else: messages.error(request, 'Please correct the error below.') else: form = ChangePasswordForm(request.user) form_help = PasswordChangeForm(request.user) return render(request, 'accounts/password_change.html', { 'form': form, 'message': message, 'form_help': form_help })