Skip to content

Instantly share code, notes, and snippets.

@jeffery
Created August 4, 2013 06:28
Show Gist options
  • Save jeffery/6149419 to your computer and use it in GitHub Desktop.
Save jeffery/6149419 to your computer and use it in GitHub Desktop.
Account Module
<?php
return array (
'controllers' => array (
'invokables' => array (
'Account\Controller\Index' => 'Account\Controller\IndexController',
),
),
// The following section is new and should be added to your file
'router' => array (
'routes' => array (
'account' => array (
'type' => 'segment',
'options' => array (
'route' => '/account[/][:action][/:id]',
'constraints' => array (
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array (
'controller' => 'Account\Controller\Index',
'action' => 'index',
),
),
),
'zfcuser' => array (
'options' => array (
'route' => '/account',
),
),
),
),
'view_manager' => array (
'template_path_stack' => array (
'account' => __DIR__ . '/../view',
),
),
);
<?php
namespace Account;
use Zend\Mvc\MvcEvent;
class Module
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array (
'Zend\Loader\StandardAutoloader' => array (
'namespaces' => array (
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Account\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use \ZfcUser\Controller\Plugin\ZfcUserAuthentication;
class IndexController extends
AbstractActionController
{
public function indexAction()
{
/*if ( $this->ifUserNotLoggedIn() )
{
$this->redirectToLoginPage();
}*/
return new ViewModel();
}
/**
* @return bool
*/
private function ifUserNotLoggedIn()
{
return !$this->getAuthenticator()->hasIdentity();
}
/**
* @return ZfcUserAuthentication
*/
private function getAuthenticator()
{
return $this->zfcUserAuthentication();
}
private function redirectToLoginPage()
{
$this->redirect()->toRoute(
'account', array (
'controller' => 'zfc-user',
'action' => 'login',
)
);
}
}
<!-- Test if the User is connected -->
<?php if ( !$this->zfcUserIdentity() ): ?>
<!-- display the login form -->
<?php echo $this->zfcUserLoginWidget( array ( 'redirect' => 'index' ) ); ?>
<?php else: ?>
<div style="float:left; padding-right:16px;"><?php echo $this->gravatar( $this->zfcUserIdentity()->getEmail() ) ?></div>
<h3><?php echo $this->translate( 'Hello' ); ?>, <?php echo $this->zfcUserDisplayName() ?>!</h3>
<a href="<?php echo $this->url( 'zfcuser/logout' ) ?>">[<?php echo $this->translate( 'Sign Out' ); ?>]</a>
<div style="clear:both;"></div>
<div><h2>Manage</h2></div>
<?php endif ?>
<?php
var_dump($_SESSION);
<div style="float:left; padding-right:16px;"><?php echo $this->gravatar( $this->zfcUserIdentity()->getEmail() ) ?></div>
<h3><?php echo $this->translate( 'Hello' ); ?>, <?php echo $this->zfcUserDisplayName() ?>!</h3>
<a href="<?php echo $this->url( 'zfcuser/logout' ) ?>">[<?php echo $this->translate( 'Sign Out' ); ?>]</a>
<div style="clear:both;"></div>
<h2>Override</h2>
<h1><?php echo $this->translate('Sign In'); ?></h1>
<?php
$form = $this->loginForm;
$form->prepare();
$form->setAttribute('action', $this->url('zfcuser/login'));
$form->setAttribute('method', 'post');
?>
<?php echo $this->form()->openTag($form) ?>
<dl class="zend_form">
<?php echo $this->formElementErrors($form->get('identity')) ?>
<dt><?php echo $this->formLabel($form->get('identity')) ?></dt>
<dd><?php echo $this->formInput($form->get('identity')) ?></dd>
<dt><?php echo $this->formLabel($form->get('credential')) ?></dt>
<dd><?php echo $this->formInput($form->get('credential')) ?></dd>
<?php if ($this->redirect): ?>
<input type="hidden" name="redirect" value="<?php echo $this->escapeHtml($this->redirect) ?>" />
<?php endif ?>
<dd><?php echo $this->formButton($form->get('submit')) ?></dd>
</dl>
<?php echo $this->form()->closeTag() ?>
<?php if ($this->enableRegistration) : ?>
<?php echo $this->translate('Not registered?'); ?> <a href="<?php echo $this->url('zfcuser/register') . ($this->redirect ? '?redirect='.$this->redirect : '') ?>"><?php echo $this->translate('Sign up!'); ?></a>
<?php endif; ?>
<h2>Override</h2>
<h1><?php echo $this->translate('Register'); ?></h1>
<?php
if (!$this->enableRegistration) {
print "Registration is disabled";
return;
}
$form = $this->registerForm;
$form->prepare();
$form->setAttribute('action', $this->url('zfcuser/register'));
$form->setAttribute('method', 'post');
?>
<?php echo $this->form()->openTag($form) ?>
<dl class="zend_form">
<?php foreach ($form as $element): ?>
<?php if (!$element instanceof Zend\Form\Element\Button): ?>
<dt><?php echo $this->formLabel($element) ?></dt>
<?php endif ?>
<?php if ($element instanceof Zend\Form\Element\Button): ?>
<dd><?php echo $this->formButton($element) ?></dd>
<?php elseif ($element instanceof Zend\Form\Element\Captcha): ?>
<dd><?php echo $this->formCaptcha($element) . $this->formElementErrors($element) ?></dd>
<?php else: ?>
<dd><?php echo $this->formInput($element) . $this->formElementErrors($element) ?></dd>
<?php endif ?>
<?php endforeach ?>
</dl>
<?php if ($this->redirect): ?>
<input type="hidden" name="redirect" value="<?php echo $this->escapeHtml($this->redirect) ?>" />
<?php endif ?>
<?php echo $this->form()->closeTag() ?>
<h2>Override</h2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment