def sign_up(request): context = { 'form': UserRegisterForm(), 'icon_message': 'success', 'title_message': 'Great' } if request.method == 'POST': data_form = UserRegisterForm(data=request.POST) if data_form.is_valid(): data_form.save() # loguear automaticamente con datos del formulario user = authenticate( username=data_form.cleaned_data['username'], password=data_form.cleaned_data['password1'] ) login(request, user) # redireccionar al home luego de un mensaje messages.success( request, "you have registered successfully!" ) return redirect(to='home') context['form'] = data_form return render(request, 'registration/sign_up.html', context)
def registerCheck(request): uf = UserRegisterForm(request.POST) if uf.is_valid(): uf.save() messages.success(request, 'Successfully Registered') return redirect('registerForm') else: messages.error(request, uf.errors) return render(request, 'registerForm.html', {'RegForm': uf})
def register(request): if request.user.is_authenticated: return redirect('/') if request.method == 'POST': form = UserRegisterForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') messages.success( request, f'Your account {username} has been created. Login now!') return redirect('login') else: form = UserRegisterForm() return render(request, 'register.html', {'form': form})
def register(request): """ View for register returns register.html template """ if not request.user.is_authenticated(): context_dict={} if request.method == 'POST': user_form = UserRegisterForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=False) user.set_password(user.password) user.is_staff=True profile = profile_form.save(commit=False) user.save() profile.user = user profile.save() return HttpResponseRedirect(settings.REGISTER_REDIRECT_UTL) else: print user_form.errors print profile_form.errors context_dict["error1"] = user_form.errors context_dict["error2"] = user_form.errors else: user_form = UserRegisterForm() profile_form = UserProfileForm() context_dict["user_form"]=user_form context_dict["profile_form"]=profile_form return render(request, 'app/register.html',context_dict ) else : return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
def register_view(request): print(request.user.is_authenticated()) form = UserRegisterForm(request.POST, request.FILES or None) if form.is_valid(): user = form.save(commit=False) password = form.cleaned_data.get('password') im = form.cleaned_data.get('image') user.set_password(password) user.save() new_user = authenticate(username=user.username, password=password) login(request, new_user) return render(request, 'register_sucessfull.html', {}) context = { "form": form, } return render(request, 'register.html', context)
def register_view(request): next = request.GET.get('next') form = UserRegisterForm(request.POST or None) if form.is_valid(): user = form.save(request) password = form.cleaned_data.get('password') password = make_password(form.cleaned_data.get('password')) user.set_password(password) user.save() new_user = authenticate(username=user.username, password=password) login(request, new_user) if next: return redirect(next) return redirect('/') context = { 'form': form, } return render(request, "signup.html", context)
def post(self, request): register_form = UserRegisterForm(request.POST) if register_form.is_valid(): user = register_form.save() user.is_active = False user.set_password(request.POST['password1']) user.save() uid = urlsafe_base64_encode(force_bytes(user.pk)) activate_url = "{}/{}/{}".format( "http://localhost:8000/activate", uid, default_token_generator.make_token(user=user) ) send_email( recipient_list=[user.email], activate_url=activate_url ) return HttpResponse("Check your email list to activate account!") return HttpResponse("Wrong Data")