def test_func_it_works(self): business1 = Business(name='name', password='******', email='email', confirmed=True) business2 = Business(name='name', password='******', email='email', confirmed=True) business2.registered_on -= timedelta(days=32) business3 = Business(name='name', password='******', email='email', confirmed=False) business3.registered_on -= timedelta(days=32) business4 = Business(name='name', password='******', email='email', confirmed=False) db.session.add(business1) db.session.add(business2) db.session.add(business3) db.session.add(business4) db.session.commit() self.assertTrue(Business.it_works(business1.id)) self.assertTrue(Business.it_works(business2.id)) self.assertFalse(Business.it_works(business3.id)) self.assertTrue(Business.it_works(business4.id))
def login_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 = LoginBusinessForm() if form.validate_on_submit(): if Business.check_b(form.email.data, form.password.data): session['id'] = Business.query.filter_by(email=form.email.data).first().id if not Business.it_works(session.get('id', '')): session['id'] = '' form.password.errors = ('Неправильная почта или пароль', '') elif not Business.check_confirmed(session.get('id', '')): return redirect('/business/unconfirmed') else: return redirect(url_for('business.business_card', business_id=session.get('id', ''))) else: form.password.errors = ('Неправильная почта или пароль', '') return render_template('login_business.html', title='Вход бизнеса', form=form)
def forgot_password(): if session.get('id', '') != '': return redirect(url_for('business.business_card', business_id=session.get('id', ''))) session['id_client'] = '' form = ForgotPasswordForm() if form.validate_on_submit(): if Business.query.filter_by(email=form.email.data).first(): id = Business.query.filter_by(email=form.email.data).first().id if Business.it_works(id): new_password = Business.random_password(size=15) rows = Business.query.filter_by(id=id).update({'password': generate_password_hash(new_password)}) db.session.commit() Business.send_password(form.email.data, new_password) return redirect( "/business/feedback/Мы отправили вам новый пароль на почту! Если вы не получили письмо, \ проверьте, что вы написали почту правильно!") else: form.email.errors = ('Неправильная почта', '') else: form.email.errors = ('Неправильная почта', '') return render_template('forgot_password.html', title='Забыли пароль?', form=form)