def base_view(request): context = {} users = User.objects.all() current_page = Paginator(users, 5) page = request.GET.get('page') try: users = current_page.page(page) except PageNotAnInteger: users = current_page.page(1) except EmptyPage: users = current_page.page(current_page.num_pages) form = NewUserForm(request.POST or None) if form.is_valid(): full_name = form.cleaned_data['full_name'] birth_day = form.cleaned_data['birth_day'] phone = form.cleaned_data['phone'] middle_name = form.cleaned_data['middle_name'] email = form.cleaned_data['email'] User.objects.create( full_name=full_name, birth_day=birth_day, phone=phone, middle_name=middle_name, email=email) return HttpResponseRedirect(reverse('base')) context = { 'users': users, 'form': form } return render(request, 'base.html', context)
def createUser(request): """Method for to sign up in the platform""" logout(request) if request.method == "POST": form = NewUserForm(request.POST) if form.is_valid(): nickName = form.cleaned_data['nickname'] emailUser = form.cleaned_data['emailUser'] passUser = form.cleaned_data['passUser'] user = User.objects.create_user(nickName, emailUser, passUser) return render_to_response("profile.html", {'user': user}, context_instance=RC(request))
def createUser(request): """Method for to sign up in the platform""" logout(request) if request.method == "POST": form = NewUserForm(request.POST) if form.is_valid(): nickName = form.cleaned_data['nickname'] emailUser = form.cleaned_data['emailUser'] passUser = form.cleaned_data['passUser'] user = User.objects.create_user(nickName, emailUser, passUser) return render_to_response("profile.html", {'user': user}, context_instance=RC(request))
def join(room_code): room = Room.query.filter_by(code=room_code).first_or_404() new_user_form = NewUserForm() if new_user_form.validate_on_submit(): user = User(name=new_user_form.name.data, room_code=room_code) db.session.commit() login_user(user) flash(f"Joined {room.name}") return redirect(url_for('member_view', room_code=room.code)) return render_template('join.html', title='Join room', room=room, form=new_user_form)
def test_cant_create_two_accounts_with_same_user(self): user_data = { 'name': fake.name(), 'username': '******', 'password': '******', 'email': fake.safe_email() } response = self.client.post(reverse('log-in'), data=user_data) self.assertEqual(302, response.status_code) form = NewUserForm(data=user_data) self.assertFalse(form.is_valid()) self.assertTrue(form.has_error('username', USER_EXISTS_ERROR_CODE))
def register(): form = NewUserForm() if form.validate_on_submit() and request.method == 'POST': user = UserProfile(request.form['email'], request.form['firstname'], request.form['lastname'], request.form['username'], request.form['password'], "", "", "") db.session.add(user) db.session.commit() access_token = create_access_token(identity=request.form['username']) return jsonify({ 'authenticated': True, 'access_token': access_token }), 200 return jsonify(response=form_errors(form))
def other(request): form = NewUserForm() if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): form.save(commit=True) return home(request) return render(request, 'other.html', {'form': form})
def users(request): form = NewUserForm() if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): form.save(commit=True) return index(request) return render(request, 'form.html', {'form': form})
def signup_users(request): form = NewUserForm() if request.method == "POST": form = NewUserForm(request.POST) if form.is_valid(): form.save(commit=True) # this will save the form return index(request) # this will returns are to the index page return render(request, 'app/signup.html', {'form': form})
def addUser(request): if request.method == 'POST': Users = User.objects.all() form = NewUserForm(request.POST) if form.is_valid(): form.save() # render Home Page assert isinstance(request, HttpRequest) return render(request, 'app/home.html', { 'title': 'Home Page', 'year': datetime.now().year, }) else: assert isinstance(request, HttpRequest) return render(request, 'app/newUser.html', { 'title': 'New User', 'year': datetime.now().year, 'user': User() })
def user(request): form = NewUserForm() if (request.method == "POST"): form = NewUserForm(request.POST) if (form.is_valid()): form.save(commit=True) return index(request) else: print("something went wrong") return render(request, 'app/abc.html', {'form': form})
def users(request): form = NewUserForm() if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): print("Password:" + form.cleaned_data['password']) form.save(commit=True) return end(request) return render(request, 'form.html', {'form': form})
def save_model(request): if request.method == "POST": form = NewModelForm(request.POST) if form.is_valid(): user = form.save() login(request, user) messages.success(request, "Registration successful.") return redirect("/list_diagram") messages.error(request, "Unsuccessful registration. Invalid information.") form = NewUserForm() return render(request=request, template_name="save_model.html", context={"register_form": form})
def test_new_form_middle_name_field_label(self): form = NewUserForm() self.assertTrue(form.fields['middle_name'].label == 'Отчество')
def test_new_form_name_field_label(self): form = NewUserForm() self.assertTrue(form.fields['full_name'].label == 'Имя и фамилия')
def test_new_form_birth_day_field_label(self): form = NewUserForm() self.assertTrue(form.fields['birth_day'].label == 'Дата рождения')
def signup(): signup_form = NewUserForm() dates = { 'signup_form': signup_form, } if request.method == 'POST': email = request.form['email'].encode('utf8') username = request.form['username'].encode('utf8') passwd = request.form['password'].encode('utf8') confirmation = request.form['password_confirmation'].encode('utf8') user_validate = user_data_by_email(id_user=email) if user_validate is None: if validate_email(email, verify=True): if len(username.split('.')) > 1 and len( username.split('.')) < 3: alphanumeric = passwd.isalnum() # True alphabetic = passwd.isalpha() # False numeric = passwd.isdigit() # False lower = passwd.islower() # False upper = passwd.isupper() # False if alphanumeric and not alphabetic and not numeric and not lower and not upper: if passwd == confirmation: passwd_db = generate_password_hash(passwd) user_dates = Users(user_name=username, password=passwd_db, init_date=str( datetime.now().date()), email=email), user_dates = user_dates[0] signup_user(user_dates) validate = user_data_by_email(id_user=email) email_message(username, email, passwd) dates_usu = UserDates(id=validate.id, user_name=validate.user_name, password=validate.password, init_date=validate.init_date, email=validate.email) user = ModelUser(dates_usu) login_user(user) Config.SECRET_KEY = passwd session['username'] = username flash('User logged in successfully. Welcome {}'. format(username)) return redirect(url_for('Home')) else: flash('Signup failed.'.decode('utf8')) flash('Passwords do not match.'.decode('utf8')) else: flash('Signup failed.'.decode('utf8')) flash('Invalid password'.decode('utf8')) else: flash('Signup failed.'.decode('utf8')) flash('Invalid username'.decode('utf8')) else: flash('Signup failed.'.decode('utf8')) flash('No email exists.'.decode('utf8')) else: flash('User already exists.') return render_template('signup.html', **dates)
def test_new_form_phone_field_help_text(self): form = NewUserForm() self.assertTrue(form.fields['phone'].help_text == 'Формат: +375(ХХ)ХХХ-ХХ-ХХ')
def test_new_form_phone_field_initial(self): form = NewUserForm() self.assertTrue(form.fields['phone'].initial == '+375()--')
def test_new_form_phone_field_label(self): form = NewUserForm() self.assertTrue(form.fields['phone'].label == 'Номер телефона')