Esempio n. 1
0
def create_user(name,
                email,
                groups,
                default_sharing,
                permissions,
                password=None):
    user = User.get(email=email.lower())

    if user:
        print "/!\ User with this email address already exists."
    else:
        user = User({
            'name': name,
            'email': email.lower(),
            'groups': groups,
            'default_sharing': default_sharing,
            'permissions': permissions,
            'enabled': True
        })
        if password:
            user['pwd_hash'] = generate_password_hash(password)
        user.save()
        print "[+] User created."

        user.generate_avatar()
        print "[+] Downloaded avatar."

    return user
Esempio n. 2
0
    def update(self, id):
        """Update a user.

        .. :quickref: User; Update existing user

        Requires the `manage_users` permission.

        When succesful, the new user will be returned in the ``user`` field.
        Otherwise, an ``errors`` field will list errors.

        :form name: full name
        :form email: email address
        :form groups: comma-delimited list of groups
        :form permission_VALUE: specify a value different than ``0`` or ``False``
            for all permissions the user should have.
        """
        name = request.form.get('name')
        email = request.form.get('email').lower()
        groups = [g for g in request.form.get('groups', '').split(',') if g]

        user = User(get_or_404(User.get_collection(), _id=id))

        if not self._valid_form(name, email, groups, user['email']):
            return validation_error()

        user['name'] = name
        user['email'] = email
        user['groups'] = groups
        user['permissions'] = self.get_permissions(user['permissions'])
        user.save()

        return redirect({'user': clean_users(user)},
                        url_for('UsersView:get', id=user['_id']))
Esempio n. 3
0
def create_user(saml_name_id, saml_user_data):

    role = saml_user_data[ROLE_KEY][0]

    user = User({
        'saml_name_id': saml_name_id,
        'name': saml_name_id,
        'groups': ROLE_MAPPING[role]['groups'],
        'default_sharing': ROLE_MAPPING[role]['default_sharing'],
        'permissions': ROLE_MAPPING[role]['permissions'],
        'enabled': True
    })
    user.save()
    user.generate_avatar()

    return user
Esempio n. 4
0
def get_or_create_user():
    user = User.get(email="admin@fame")

    if not user:
        user = User({
            'name': "admin",
            'email': "admin@fame",
            'groups': ['admin', '*'],
            'default_sharing': ['admin'],
            'permissions': ['*'],
            'enabled': True
        })
        user.save()
        user.generate_avatar()

    return user
Esempio n. 5
0
def create_user(ldap_user):
    groups = get_mapping(ldap_user['groups'], "groups")
    default_sharing = get_mapping(ldap_user['groups'], "default_sharing")
    permissions = get_mapping(ldap_user["groups"], "permissions")

    user = User({
        'name': ldap_user['name'],
        'email': ldap_user['mail'],
        'enabled': ldap_user['enabled'],
        'groups': groups,
        'default_sharing': default_sharing,
        'permissions': permissions,
    })
    user.save()
    user.generate_avatar()

    return user
Esempio n. 6
0
    def create(self):
        """Create a user.

        .. :quickref: User; Create new user

        Requires the `manage_users` permission.

        When succesful, the new user will be returned in the ``user`` field.
        Otherwise, an ``errors`` field will list errors.

        :form name: full name
        :form email: email address
        :form groups: comma-delimited list of groups
        :form permission_VALUE: specify a value different than ``0`` or ``False``
            for all permissions the user should have.
        """
        name = request.form.get('name')
        email = request.form.get('email').lower()
        groups = [g for g in request.form.get('groups', '').split(',') if g]

        if not self._valid_form(name, email, groups):
            return validation_error()

        user = User({
            'name': name,
            'email': email.lower(),
            'groups': groups,
            'default_sharing': groups,
            'permissions': self.get_permissions(),
            'enabled': True
        })

        if not auth_module.create_user(user):
            return validation_error()

        user.save()

        return redirect({'user': clean_users(user)},
                        url_for('UsersView:index'))