def signup(self): form = SignupForm() if request.method == 'POST': if not form.validate_on_submit(): flash_error(form.errors) 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 = User.generate_password_hash(form.password.data) 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)
#!/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()