Beispiel #1
0
def create(grant_admin):
    """Creates a new user"""
    user_type = 'user' if not grant_admin else 'admin'
    while True:
        email = prompt_email()
        if email is None:
            return
        email = email.lower()
        if not User.query.filter(User.all_emails == email, ~User.is_deleted, ~User.is_pending).has_rows():
            break
        print(cformat('%{red}Email already exists'))
    first_name = click.prompt("First name").strip()
    last_name = click.prompt("Last name").strip()
    affiliation = click.prompt("Affiliation", '').strip()
    print()
    while True:
        username = click.prompt("Enter username").lower().strip()
        if not Identity.find(provider='indico', identifier=username).count():
            break
        print(cformat('%{red}Username already exists'))
    password = prompt_pass()
    if password is None:
        return

    identity = Identity(provider='indico', identifier=username, password=password)
    user = create_user(email, {'first_name': to_unicode(first_name), 'last_name': to_unicode(last_name),
                               'affiliation': to_unicode(affiliation)}, identity)
    user.is_admin = grant_admin
    _print_user_info(user)

    if click.confirm(cformat("%{yellow}Create the new {}?").format(user_type), default=True):
        db.session.add(user)
        db.session.commit()
        print(cformat("%{green}New {} created successfully with ID: %{green!}{}").format(user_type, user.id))
Beispiel #2
0
def create(grant_admin):
    """Creates a new user"""
    user_type = 'user' if not grant_admin else 'admin'
    while True:
        email = prompt_email()
        if email is None:
            return
        email = email.lower()
        if not User.query.filter(User.all_emails == email, ~User.is_deleted, ~User.is_pending).has_rows():
            break
        print(cformat('%{red}Email already exists'))
    first_name = click.prompt("First name").strip()
    last_name = click.prompt("Last name").strip()
    affiliation = click.prompt("Affiliation", '').strip()
    print()
    while True:
        username = click.prompt("Enter username").lower().strip()
        if not Identity.find(provider='indico', identifier=username).count():
            break
        print(cformat('%{red}Username already exists'))
    password = prompt_pass()
    if password is None:
        return

    identity = Identity(provider='indico', identifier=username, password=password)
    user = create_user(email, {'first_name': to_unicode(first_name), 'last_name': to_unicode(last_name),
                               'affiliation': to_unicode(affiliation)}, identity)
    user.is_admin = grant_admin
    _print_user_info(user)

    if click.confirm(cformat("%{yellow}Create the new {}?").format(user_type), default=True):
        db.session.add(user)
        db.session.commit()
        print(cformat("%{green}New {} created successfully with ID: %{green!}{}").format(user_type, user.id))
Beispiel #3
0
def create(grant_admin):
    """Create a new user."""
    user_type = 'user' if not grant_admin else 'admin'
    while True:
        email = prompt_email()
        if email is None:
            return
        email = email.lower()
        if not User.query.filter(User.all_emails == email, ~User.is_deleted, ~User.is_pending).has_rows():
            break
        click.secho('Email already exists', fg='red')
    first_name = click.prompt('First name').strip()
    last_name = click.prompt('Last name').strip()
    affiliation = click.prompt('Affiliation', '').strip()
    print()
    while True:
        username = click.prompt('Enter username').lower().strip()
        if not Identity.query.filter_by(provider='indico', identifier=username).has_rows():
            break
        click.secho('Username already exists', fg='red')
    password = prompt_pass()
    if password is None:
        return

    identity = Identity(provider='indico', identifier=username, password=password)
    user = create_user(email, {'first_name': first_name, 'last_name': last_name, 'affiliation': affiliation}, identity)
    user.is_admin = grant_admin
    _print_user_info(user)

    if click.confirm(click.style(f'Create the new {user_type}?', fg='yellow'), default=True):
        db.session.add(user)
        db.session.commit()
        print(cformat('%{green}New {} created successfully with ID: %{green!}{}').format(user_type, user.id))
Beispiel #4
0
def user_create(grant_admin):
    """Creates new user"""
    update_session_options(db)
    user_type = 'user' if not grant_admin else 'admin'
    while True:
        email = prompt_email()
        if email is None:
            return
        email = email.lower()
        if not User.find(User.all_emails.contains(email), ~User.is_deleted, ~User.is_pending).count():
            break
        error('Email already exists')
    first_name = prompt("First name")
    last_name = prompt("Last name")
    affiliation = prompt("Affiliation", '')
    print()
    while True:
        username = prompt("Enter username").lower()
        if not Identity.find(provider='indico', identifier=username).count():
            break
        error('Username already exists')
    password = prompt_pass()
    if password is None:
        return

    identity = Identity(provider='indico', identifier=username, password=password)
    user = create_user(email, {'first_name': to_unicode(first_name), 'last_name': to_unicode(last_name),
                               'affiliation': to_unicode(affiliation)}, identity)
    user.is_admin = grant_admin
    print_user_info(user)

    if prompt_bool(cformat("%{yellow}Create the new {}?").format(user_type), default=True):
        db.session.add(user)
        db.session.commit()
        success("New {} created successfully with ID: {}".format(user_type, user.id))
Beispiel #5
0
def register_user(email, extra_emails, user_data, identity_data, settings, from_moderation=False):
    """
    Create a user based on the registration data provided during te
    user registration process (via `RHRegister` and `RegistrationHandler`).

    This method is not meant to be used for generic user creation, the
    only reason why this is here is that approving a registration request
    is handled by the `users` module.
    """
    identity = Identity(**identity_data)
    user = create_user(email, user_data, identity=identity, settings=settings, other_emails=extra_emails,
                       from_moderation=from_moderation)
    return user, identity
Beispiel #6
0
def register_user(email, extra_emails, user_data, identity_data, settings, from_moderation=False):
    """
    Create a user based on the registration data provided during te
    user registration process (via `RHRegister` and `RegistrationHandler`).

    This method is not meant to be used for generic user creation, the
    only reason why this is here is that approving a registration request
    is handled by the `users` module.
    """
    identity = Identity(**identity_data)
    user = create_user(email, user_data, identity=identity, settings=settings, other_emails=extra_emails,
                       from_moderation=from_moderation)
    return user, identity
Beispiel #7
0
 def _process(self):
     form = AdminAccountRegistrationForm()
     if form.validate_on_submit():
         data = form.data
         identity = Identity(provider='indico', identifier=data.pop('username'), password=data.pop('password'))
         user = create_user(data.pop('email'), data, identity, from_moderation=True)
         msg = Markup('{} <a href="{}">{}</a>').format(
             escape(_('The account has been created.')),
             url_for('users.user_profile', user),
             escape(_('Show details'))
         )
         flash(msg, 'success')
         return jsonify_data()
     return jsonify_template('users/users_admin_create.html', form=form)
Beispiel #8
0
 def _process(self):
     form = AdminAccountRegistrationForm()
     if form.validate_on_submit():
         data = form.data
         identity = Identity(provider='indico', identifier=data.pop('username'), password=data.pop('password'))
         user = create_user(data.pop('email'), data, identity, from_moderation=True)
         msg = Markup('{} <a href="{}">{}</a>').format(
             escape(_('The account has been created.')),
             url_for('users.user_profile', user),
             escape(_('Show details'))
         )
         flash(msg, 'success')
         return jsonify_data()
     return jsonify_template('users/users_admin_create.html', form=form)