Skip to content

Instantly share code, notes, and snippets.

@svparijs
Created November 20, 2012 20:26
Show Gist options
  • Save svparijs/4120834 to your computer and use it in GitHub Desktop.
Save svparijs/4120834 to your computer and use it in GitHub Desktop.
<f:layout name="Default" />
<f:section name="Title">Account - Login</f:section>
<f:section name="Content">
<div class="row form-alignment">
<div class="offset3 span6 loginbox">
<f:form name="login" class="form-horizontal well" action="authenticate">
<fieldset>
<div id="legend">
<legend class=""><f:translate id="authentication.header">Login</f:translate></legend>
<f:flashMessages class="alert" />
</div>
<div class="control-group">
<!-- Username -->
<label class="control-label" for="username"><f:translate id="authentication.username">Username</f:translate></label>
<div class="controls">
<f:form.textfield id="username" type="text" placeholder="{f:translate(id: 'authentication.username.placeholder', value: 'Your username')}" class="input-large" name="__authentication[TYPO3][Flow][Security][Authentication][Token][UsernamePassword][username]" value="{username}" />
</div>
</div>
<div class="control-group">
<!-- Password-->
<label class="control-label" for="password"><f:translate id="authentication.password">Password</f:translate></label>
<div class="controls">
<f:form.textfield id="password" type="password" placeholder="{f:translate(id: 'authentication.password.placeholder', value: 'Your password')}" class="input-large" name="__authentication[TYPO3][Flow][Security][Authentication][Token][UsernamePassword][password]" />
</div>
</div>
<div class="control-group">
<!-- Button -->
<div class="controls">
<button class="btn btn-success btn-large"><f:translate id="authentication.login">Login</f:translate></button>
<f:if condition="{settings.register}">
<f:link.action class="pull-right" controller="Register" action="new"><f:translate id="register.account">Register account?</f:translate></f:link.action>
</f:if>
</div>
</div>
</fieldset>
</f:form>
</div>
</div>
</f:section>
<?php
namespace Security\Manager\Controller;
/* *
* This script belongs to the TYPO3 Flow package "Security.Manager". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
/**
* A controller which allows for loggin into a application
*
* @Flow\Scope("singleton")
*/
class LoginController extends \TYPO3\Flow\Security\Authentication\Controller\AbstractAuthenticationController {
/**
* @Flow\Inject
* @var \TYPO3\Flow\Security\Authorization\AccessDecisionManagerInterface
*/
protected $accessDecisionManager;
/**
* Index action
*
* @return void
*/
public function indexAction($username = NULL) {
$this->view->assign('username', $username);
$this->view->assign('hostname', $this->request->getHttpRequest()->getBaseUri()->getHost());
$this->view->assign('date', new \DateTime());
}
/**
*
* @return void
*/
public function signedInAction(){
}
/**
* Redirect action
*
* @return void
*/
public function redirectAction() {
$this->redirect('index');
}
/**
* Is called if authentication failed.
*
* @param \TYPO3\Flow\Security\Exception\AuthenticationRequiredException $exception The exception thrown while the authentication process
* @return void
*/
protected function onAuthenticationFailure(\TYPO3\Flow\Security\Exception\AuthenticationRequiredException $exception = NULL) {
$this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Error('The entered username or password was wrong.', ($exception === NULL ? 1347016771 : $exception->getCode())));
#$this->redirect('index');
\TYPO3\Flow\var_dump($this->request->getArguments());
\TYPO3\Flow\var_dump($this->securityContext->getAccount());
}
/**
* Is called if authentication was successful.
*
* @param \TYPO3\Flow\Mvc\ActionRequest $originalRequest The request that was intercepted by the security framework, NULL if there was none
* @return string
*/
public function onAuthenticationSuccess(\TYPO3\Flow\Mvc\ActionRequest $originalRequest = NULL) {
if ($originalRequest !== NULL) {
$this->redirectToRequest($originalRequest);
}
$this->redirect('signedIn');
}
/**
* Logs out a - possibly - currently logged in account.
*
* @return void
*/
public function logoutAction() {
parent::logoutAction();
switch ($this->request->getFormat()) {
default :
$this->flashMessageContainer->addMessage(new \TYPO3\Flow\Error\Notice('Successfully logged out.', 1318421560));
$this->redirect('index');
break;
}
}
}
?>
<?php
namespace Security\Manager\Controller;
/* *
* This script belongs to the TYPO3 Flow package "Security.Manager". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Mvc\Controller\ActionController;
/**
* Register controller for the Security.Manager package
*
* @Flow\Scope("singleton")
*/
class RegisterController extends ActionController {
/**
* @Flow\Inject
* @var \TYPO3\Flow\Security\AccountRepository
*/
protected $accountRepository;
/**
* @Flow\Inject
* @var \TYPO3\Party\Domain\Repository\PartyRepository
*/
protected $partyRepository;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Security\AccountFactory
*/
protected $accountFactory;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Security\Cryptography\HashService
*/
protected $hashService;
/**
* @var \TYPO3\Flow\Security\Context
* @Flow\Inject
*/
protected $securityContext;
/**
* @return void
*/
protected function initializeAction() {
parent::initializeAction();
if ($this->arguments->hasArgument('account')) {
$propertyMappingConfigurationForAccount = $this->arguments->getArgument('account')->getPropertyMappingConfiguration();
$propertyMappingConfigurationForAccountParty = $propertyMappingConfigurationForAccount->forProperty('party');
$propertyMappingConfigurationForAccountPartyName = $propertyMappingConfigurationForAccount->forProperty('party.name');
$propertyMappingConfigurationForAccountParty->setTypeConverterOption('TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_TARGET_TYPE, '\Security\Manager\Domain\Model\User');
foreach (array($propertyMappingConfigurationForAccountParty, $propertyMappingConfigurationForAccountPartyName) as $propertyMappingConfiguration) {
$propertyMappingConfiguration->setTypeConverterOption('TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, TRUE);
$propertyMappingConfiguration->setTypeConverterOption('TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, TRUE);
}
}
}
/**
* Shows a list of registers
*
* @return void
*/
public function indexAction() {
$this->view->assign('accounts', $this->accountRepository->findAll());
}
/**
* Shows a form for creating a new account object
*
* @param \TYPO3\Flow\Security\Account $account
* @return void
*/
public function newAction(\TYPO3\Flow\Security\Account $account = NULL) {
$this->view->assign('account', $account);
}
/**
* Adds the given new account object to the account repository
*
* @param string $identifier
* @Flow\Validate(argumentName="identifier", type="NotEmpty")
* @Flow\Validate(argumentName="identifier", type="StringLength", options={ "minimum"=1, "maximum"=255 })
* @Flow\Validate(argumentName="identifier", type="\Security\Manager\Validation\Validator\AccountExistsValidator", options={ "authenticationProviderName"="Typo3BackendProvider" })
* @param array $password
* @Flow\Validate(argumentName="password", type="\Security\Manager\Validation\Validator\PasswordValidator", options={ "allowEmpty"=0, "minimum"=1, "maximum"=255 })
* @param string $firstName
* @Flow\Validate(argumentName="firstName", type="NotEmpty")
* @Flow\Validate(argumentName="firstName", type="StringLength", options={ "minimum"=1, "maximum"=255 })
* @param string $lastName
* @Flow\Validate(argumentName="lastName", type="NotEmpty")
* @Flow\Validate(argumentName="lastName", type="StringLength", options={ "minimum"=1, "maximum"=255 })
* @return void
* @todo Security
*/
public function createAction($identifier, array $password, $firstName, $lastName) {
$user = new \Security\Manager\Domain\Model\User();
$name = new \TYPO3\Party\Domain\Model\PersonName('', $firstName, '', $lastName, '', $identifier);
$user->setName($name);
$this->partyRepository->add($user);
$account = $this->accountFactory->createAccountWithPassword($identifier, array_shift($password), array('Administrator'), 'DefaultProvider');
$account->setParty($user);
$this->accountRepository->add($account);
$this->addFlashMessage('Created a new account.');
$this->redirect('index');
}
/**
* Edit account profile
*
* @return void
*/
public function editProfileAction(){
$this->view->assign('account', $this->securityContext->getAccount());
}
/**
* Shows a form for editing an existing register object
*
* @param \TYPO3\Flow\Security\Account $account
* @return void
*/
public function editAction(\TYPO3\Flow\Security\Account $account) {
$this->view->assign('account', $account);
}
/**
* Updates the given account object
*
* @param \TYPO3\Flow\Security\Account $account
* @param array $password
* @Flow\Validate(argumentName="password", type="\Security\Manager\Validation\Validator\PasswordValidator", options={ "allowEmpty"=1, "minimum"=1, "maximum"=255 })
* @return void
* @todo Handle validation errors for account (accountIdentifier) & check if there's another account with the same accountIdentifier when changing it
* @todo Security
*/
public function updateAction(\TYPO3\Flow\Security\Account $account, array $password = array()) {
$password = array_shift($password);
if (strlen(trim(strval($password))) > 0) {
$account->setCredentialsSource($this->hashService->hashPassword($password, 'default'));
}
$this->accountRepository->update($account);
$this->partyRepository->update($account->getParty());
$this->addFlashMessage('The user profile has been updated.');
$this->redirect('index');
}
/**
* @param \TYPO3\Flow\Security\Account $account
* @return void
* @todo Security
*/
public function deleteAction(\TYPO3\Flow\Security\Account $account) {
if ($this->securityContext->getAccount() === $account) {
$this->addFlashMessage('You can not remove current logged in user');
$this->redirect('index');
}
$this->accountRepository->remove($account);
$this->addFlashMessage('The user has been deleted.');
$this->redirect('index');
}
/**
* Redirects the action toward the configured back location
*
* @return void
*/
public function backAction(){
$this->redirect('index', 'Login');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment