def confirm_email(request): args = {} if request.method == "GET" and 'key' in request.GET and 'user' in request.GET: try: user = get_user_model().objects.get(username=request.GET["user"]) user.backend = 'django.contrib.auth.backends.ModelBackend' if not user.is_confirmed: user.confirm_email(request.GET["key"]) system_auth(request, user) return redirect(password_change) else: raise Http404("Wrong data, reject request") except: raise Http404("Wrong data, reject request") else: raise Http404("Wrong data, reject request")
def password_reset_confirm(request, uidb64=None, token=None, template_name='account/auth.html', token_generator=default_token_generator, set_password_form=SetPasswordForm, current_app=None, extra_context=None): """ View that checks the hash in a password reset link and presents a form for entering a new password. """ UserModel = get_user_model() assert uidb64 is not None and token is not None # checked by URLconf try: # urlsafe_base64_decode() decodes to bytestring on Python 3 uid = force_text(urlsafe_base64_decode(uidb64)) user = UserModel._default_manager.get(pk=uid) except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist): user = None if user is not None and token_generator.check_token(user, token): validlink = True if request.method == 'POST': form = set_password_form(user, request.POST) if form.is_valid(): form.save() user.backend = 'django.contrib.auth.backends.ModelBackend' system_auth(request, user) return redirect(profile) else: form = set_password_form(user) else: validlink = False form = None return HttpResponse("Password reset unsuccessful, please start process again") context = { 'form': form, 'validlink': validlink, } if extra_context is None: extra_context = {"auth" : False} context.update(extra_context) if current_app is not None: request.current_app = current_app return render_to_response(template_name, context, RequestContext(request))