public function first(Request $request)
{
// We should only be here for creating the first user
if ($this->app['schema']->hasUserTable() && $this->users()->hasUsers()) {
return $this->redirectToRoute('dashboard');
}
// Get and empty user
$userEntity = new Entity\Users();
// Add a note, if we're setting up the first user using SQLite.
$dbdriver = $this->getOption('general/database/driver');
if ($dbdriver === 'sqlite' || $dbdriver === 'pdo_sqlite') {
$note = Trans::__('page.edit-users.note-sqlite');
} else {
$note = '';
}
// If we get here, chances are we don't have the tables set up, yet.
$this->app['schema']->update();
// Grant 'root' to first user by default
$userEntity->setRoles([Permissions::ROLE_ROOT]);
// Get the form
$form = $this->getUserForm($userEntity, true);
// Set the validation
$form = $this->setUserFormValidation($form, true);
/** @var \Symfony\Component\Form\Form */
$form = $form->getForm();
// Check if the form was POST-ed, and valid. If so, store the user.
if ($request->isMethod('POST') && ($response = $this->firstPost($request, $form))) {
return $response;
}
$context = ['kind' => 'create', 'form' => $form->createView(), 'note' => $note, 'displayname' => $userEntity['displayname'], 'sitename' => $this->getOption('general/sitename')];
return $this->render('@bolt/firstuser/firstuser.twig', $context);
}