def add_user(user_name, first_name, last_name):
    print("Adding User into IPA")

    client = Client(IPA_SERVER_HOST, version='2.215')
    client.login(IPA_ADMIN_USER, IPA_ADMIN_PASSWORD)
    user = client.user_add(user_name, first_name, last_name,
                           "{} {}".format(first_name, last_name))
    print user
Esempio n. 2
0
def verify_user(uid):
    form = RegisterForm(request.form)
    user = User.query.filter_by(uuid=uid).first_or_404()

    if request.method == "POST" and form.validate():
        client = Client("ipa.freeside.co.uk",
                        verify_ssl=False,
                        version="2.215")
        client.login("admin", app.config["IPA_PASSWORD"])
        username = user.email.split("@")[0]
        firstname = form.first_name.data
        firstname = firstname.title()
        lastname = username.split(".")[-1].title()
        username = re.sub("[^a-zA-Z]+", "", username)
        username = username.lower()

        try:
            ipauser = client.user_add(
                username,
                firstname,
                lastname,
                form.first_name.data + " " + lastname,
                display_name=form.display_name.data,
                mail=user.email,
                preferred_language="EN",
                random_pass=True,
            )
        except exceptions.DuplicateEntry:
            flash("Account already exists.")
            return render_template("layout.html")
        print(ipauser["randompassword"])
        client.change_password(username, form.password.data,
                               ipauser["randompassword"])
        user.account_created = True
        db.session.commit()

        createHomeDir(username)

        msg = Message("Welcome to Freeside", recipients=[user.email])
        msg.html = render_template("emails/welcome.html",
                                   firstname=firstname,
                                   username=username)
        with app.app_context():
            mail.send(msg)
        flash("Account created! Your username is: " + username)
        return redirect(url_for("accounts.home"))
    else:
        if user.account_created is True:
            flash("Account already verified!")
            return redirect(url_for("accounts.home"))
        else:
            return render_template("complete_registration.html", form=form)
Esempio n. 3
0
     last_name = name_split[1].strip() if len(name_split) > 1 and len(name_split[1].strip()) > 1 else '*'
 else:
     name = '*'
     first_name = '*'
     last_name = '*'
 try:
     if not only_map_groups:
         try:
             ipa.user_add(
                 person['username'],
                 first_name,
                 last_name,
                 name,
                 home_directory='/home/fedora/%s' % person['username'],
                 disabled=person['status'] != 'active',
                 # If they haven't synced yet, they must reset their password:
                 random_pass=True,
                 fasircnick=person['ircnick'].strip() if person['ircnick'] else None,
                 faslocale=person['locale'].strip() if person['locale'] else None,
                 fastimezone=person['timezone'].strip() if person['timezone'] else None,
                 fasgpgkeyid=[person['gpg_keyid'][:16].strip() if person['gpg_keyid'] else None],
                 fasclafpca=person['group_roles'].get('cla_fpca', {}).get('role_type') == 'user',
             )
             print('ADDED')
         except python_freeipa.exceptions.FreeIPAError as e:
             if e.message == 'user with name "%s" already exists' % person['username']:
                 # Update them instead
                 ipa.user_mod(
                     person['username'],
                     first_name=first_name,
                     last_name=last_name,