def test_func_name_is_free(self): business = Business(name='name', password='******', email='email', confirmed=True) business.registered_on -= timedelta(days=32) db.session.add(business) db.session.commit() self.assertTrue(Business.name_is_free('name1')) self.assertFalse(Business.name_is_free('name'))
def registration_business(): if session.get('id', '') != '': if not Business.check_confirmed(session.get('id', '')): session['id'] = '' return redirect(url_for('business.business_card', business_id=session.get('id', ''))) session['id_client'] = '' form = RegistrationBusinessForm(csrf_enabled=False) if form.validate_on_submit(): free_name = Business.name_is_free(form.name.data) free_email = Business.email_is_free(form.email.data) check_pass = (form.password.data == form.check_password.data) password_is_valid = Business.password_is_valid(form.password.data) if free_name and check_pass and password_is_valid and free_email: Business.send_token(form.email.data) business = Business(name=form.name.data, password=form.password.data, email=form.email.data, confirmed=False) Business.save(business) return redirect( "/business/feedback/Регистрация прошла успешно. Пройдите по ссылке, \ которую мы отправили вам на почту, чтобы подтвердить её") elif not free_name: form.name.errors = ('Название занято', '') elif not free_email: form.email.errors = ('Почта занята', '') elif not password_is_valid: form.check_password.errors = ('Пароль не может содержать пробелы', '') elif not check_pass: form.check_password.errors = ('Пароли не совпадают', '') return render_template('registration_business.html', title='Регистрация бизнеса', form=form)
def change_business(): if session.get('id', '') == '': return redirect('/business') if not Business.check_confirmed(session.get('id', '')): return redirect('/business/unconfirmed') changename = "" changepassword = "" form_name = ChangeBusinessNameForm() form_password = ChangeBusinessPasswordForm() id = session.get('id', '') if form_name.submit1.data and form_name.validate_on_submit(): free_name = Business.name_is_free(form_name.new_name.data) b_password = Business.query.filter_by(id=id).first().password b_name = Business.get_name(id) if free_name or b_name == form_name.new_name.data \ and check_password_hash(b_password, form_name.password.data): rows = Business.query.filter_by(id=id).update({'name': form_name.new_name.data}) db.session.commit() if BusinessCard.is_real(session.get('id', '')): rows = BusinessCard.query.filter_by(business_id=session.get('id', '')).update( {'name': form_name.new_name.data}) db.session.commit() changename = "Название было изменено" # return redirect('/change_business') elif not free_name and form_name.new_name.data != b_name: form_name.new_name.errors = ('Название занято', '') elif not check_password_hash(b_password, form_name.password.data): form_name.password.errors = ('Неправильный пароль', '') if form_password.submit2.data and form_password.validate_on_submit(): b_password = Business.query.filter_by(id=id).first().password check_new = form_password.new_password.data == form_password.check_new_password.data check_old = check_password_hash(b_password, form_password.old_password.data) password_is_valid = Business.password_is_valid(form_password.new_password.data) if check_old and check_new and password_is_valid: new_password = generate_password_hash(form_password.new_password.data) rows = Business.query.filter_by(id=id).update({'password': new_password}) db.session.commit() changepassword = "******" # return redirect('/change_business') elif not password_is_valid: form_password.new_password.errors = ('Пароль не может содержать пробелы', '') elif not check_new: form_password.check_new_password.errors = ('Пароли не совпадают', '') elif not check_old: form_password.old_password.errors = ('Неправильный пароль', '') form_name.new_name.data = Business.query.filter_by(id=id).first().name return render_template('change_business.html', title='Изменить настройки бизнеса', form=form_name, p_form=form_password, changename=changename, changepassword=changepassword)