Skip to content

Instantly share code, notes, and snippets.

@fsuter
Created July 10, 2012 14:59
Show Gist options
  • Save fsuter/3083859 to your computer and use it in GitHub Desktop.
Save fsuter/3083859 to your computer and use it in GitHub Desktop.
Account creation controller
<?php
namespace Cobweb\Monitoring\Controller;
/* *
* This script belongs to the FLOW3 package "Cobweb.Monitoring". *
* *
* */
use TYPO3\FLOW3\Annotations as FLOW3;
/**
* Default controller for the Cobweb.Monitoring package
*
* @FLOW3\Scope("singleton")
*/
class AccountController extends \TYPO3\FLOW3\Mvc\Controller\ActionController {
/**
* @FLOW3\Inject
* @var \TYPO3\FLOW3\Security\AccountFactory
*/
protected $accountFactory;
/**
* @FLOW3\Inject
* @var \TYPO3\FLOW3\Security\AccountRepository
*/
protected $accountRepository;
/**
* @FLOW3\Inject
* @var \TYPO3\Party\Domain\Repository\PartyRepository
*/
protected $partyRepository;
/**
* Index action, lists all existing user accounts
*
* @return void
*/
public function indexAction() {
$this->view->assign('accounts', $this->accountRepository->findAll());
}
/**
* Display form to create a new account
*
* @param \TYPO3\FLOW3\Security\Account $account
* @return void
*/
public function newAction(\TYPO3\FLOW3\Security\Account $account = NULL) {
$this->view->assign('account', $account);
}
/**
* @param string $identifier
* @FLOW3\Validate(argumentName="identifier", type="NotEmpty")
* @FLOW3\Validate(argumentName="identifier", type="StringLength", options={ "minimum"=3, "maximum"=255 })
* @FLOW3\Validate(argumentName="identifier", type="\Cobweb\Monitoring\Validation\Validator\AccountExistsValidator")
* @param array $password
* @FLOW3\Validate(argumentName="password", type="\Cobweb\Monitoring\Validation\Validator\PasswordValidator", options={ "minimum"=10, "maximum"=255 })
* @param string $firstName
* @FLOW3\Validate(argumentName="firstName", type="NotEmpty")
* @FLOW3\Validate(argumentName="firstName", type="StringLength", options={ "minimum"=1, "maximum"=255 })
* @param string $lastName
* @FLOW3\Validate(argumentName="lastName", type="NotEmpty")
* @FLOW3\Validate(argumentName="lastName", type="StringLength", options={ "minimum"=1, "maximum"=255 })
* @param array $roles
* @FLOW3\Validate(argumentName="roles", type="\Cobweb\Monitoring\Validation\Validator\RolesValidator")
*/
public function createAction($identifier, $password, $firstName, $lastName, $roles) {
$account = $this->accountFactory->createAccountWithPassword($identifier, $password[0], $roles);
$this->accountRepository->add($account);
$personName = new \TYPO3\Party\Domain\Model\PersonName('', $firstName, '', $lastName);
$person = new \TYPO3\Party\Domain\Model\Person();
$person->setName($personName);
$person->addAccount($account);
$this->partyRepository->add($person);
$this->addFlashMessage('New account created.');
$this->redirect('index');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment