public function create(UserAccountModel $user, UserAccountEditMetaDataModel $userAccountEditMetaDataModel = null)
 {
     global $DB, $CONFIG, $EXTENSIONHOOKRUNNER;
     // TODO should check email and username not already exist and nice error
     $stat = $DB->prepare("INSERT INTO user_account_information (username, username_canonical, email, email_canonical, password_hash, created_at, is_editor, created_from_ip) " . "VALUES (:username, :username_canonical, :email, :email_canonical, :password_hash, :created_at, :is_editor, :created_from_ip) RETURNING id");
     $stat->execute(array('username' => substr($user->getUsername(), 0, VARCHAR_COLUMN_LENGTH_USED), 'username_canonical' => substr(UserAccountModel::makeCanonicalUserName($user->getUsername()), 0, VARCHAR_COLUMN_LENGTH_USED), 'email' => substr($user->getEmail(), 0, VARCHAR_COLUMN_LENGTH_USED), 'email_canonical' => substr(UserAccountModel::makeCanonicalEmail($user->getEmail()), 0, VARCHAR_COLUMN_LENGTH_USED), 'password_hash' => $user->getPasswordHash(), 'created_at' => \TimeSource::getFormattedForDataBase(), 'is_editor' => $CONFIG->newUsersAreEditors ? 1 : 0, 'created_from_ip' => $userAccountEditMetaDataModel ? $userAccountEditMetaDataModel->getIp() : null));
     $data = $stat->fetch();
     $user->setId($data['id']);
     $EXTENSIONHOOKRUNNER->afterUserAccountCreate($user);
 }
 function register(Request $request, Application $app)
 {
     global $CONFIG;
     if (!$app['config']->allowNewUsersToRegister) {
         return $app['twig']->render('index/user/register.notallowed.html.twig', array());
     }
     $this->processThingsToDoAfterGetUser($request, $app);
     $userRepository = new UserAccountRepository();
     $form = $app['form.factory']->create(new SignUpUserForm());
     if ('POST' == $request->getMethod()) {
         $form->bind($request);
         $data = $form->getData();
         if (is_array($CONFIG->userNameReserved) && in_array($data['username'], $CONFIG->userNameReserved)) {
             $form->addError(new FormError('That user name is already taken'));
         }
         $userExistingUserName = $userRepository->loadByUserName($data['username']);
         if ($userExistingUserName) {
             $form->addError(new FormError('That user name is already taken'));
         }
         $userExistingEmail = $userRepository->loadByEmail($data['email']);
         if ($userExistingEmail) {
             $form->addError(new FormError('That email address already has an account'));
         }
         if ($form->isValid()) {
             $user = new UserAccountModel();
             $user->setEmail($data['email']);
             $user->setUsername($data['username']);
             $user->setPassword($data['password1']);
             $userAccountMeta = new UserAccountEditMetaDataModel();
             $userAccountMeta->setFromRequest($request);
             $userRepository->create($user, $userAccountMeta);
             $repo = new UserAccountVerifyEmailRepository();
             $userVerify = $repo->create($user);
             $userVerify->sendEmail($app, $user);
             userLogIn($user);
             $this->actionThingsToDoAfterGetUser($app, $user);
             return $app->redirect("/");
         }
     }
     $this->parameters['form'] = $form->createView();
     return $app['twig']->render('index/user/register.html.twig', $this->parameters);
 }