def login_signup(request, signup=False): if request.method == 'POST': if signup: form = SignUpForm(data=request.POST) error = None if form.is_valid(): try: user = User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['username'], form.cleaned_data['password']) except: error = "Can't create user. Try another email and(or) password." else: login(request, user) return redirect(reverse('home')) return render(request, 'polls/login.html', { 'signup_form': form, 'error': error, 'signup': True, }) else: form = LoginForm(data=request.POST) if form.is_valid(): user = authenticate(request, **form.cleaned_data) if user: login(request, user) return redirect(reverse('home')) return render(request, 'polls/login.html', { 'login_form': form, 'error': 'Incorrect user name or password', }) else: return render(request, 'polls/login.html')
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() return redirect('/polls') else: form = SignUpForm() args = {'form': form} return render(request, 'polls/signup_form.html', args)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save() user.refresh_from_db() user.profile.primeiro_nome = form.cleaned_data.get('primeiro_nome') user.save() user.profile.ultimo_nome = form.cleaned_data.get('ultimo_nome') user.save() #user.profile.ID = form.cleaned_data.get('ID') #user.save() user.profile.email = form.cleaned_data.get('email') user.save() #user.User.password = form.cleaned_data.get('password') #user.save() user.profile.telefone = form.cleaned_data.get('telefone') user.save() user.profile.nome_aparelho = form.cleaned_data.get('nome_aparelho') user.save() raw_password = form.cleaned_data.get('password1') user = authenticate(username=user.username,password=raw_password) login(request,user) return redirect('minhaconta') else: form = SignUpForm() return render (request, 'signup.html', {'form':form})
def signup(request): # Returns the path, plus an appended query string, if applicable. Example: "/music/bands/the_beatles/?print=true" path = request.get_full_path() if request.method == 'POST': form = SignUpForm(data=request.POST, auto_id="%s") if form.is_valid(): UserModel = get_user_model() username = form.cleaned_data['username'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] user = UserModel.objects.create_user(username=username, email=email, password=password) user.save() auth_user = authenticate(username=username, password=password) auth_login(request, auth_user) return redirect("index") else: print("666") else: form = SignUpForm(auto_id="%s") return render(request, 'sign_up.html', locals())
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('/') else: return render(request, 'user_register.html', {'form': form}) else: cat = Category.objects.all form = SignUpForm() return render(request, 'user_register.html', { 'form': form, 'category': cat })
def signup(request): global logged_in, user if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() first_name = form.cleaned_data.get('first_name') last_name = form.cleaned_data.get('last_name') username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = authenticate(first_name=first_name, last_name=last_name, username=username, password=raw_password) logged_in = True login(request, user) return redirect('home') else: error = "" if 'password2' in form.errors.as_data(): error = list(form.errors.as_data()['password2'][0])[0] elif 'username' in form.errors.as_data(): error = list(form.errors.as_data()['username'][0])[0] return render(request, 'signup.html', {'form': form, 'logged_in': logged_in, 'error': error}) else: form = SignUpForm() return render(request, 'signup.html', {'form': form, 'logged_in': logged_in, 'error': "nothing"})
def test_sign_up_form_first_name_field_validation(self): form = SignUpForm() self.assertTrue(form.fields['first_name'].required)
def test_sign_up_form_first_name_field_label(self): form = SignUpForm() self.assertTrue(form.fields['first_name'].label == None or form.fields['first_name'].label == 'First Name')