def _create_user_for_api_registration(self, api_user_id): api_registration = ApiRegistrations.query.filter_by( id=api_user_id).one() password = os.urandom(5).encode('hex') kwargs = dict(email=api_registration.email, password=password, active='y') form = ConfirmRegisterForm(MultiDict(kwargs), csrf_enabled=False) u = None # Role with id 4 is an API user r = Role.query.filter_by(id=4).one() if form.validate(): kwargs['password'] = hash_password(kwargs['password']) kwargs['active'] = True u = _datastore.create_user(**kwargs) if _datastore.add_role_to_user(u, r): msg = TemplatedMessage( template_html='scoap3_api/email/confirmed.html', subject='SCOAP3 - Partner registration confirmation', sender=current_app.config.get('MAIL_DEFAULT_SENDER'), recipients=[api_registration.email], ctx={ 'email': api_registration.email, 'password': password, 'recipient': api_registration.name }) current_app.extensions['mail'].send(msg) else: flash('Error creating user. %s' % form.errors, 'error')
def run(self, **kwargs): # handle confirmed if re.sub(r"\s", "", str(kwargs.pop("confirmed"))).lower() in [ "", "y", "yes", "1", "active", ]: kwargs["confirmed_at"] = datetime.datetime.now() # sanitize active input ai = re.sub(r"\s", "", str(kwargs["active"])) kwargs["active"] = ai.lower() in ["", "y", "yes", "1", "active"] from flask_security.forms import ConfirmRegisterForm from werkzeug.datastructures import MultiDict form = ConfirmRegisterForm(MultiDict(kwargs), csrf_enabled=False) if form.validate(): kwargs["password"] = encrypt_password(kwargs["password"]) user_datastore.create_user(**kwargs) print("User created successfully.") kwargs["password"] = "******" pprint(kwargs) else: print("Error creating user") pprint(form.errors)
def run(self, **kwargs): # handle confirmed if re.sub(r'\s', '', str(kwargs.pop('confirmed'))).lower() in [ '', 'y', 'yes', '1', 'active' ]: kwargs['confirmed_at'] = datetime.datetime.now() # sanitize active input ai = re.sub(r'\s', '', str(kwargs['active'])) kwargs['active'] = ai.lower() in ['', 'y', 'yes', '1', 'active'] from flask_security.forms import ConfirmRegisterForm from werkzeug.datastructures import MultiDict form = ConfirmRegisterForm(MultiDict(kwargs), csrf_enabled=False) if form.validate(): kwargs['password'] = encrypt_password(kwargs['password']) user_datastore.create_user(**kwargs) print('User created successfully.') kwargs['password'] = '******' pprint(kwargs) else: print('Error creating user') pprint(form.errors)
def _create_user_for_api_registration(self, api_user_id): api_registration = ApiRegistrations.query.filter_by(id=api_user_id).one() password = os.urandom(5).encode('hex') kwargs = dict(email=api_registration.email, password=password, active='y') form = ConfirmRegisterForm(MultiDict(kwargs), csrf_enabled=False) u = None # Role with id 4 is an API user r = Role.query.filter_by(id=4).one() if form.validate(): kwargs['password'] = hash_password(kwargs['password']) kwargs['active'] = True u = _datastore.create_user(**kwargs) if _datastore.add_role_to_user(u, r): msg = TemplatedMessage(template_html='scoap3_api/email.html', subject='SCOAP3 - API registration confirmation', sender=current_app.config.get('MAIL_DEFAULT_SENDER'), recipients=[api_registration.email], ctx={'email': api_registration.email, 'password': password, 'recipient': api_registration.name }) current_app.extensions['mail'].send(msg) else: flash('Error creating user. %s' % form.errors, 'error')
def test_form_error(app, client, get_message): # A few form validations use ValidatorMixin which provides a lazy string # Since CLI doesn't render_template it was seeing those lazy strings. # This test basically just illustrates all this. from babel.support import LazyProxy with app.test_request_context("/register"): # this is usually done @before_first_request app.jinja_env.globals["_fsdomain"] = app.security.i18n_domain.gettext rform = ConfirmRegisterForm() rform.validate() assert isinstance(rform.errors["email"][0], LazyProxy) assert str(rform.errors["email"][0]).encode("utf-8") == get_message( "EMAIL_NOT_PROVIDED") # make sure rendered template has converted LocalProxy strings. rendered = app.security.render_template( app.config["SECURITY_REGISTER_USER_TEMPLATE"], register_user_form=rform, ) assert get_message("EMAIL_NOT_PROVIDED") in rendered.encode("utf-8")
def users_create(email, password, active): """Create a user.""" kwargs = dict(email=email, password=password, active="y" if active else "") form = ConfirmRegisterForm(MultiDict(kwargs), meta={"csrf": False}) if form.validate(): kwargs["password"] = hash_password(kwargs["password"]) kwargs["active"] = active _datastore.create_user(**kwargs) click.secho("User created successfully.", fg="green") kwargs["password"] = "******" click.echo(kwargs) else: raise click.UsageError("Error creating user. %s" % form.errors)
def users_create(email, password, active): """Create a user.""" kwargs = dict(email=email, password=password, active='y' if active else '') form = ConfirmRegisterForm(MultiDict(kwargs), meta={'csrf': False}) if form.validate(): kwargs['password'] = hash_password(kwargs['password']) kwargs['active'] = active _datastore.create_user(**kwargs) click.secho('User created successfully.', fg='green') kwargs['password'] = '******' click.echo(kwargs) else: raise click.UsageError('Error creating user. %s' % form.errors)
def users_create(email, password, active): """Create a user.""" kwargs = dict(email=email, password=password, active='y' if active else '') form = ConfirmRegisterForm(MultiDict(kwargs), csrf_enabled=False) if form.validate(): kwargs['password'] = hash_password(kwargs['password']) kwargs['active'] = active _datastore.create_user(**kwargs) click.secho('User created successfully.', fg='green') kwargs['password'] = '******' click.echo(kwargs) else: raise click.UsageError('Error creating user. %s' % form.errors)
def run(self, **kwargs): # sanitize active input ai = re.sub(r'\s', '', str(kwargs['active'])) kwargs['active'] = ai.lower() in ['', 'y', 'yes', '1', 'active'] from flask_security.forms import ConfirmRegisterForm from werkzeug.datastructures import MultiDict form = ConfirmRegisterForm(MultiDict(kwargs), csrf_enabled=False) if form.validate(): kwargs['password'] = encrypt_password(kwargs['password']) _datastore.create_user(**kwargs) print 'User created successfully.' kwargs['password'] = '******' pprint(kwargs) else: print 'Error creating user' pprint(form.errors)
def run(self, **kwargs): # sanitize active input ai = re.sub(r'\s', '', str(kwargs['active'])) kwargs['active'] = ai.lower() in ['', 'y', 'yes', '1', 'active'] from flask_security.forms import ConfirmRegisterForm from werkzeug.datastructures import MultiDict form = ConfirmRegisterForm(MultiDict(kwargs), meta={'csrf': False}) if form.validate(): kwargs['password'] = hash_password(kwargs['password']) _datastore.create_user(**kwargs) print('User created successfully.') kwargs['password'] = '******' pprint(kwargs) else: print('Error creating user') pprint(form.errors)
def run(self, **kwargs): # sanitize active input ai = re.sub(r"\s", "", str(kwargs["active"])) kwargs["active"] = ai.lower() in ["", "y", "yes", "1", "active"] from flask_security.forms import ConfirmRegisterForm from werkzeug.datastructures import MultiDict form = ConfirmRegisterForm(MultiDict(kwargs), meta={"csrf": False}) if form.validate(): kwargs["password"] = hash_password(kwargs["password"]) _datastore.create_user(**kwargs) print("User created successfully.") kwargs["password"] = "******" pprint(kwargs) else: print("Error creating user") pprint(form.errors)
def run(self, **kwargs): # sanitize active input ai = re.sub(r'\s', '', str(kwargs['active'])) kwargs['active'] = ai.lower() in ['', 'y', 'yes', '1', 'active'] from flask_security.forms import ConfirmRegisterForm from werkzeug.datastructures import MultiDict if not kwargs.get('password'): kwargs['password'] = getpass('password: '******'password'] = script.encrypt_password(kwargs['password']) script._datastore.create_user(**kwargs) print('User created successfully.') kwargs['password'] = '******' script.pprint(kwargs) else: print('Error creating user') script.pprint(form.errors)