public function create(Application $app, $id, $email = null, array $templates = [])
    {
        if (!$this->enabled) {
            throw new RuntimeException('Account creator is disabled');
        }

        $login = $id;
        $n = 1;

        if (null !== $email && null !== $app['repo.users']->findByEmail($email)) {
            throw new InvalidArgumentException('Provided email already exist in account base.');
        }

        while (null !== $app['repo.users']->findByLogin($login)) {
            $login = $id . '#' . $n;
            $n++;
        }

        $user = $app['manipulator.user']->createUser($login, $this->random->generateString(128), $email);

        $base_ids = [];
        foreach ($this->appbox->get_databoxes() as $databox) {
            foreach ($databox->get_collections() as $collection) {
                $base_ids[] = $collection->get_base_id();
            }
        }

        foreach (array_merge($this->templates, $templates) as $template) {
            $app->getAclForUser($user)->apply_model($template, $base_ids);
        }

        return $user;
    }