def test_user_model(self): user = PortalUser(email="*****@*****.**", first_name="Test", last_name="User") user.save() assert PortalUser.find_by_email("*****@*****.**") assert PortalUser.find_by_key(ObjectId()) == None
def save_user(): needs_password = '******' in request.form if needs_password: form = NewUserForm(request.form) else: form = UserForm(request.form) if form.validate(): email = form.email.data if form.id.data: user = PortalUser.find_by_key(form.id.data) else: user = PortalUser.find_by_email(email) if not user: user = PortalUser(email=email) form.populate_obj(user) if 'password' in request.form: user.set_password(form.password.data) user.save() return redirect(url_for('list_users')) else: return render_template('user_detail.html', form=form, needs_password=needs_password)