def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) login(request, user) return redirect('home') else: form = SignUpForm() return render(request, 'register/signup.html', {'form': form})
def get_form(self, request): """ Return the SignUp form. If incoming request is POST then load form with POST data. :param: request: incoming Http request :type request: django.http.HttpRequest :return: the SignUpForm :rtype: register.forms.signup.SignUpForm """ if request.method.upper() == 'POST': return SignUpForm(data=request.POST) return SignUpForm()
def register(request): if request.method == "POST": form = SignUpForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = authenticate(request, username = username, password = password) login(request, user) return redirect('/home') else: form = SignUpForm() context = { "form": form } return render(request, 'register/signin.html', context)
def test_form_email_exists(self): form = SignUpForm(self.user_email_exists) form.has_error( "email", "This Email is already registered. " "Please use a different email address.", )
def signup_view(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') messages.success(request, f'account created for {username}') user = authenticate(username=username, password=raw_password) login(request, user, backend='django.contrib.auth.backends.ModelBackend') return redirect('reg-profile') else: form = SignUpForm() context = {'form': form, 'title': 'Sign up', "terms": "terms"} return render(request, 'signup.html', context)
def show_profile(request, pk): if not request.user.is_authenticated: form = SignUpForm() return render(request, 'login/login.html', context={'form': form}) curr_us = get_object_or_404(User, id=pk) profile = get_object_or_404(Profile, user=curr_us) if request.user == curr_us: return render(request, 'profile/ur_profile.html', context={'profile': profile}) else: return render(request, 'profile/not_ur_profile.html', context={'profile': profile, 'pk': pk})
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('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, 'signup.html', {'form': form})
def get(self, request): if not request.user.is_authenticated: form = SignUpForm() return render(request, 'login/login.html', context={'form': form}) form = PostForm() return render(request, 'posts/create.html', context={'form': form})
def get(self, request): if not request.user.is_authenticated: form = SignUpForm() return render(request, 'login/login.html', context={'form': form}) form = ProfileRedactForm() return render(request, 'profile/ur_profile_redact.html', context={'form': form})
def test_form_dob_valid(self): form = SignUpForm(self.user) self.assertTrue(form.is_valid())
def test_form_dob_invalid_future(self): form = SignUpForm(self.user_invalid_dob_future) form.has_error( "dob", "Invalid Date of Birth", )
def test_form_username_exists(self): form = SignUpForm(self.user_name_exists) form.has_error("username", "A user with that username already exists.")
def test_form_not_valid(self): form = SignUpForm(self.user_no_username) self.assertFalse(form.is_valid())