def password(request): user = request.user user1 = Users.objects.get(user=user) if request.method == 'POST': form = ChangePasswordForm(request.POST) if form.is_valid(): new_password = form.cleaned_data.get('new_password') user.set_password(new_password) user.save() update_session_auth_hash(request, user) user1.password = new_password user1.save() #messages.add_message(request, messages.SUCCESS, # 'Your password was successfully changed.') return redirect('password') else: form = ChangePasswordForm(instance=user) context = { 'form': form, 'name': "Change Password", 'password': "******", 'profile': user1, } return render(request, 'form.html', context)
def changePassword(request, id): user = User.objects.get(pk=id) if request.method == 'POST': form = ChangePasswordForm(request.POST) if form.is_valid(): password = form.cleaned_data['password'] new_password = form.cleaned_data['new_password'] if password != new_password: user.set_password(new_password) user.save() messages.success(request, 'Password changed!') return HttpResponseRedirect('/') else : messages.error(request, 'Same password!') return HttpResponseRedirect('/') else: form = ChangePasswordForm() response = HttpResponse(form) return response
def forgot_new(token): email = confirm_token(token) user = User.query.filter_by(email=email).first_or_404() if user.password_reset_token is not None: form = ChangePasswordForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(email=email).first() if user: # TODO: use utils methods user.password = bcrypt.generate_password_hash( form.password.data) user.password_reset_token = None db.session.commit() login_user(user) flash('Password successfully changed.', 'success') return redirect(url_for('user.profile')) else: flash('Password change was unsuccessful.', 'danger') return redirect(url_for('user.profile')) else: flash('You can now change your password.', 'success') return render_template('user/forgot_new.html', form=form) else: flash('Can not reset the password, try again.', 'danger') return redirect(url_for('main.home'))
def password_change(request): user = request.user if request.method == 'POST': form = ChangePasswordForm(request.POST, user) if form.is_valid(): old_password = form.cleaned_data.get('old_password') new_password = form.cleaned_data.get('new_password') confirm_password = form.cleaned_data.get('confirm_password') if not user.check_password(old_password): messages.error(request, 'Oops! Your old password was entered incorrectly.') return redirect('user:change-password') elif new_password != confirm_password: messages.error(request, 'Oops! Your passwords do not match.') return redirect('user:change-password') else: user.set_password(new_password) user.save() update_session_auth_hash(request, user) messages.success(request, 'Congratulations! Your password was changes successfully.') return redirect('post:home') else: form = ChangePasswordForm(instance=user) context = {'title':'Change Password', 'form':form} return render(request, 'change-password.html', context)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.validate_password(form.old_password.data): current_user.set_password(form.password.data) db.session.commit() flash('Password updated.', 'success') return redirect(url_for('.index', username=current_user.username)) else: flash('Old password is incorrect.', 'warning') return render_template('user/settings/change_password.html', form=form)
def profile(): form = ChangePasswordForm(request.form) if form.validate_on_submit(): user = User.query.filter_by(email=current_user.email).first() if user: user.password = bcrypt.generate_password_hash(form.password.data) db.session.commit() flash('Password successfully changed.', 'success') return redirect(url_for('user.profile')) else: flash('Password change was unsuccessful.', 'danger') return redirect(url_for('user.profile')) return render_template('user/profile.html', form=form)
def change_password(request): data = {} password_form = ChangePasswordForm(request.POST, user=request.user) if password_form.is_valid(): user = request.user new_password = password_form.cleaned_data['new_password'] user.set_password(new_password) user.save() auth.logout(request) data['status'] = 'SUCCESS' else: data['status'] = 'ERROR' data['errors'] = password_form.errors return JsonResponse(data)
def get(self, request, *args, **kwargs): if 'password' in request.GET and 'phone' in request.GET: try: user = User.objects.get(phone=request.GET['phone']) password = PassCode.objects.get(code=request.GET['password']) if request.GET['password'] == password.code: user.backend = 'django.contrib.auth.backends.ModelBackend' auth.login(request, user) if not user.verified: user.verified = True user.save() return redirect('/user/change-password') else: raise Http404('Не сошлись данные пароля') except Exception: raise Http404('Не сошлись данные') if request.user.is_authenticated: context = {} context['title'] = 'Смена пароля' context['form'] = ChangePasswordForm() if 'result' in context: del context['result'] return render(request, 'user/%s/change-password.html' % request.folder, context) else: return redirect('/')
def personal_info(request): context = {} bind_form = BindEmailForm() password_form = ChangePasswordForm() context['bind_form'] = bind_form context['password_form'] = password_form return render(request, 'presonal_info.html', context)
def ChangePassword(request): user = request.user if request.method == 'POST': form = ChangePasswordForm(request.POST) if form.is_valid(): new_password = form.cleaned_data.get('new_password') user.set_password(new_password) user.save() update_session_auth_hash(request, user) return redirect('change-password-done') else: form = ChangePasswordForm(instance=user) context = { 'form': form, } return render(request, 'auth/change_password.html', context)
def post(self, request, *arg, **kwargs): user = request.user form = ChangePasswordForm(request.POST) if form.is_valid(): if form.check_password(user): user.set_password(form.cleaned_data["password2"]) user.password_date = date.today() user.save() logout(request) return HttpResponseRedirect(reverse("user:login")) else: password_error = "Incorrect Old Password" else: password_error = "Password and Confirm Password Should be Same." return render(request, self.template_name, { "form": form, 'password_error': password_error })
def change_password(request): redirect_to = reverse('home') if request.method == 'POST': form = ChangePasswordForm(request.POST,user=request.user) if form.is_valid(): user = request.user new_passwrod = form.cleaned_data['new_password'] user.set_password(new_passwrod) user.save() auth.login(request, user) return redirect(redirect_to) else: form = ChangePasswordForm() context = {} context['page_title'] = '修改密码' context['form_title'] = '修改密码' context['submit_text'] = '修改' context['return_back_url'] = redirect_to context['form'] = form return render(request,'form.html',context)
def change_password(request): redirect_to = request.GET.get('from', reverse('home')) content = {} if request.method == 'POST': forgot_password_form = ChangePasswordForm(request.POST, user=request.user) if forgot_password_form.is_valid(): user = request.user password_new = forgot_password_form.cleaned_data['password_new'] user.set_password(password_new) user.save() auth.logout(request) return redirect(reverse('login')) else: change_password_form = ChangePasswordForm() content['form'] = change_password_form content['page_title'] = '修改密码' content['form_title'] = "修改密码" content['submit_text'] = '修改' content['return_back_url'] = redirect_to return render(request, 'user/change_password.html', content)
def change_password(request): redirect_to = reverse('home') if request.method == 'POST': form = ChangePasswordForm(request.POST,user=request.user) if form.is_valid(): new_password = form.cleaned_data['new_password'] old_password = form.cleaned_data['old_password'] user =request.user user.set_password(new_password) user.save() auth.logout(request) return redirect(redirect_to) else: form = ChangePasswordForm() context = { 'forms': form, 'page_title': '修改密码', 'form_title': '修改密码', 'submit_text': '修改', 'return_back_url': redirect_to } return render(request, 'form.html', context=context)
def change_password(request): redirect_to = request.GET.get('from', reverse('home')) if request.method == 'POST': form = ChangePasswordForm(request.POST, user=request.user) if form.is_valid(): password = form.cleaned_data['password'] user = User.objects.get(username=request.user.username) user.set_password(password) user.save() return redirect(redirect_to) else: form = ChangePasswordForm() context = { 'page_title': '修改密码', 'form_title': '修改密码', 'submit_text': '修改', 'form': form, 'return_back_url': redirect_to, } return render(request, 'form.html', context=context)
def change_password(request): redirect_to = request.GET.get('from', reverse('home')) if request.method == 'POST': form = ChangePasswordForm(request.POST, user=request.user) if form.is_valid(): user = request.user new_password = form.cleaned_data.get('new_password') user.set_password(new_password) user.save() # 修改密码成功,登出系统 auth.logout(request) return redirect(redirect_to) else: form = ChangePasswordForm() context = { 'page_title': '修改密码', 'form_title': '修改密码', 'submit_text': '修改', 'form': form, 'return_back_url': redirect_to } return render(request, 'form.html', context)
def post(self, request, *args, **kwargs): if request.user.is_authenticated: context = {} context['title'] = _('Смена пароля') context['form'] = ChangePasswordForm(request.POST) if context['form'].is_valid(): user = request.user user.set_password(context['form'].cleaned_data['password1']) user.save() user.backend = 'django.contrib.auth.backends.ModelBackend' auth.login(request, user) context['form'] = False context['result'] = _('Пароль изменен успешно.') return render(request, 'user/%s/change-password.html' % request.folder, context) else: return redirect('/')
def get(self, request, *arg, **kwargs): form = ChangePasswordForm() return render(request, self.template_name, {"form": form})