def update_profile(request): if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) profile_form = ProfileForm(request.POST, instance=request.user.profile) signup_form = SignUpForm(instance=request.user) print(signup_form) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return redirect('dashboard') else: return render( request, 'settings.html', { 'user_form': user_form, 'profile_form': profile_form, 'signup_form': signup_form, }) else: user_form = UserForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) signup_form = SignUpForm(instance=request.user) print('This is what you got') print(signup_form) return render( request, 'settings.html', { 'user_form': user_form, 'profile_form': profile_form, 'signup_form': signup_form, })
def test_user_signup_form_is_valid(self): signup_form = { 'username': '******', 'first_name': 'Test', 'last_name': 'User', 'email': '*****@*****.**', 'password1': 'testpassword12', 'password2': 'testpassword12', } form = SignUpForm(data=signup_form) self.assertTrue(form.is_valid())
def test_signup_form_adds_user(self): signup_form = { 'username': '******', 'first_name': 'Test', 'last_name': 'User', 'email': '*****@*****.**', 'password1': 'testpassword12', 'password2': 'testpassword12', } form = SignUpForm(data=signup_form) self.assertTrue(form.is_valid()) self.client.post(reverse('login:signup'), signup_form, follow=True) self.assertEqual(len(User.objects.all()), 1)
def signup(request): #use case: Sign Up message = "" # help messages for user if request.method == 'POST': form = SignUpForm(request.POST) # get form filled by user if form.is_valid(): # django validations username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') email = form.cleaned_data.get('email') form.save() user = authenticate(username=username, password=raw_password) score = Scores(user=user, problem1_status="not solved", problem2_status="not solved", problem3_status="not solved", score=0.00) score.save() login(request, user) return redirect('/') else: print("form not valid") message = form.errors # gather error messages to show to user form = SignUpForm() return render(request, 'registration/signup.html', { 'form': form, 'message': message })
def signup(request): message = "" # help messages for user if request.method == 'POST': form = SignUpForm(request.POST) # get form filled by user if form.is_valid(): # django validations username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') email = form.cleaned_data.get('email') if isEmailValid(email): #verify this email is not already in use form.save() # save new user newUser = User.objects.filter(username = username, email = email)[0] sp = Savings_Percentage(user = newUser) sp.save() #create new register for this new user regarding her/his desired saving amount #saving = Savings(user = newUser, month=datetime.now().month, year=datetime.now().year) #saving.save() # create new register for new user in which we will know how much is she/he saving return redirect('../login/') else: message = "not valid email" else: print("form not valid") message = form.errors # gather error messages to show to user form = SignUpForm() return render(request, 'registration/signup.html',{'form': form, 'message': message})
def update_profile(request): if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) profile_form = ProfileForm(request.POST, instance=request.user.profile) signup_form = SignUpForm(instance=request.user) current_profile = Profile.objects.filter(pk=request.user.id)[0] print('CHECK =', request.FILES) if 'myfile' in request.FILES and request.FILES['myfile']: myfile = request.FILES['myfile'] fs = FileSystemStorage() filename = fs.save( myfile.name + '-' + datetime.datetime.now().isoformat(), myfile) uploaded_file_url = fs.url(filename) user = User.objects.filter(pk=request.user.id) current_profile = Profile.objects.get(user=user) current_profile.image = uploaded_file_url current_profile.save() print('UPDATED =', uploaded_file_url) return render(request, 'profile.html', {}) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return redirect('settings') else: return render( request, 'settings.html', { 'user_form': user_form, 'signup_form': signup_form, 'profile': current_profile, }) else: user_form = UserForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) signup_form = SignUpForm(instance=request.user) current_profile = Profile.objects.filter(pk=request.user.id)[0] return render( request, 'settings.html', { 'user_form': user_form, 'signup_form': signup_form, 'profile': current_profile })
def signin(request): username = request.POST.get('username', False) password = request.POST.get('password', False) user = authenticate(username=username, password=password) if user is not None and user.is_active: login(request, user) return HttpResponseRedirect('home') else: form = SignUpForm() return render(request, 'signin.html', {'form': form})
def signup(request): form = SignUpForm() registered = False if request.method == 'POST': form = SignUpForm(data=request.POST) if form.is_valid(): form.save() registered = True dict = {'form': form, 'registered': registered} return render(request, 'login/signup.html', context=dict)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) form2 = PhoneDetailsForm(request.POST) if form.is_valid(): ''' Begin reCAPTCHA validation ''' recaptcha_response = request.POST.get('g-recaptcha-response') url = 'https://www.google.com/recaptcha/api/siteverify' values = { 'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY, 'response': recaptcha_response } data = urllib.parse.urlencode(values).encode() req = urllib.request.Request(url, data=data) response = urllib.request.urlopen(req) result = json.loads(response.read().decode()) ''' End reCAPTCHA validation ''' if result['success']: print("Success") form.save() phone = form2.save(commit=False) phone.username = form.cleaned_data['username'] phone.save() 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: messages.error(request, 'Invalid reCAPTCHA. Please try again.', extra_tags='safe') else: form = SignUpForm() form2 = PhoneDetailsForm() return render(request, 'signup.html', {'form': form, 'form2': form2})
def create_user(): form = SignUpForm() if request.method == 'POST': new_user = User( username=request.form.get('username'), email=request.form.get('email'), password=bcrypt.generate_password_hash( request.form.get('password')), ) db.session.add(new_user) db.session.commit() return redirect('/') return render_template('signup.html', form=form)
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('login') else: form = SignUpForm() return render(request, "signup.html", {'form': form})
def signUpRequest(request): message = "" if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') email = form.cleaned_data.get('email') if isEmailValid(email): form.save() return redirect('../login/') else: message = "not valid email" else: print("form not valid") message = form.errors form = SignUpForm() return render(request, 'registration/registro.html',{'form': form, 'message': message})
def registrar_participante(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user = form.save() user.refresh_from_db() # load the profile instance created by the signal user.profile.birth_date = form.cleaned_data.get('birth_date') user.save() raw_password = form.cleaned_data.get('password1') user = authenticate(username=user.username, password=raw_password) login(request, user) return redirect('participantes') else: form = SignUpForm() return render(request, 'signup.html', {'form': form})
def signup(request): if 'UserName' in request.session: return redirect("/") else: form = SignUpForm() if request.method == "POST": form = SignUpForm(request.POST) password = request.POST.get("Password") confirmPassword = request.POST.get("ConfirmPassword") if password == confirmPassword: if form.is_valid(): form.save(commit=True) return redirect("login") else: return render(request, 'login/signup.html', { 'form': form, 'msg': "Passwords does not match" }) return render(request, 'login/signup.html', {'form': form})
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( '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 signup(request): if request.user.is_anonymous(): if request.method == "POST": signupForm = SignUpForm(request.POST) if signupForm.is_valid(): signupForm = signupForm.clean() userName = signupForm['username'] userMail = signupForm['email'] password = signupForm['password'] user = User.objects.create_user(userName, userMail, password) user.save() login(request) messages.success(request, "User account created succesfully") return HttpResponseRedirect('/home') else: messages.error(request, "Please check the entered form") else: signupForm = SignUpForm() return render(request, "login/signup.html", {"signupForm": signupForm}) else: return HttpResponseRedirect("/home/")
def test_signup_form_invalid(self): form = SignUpForm(data={}) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 4)