def remove_entry(us: User, mid: str): for entry in us.entries: if str(entry.id) == mid: us.entries.remove(entry) us.save() break __remove_from_scheduler(mid)
def signup(self): form = SignupForm() if request.method == 'POST': if not form.validate_on_submit(): return render_template('home/register.html', form=form) email = form.email.data if not is_valid_email(email, False): flash_error(gettext(u'Invalid email.')) return render_template('home/register.html', form=form) existing_user = User.objects(email=email).first() if existing_user: return redirect(url_for('HomeView:signin')) hash_pass = generate_password_hash(form.password.data, method='sha256') new_user = User(email=email, password=hash_pass) new_user.save() token = self._confirm_link_generator.dumps(email, salt=HomeView.SALT_LINK) confirm_url = url_for('HomeView:confirm_email', token=token, _external=True) config = app.config['PUBLIC_CONFIG'] html = render_template( 'home/email/activate.html', confirm_url=confirm_url, contact_email=config['support']['contact_email'], title=config['site']['title'], company=config['company']['title']) msg = Message(subject=gettext(u'Confirm Email'), recipients=[email], html=html) mail.send(msg) flash_success(gettext(u'Please check email: {0}.'.format(email))) return redirect(url_for('HomeView:signin')) return render_template('home/register.html', form=form)
def __add_to_scheduler_pending_entry(us: User, entry: MoneyEntry): if entry.state == MoneyEntry.State.PENDING: __add_to_scheduler(us.id, entry) return assert (entry.state == MoneyEntry.State.APPROVED ), "Entry state should be APPROVED!" rel = __relativedelta_from_recurring(entry.recurring) if not rel: return date = entry.date + rel if date < datetime.now(): return cloned = entry.clone() cloned.date = date cloned.state = MoneyEntry.State.PENDING us.entries.append(cloned) us.save() __add_to_scheduler(us.id, cloned)
#!/usr/bin/env python3 import argparse import os import sys from mongoengine import connect sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from app.home.user_loging_manager import User PROJECT_NAME = 'test_life' if __name__ == '__main__': parser = argparse.ArgumentParser(prog=PROJECT_NAME, usage='%(prog)s [options]') parser.add_argument('--mongo_uri', help='MongoDB credentials', default='mongodb://localhost:27017/iptv') parser.add_argument('--email', help='User email') parser.add_argument('--password', help='User password') argv = parser.parse_args() mongo = connect(argv.mongo_uri) if mongo: hash_pass = User.generate_password_hash(argv.password) new_user = User(email=argv.email, password=hash_pass) new_user.status = User.Status.ACTIVE new_user.save()
def add_entry(us: User, entry: MoneyEntry): us.entries.append(entry) us.save() __add_to_scheduler_pending_entry(us, entry)