コード例 #1
0
ファイル: handler.py プロジェクト: sand8080/helixauth
    def register_user(self, data, req_info, curs=None):
        env_name = data.get('environment_name')
        env_f = EnvironmentFilter({'name': env_name}, {}, None)
        env = env_f.filter_one_obj(curs)

        # creating user
        a = Authenticator()
        salt = a.salt()
        lang = data.get('lang', User.DEFAULT_LANG)
        u_data = {'environment_id': env.id, 'email': data.get('email'),
            'password': a.encrypt_password(data.get('password'), salt),
            'salt': salt, 'role': User.ROLE_USER,
            'lang': lang}

        group_f = GroupFilter(env.id, {'is_default': True}, {}, None)
        groups = group_f.filter_objs(curs)
        groups_ids = [g.id for g in groups]

        u_data['groups_ids'] = groups_ids
        user = User(**u_data)

        # For correct action logging
        data['environment_id'] = env.id
        try:
            mapping.save(curs, user)
        except ObjectCreationError:
            raise UserAlreadyExists
        auth = Authenticator()
        session = auth.create_session(curs, env, user, req_info)
        _add_log_info(data, session)

        n = Notifier()
        n_process = n.register_user(curs, user, session)
        return response_ok(session_id=session.session_id, id=user.id,
                           notification=n_process)
コード例 #2
0
ファイル: handler.py プロジェクト: sand8080/helixauth
    def add_user(self, data, req_info, session, curs=None):
        a = Authenticator()
        env_id = session.environment_id
        salt = a.salt()
        u_data = {'environment_id': env_id, 'email': data.get('email'),
            'role': data.get('role', User.ROLE_USER),
            'password': a.encrypt_password(data.get('password'), salt),
            'salt': salt, 'is_active': data.get('is_active', True),
            'lang': data.get('lang', User.DEFAULT_LANG)
        }
        if u_data['role'] == User.ROLE_SUPER:
            raise SuperUserCreationDenied

        groups_ids = data.get('groups_ids', [])
        filtered_g_ids = self._filter_existed_groups(curs, session, groups_ids)
        u_data['groups_ids'] = filtered_g_ids
        user = User(**u_data)
        try:
            mapping.save(curs, user)
        except ObjectCreationError:
            raise HelixauthObjectAlreadyExists

        # For correct action logging
        data['id'] = [user.id]
        n = Notifier()
        n_process = n.register_user(curs, user, session)
        return response_ok(id=user.id, notification=n_process)