def signup_view(request): form = SignUpForm() if request.method == 'POST': form = SignUpForm(request.POST) user = form.save() user.set_password(user.password) user.save() return HttpResponseRedirect('/accounts/login') return render(request, 'authapp/signup.html', {'form': form})
def register(request): title = 'Регистрация' if request.user.is_authenticated: if request.user.is_staff: return HttpResponseRedirect( reverse("staff_profile", kwargs={'page': 1})) else: return HttpResponseRedirect( reverse('bids_list_work', kwargs={ 'pk': request.user.pk, 'page': 1 })) if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): account = form.save() account.save() username = request.POST['username'] password = request.POST['password1'] user = auth.authenticate(username=username, password=password) if user.is_superuser: reverse_lazy('admin') auth.login(request, user) send_mail( '{}'.format(title), 'Пользователь с почтой {} и номером {} зарегистрировался'. format(username, request.POST['telephone_num']), settings.EMAIL_HOST_USER, [settings.EMAIL_HOST_USER], fail_silently=False, ) return HttpResponseRedirect( reverse('create', kwargs={'pk': request.user.pk})) else: content = {'title': title, 'form': form} return render(request, 'authapp/index.html', content) else: form = SignUpForm() content = {'title': title, 'form': form} return render(request, 'authapp/index.html', content)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save(commit=False) user.is_active = False user.save() current_site = get_current_site(request) subject = 'Activate Your MySite Account' message = render_to_string( 'authapp/account_activation_email.html', { 'user': user, 'domain': current_site.domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user), }) user.email_user(subject, message) return redirect('account_activation_sent') else: form = SignUpForm() return render(request, 'authapp/signup.html', {'form': form})