Esempio n. 1
0
def add_user(login_id,
             email,
             password=None,
             super_user=False,
             send_email=True):
    """
        Creates a new user and optionally sends out the welcome email
    """
    from compstack.auth.model.orm import User
    from compstack.auth.helpers import send_new_user_email

    u = User.add(login_id=login_id,
                 email_address=email,
                 password=password or randchars(8),
                 super_user=super_user)
    if send_email:
        email_sent = send_new_user_email(u)
    else:
        email_sent = False
    return u, email_sent
Esempio n. 2
0
def create_user_with_permissions(approved_perms=None,
                                 denied_perms=None,
                                 super_user=False):
    from compstack.auth.model.orm import User, Permission

    appr_perm_ids = []
    denied_perm_ids = []
    # create the permissions
    for perm in tolist(approved_perms):
        p = Permission.get_by(name=perm)
        if p is None:
            raise ValueError('permission %s does not exist' % perm)
        appr_perm_ids.append(p.id)
    for perm in tolist(denied_perms):
        p = Permission.get_by(name=perm)
        if p is None:
            raise ValueError('permission %s does not exist' % perm)
        denied_perm_ids.append(p.id)

    # create the user
    username = u'user_for_testing_%s' % randchars(15)
    password = randchars(15)
    user = User.add(login_id=username,
                    email_address=u'*****@*****.**' % username,
                    password=password,
                    super_user=super_user,
                    assigned_groups=[],
                    approved_permissions=appr_perm_ids,
                    denied_permissions=denied_perm_ids)

    # turn login flag off
    user.reset_required = False
    db.sess.commit()

    # make text password available
    user.text_password = password

    return user