Skip to content

Commit

Permalink
Admin in AuthDoctrine
Browse files Browse the repository at this point in the history
  • Loading branch information
wingman007 committed Aug 27, 2013
1 parent 98e073a commit a831cb3
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 13 deletions.
5 changes: 4 additions & 1 deletion config/autoload/acl.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
'add' => 'admin',
'edit' => 'admin',
'delete'=> 'admin',
),
),
'AuthDoctrine\Controller\Admin' => array(
'all' => 'admin',
),
// for CMS articles
'Public Resource' => array(
'view' => 'guest',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
namespace Auth\Controller;
namespace AuthDoctrine\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

use Zend\Db\TableGateway\TableGateway;

use Auth\Form\UserForm;
use Auth\Form\UserFilter;
use AuthDoctrine\Form\UserForm;
use AuthDoctrine\Form\UserFilter;

class AdminController extends AbstractActionController
{
Expand All @@ -32,7 +32,7 @@ public function createAction()
unset($data['submit']);
if (empty($data['usr_registration_date'])) $data['usr_registration_date'] = '2013-07-19 12:00:00';
$this->getUsersTable()->insert($data);
return $this->redirect()->toRoute('auth/default', array('controller' => 'admin', 'action' => 'index'));
return $this->redirect()->toRoute('auth-doctrine/default', array('controller' => 'admin', 'action' => 'index'));
}
}
return new ViewModel(array('form' => $form));
Expand All @@ -42,7 +42,7 @@ public function createAction()
public function updateAction()
{
$id = $this->params()->fromRoute('id');
if (!$id) return $this->redirect()->toRoute('auth/default', array('controller' => 'admin', 'action' => 'index'));
if (!$id) return $this->redirect()->toRoute('auth-doctrine/default', array('controller' => 'admin', 'action' => 'index'));
$form = new UserForm();
$request = $this->getRequest();
if ($request->isPost()) {
Expand All @@ -53,7 +53,7 @@ public function updateAction()
unset($data['submit']);
if (empty($data['usr_registration_date'])) $data['usr_registration_date'] = '2013-07-19 12:00:00';
$this->getUsersTable()->update($data, array('usr_id' => $id));
return $this->redirect()->toRoute('auth/default', array('controller' => 'admin', 'action' => 'index'));
return $this->redirect()->toRoute('auth-doctrine/default', array('controller' => 'admin', 'action' => 'index'));
}
}
else {
Expand All @@ -71,7 +71,7 @@ public function deleteAction()
$this->getUsersTable()->delete(array('usr_id' => $id));
}

return $this->redirect()->toRoute('auth/default', array('controller' => 'admin', 'action' => 'index'));
return $this->redirect()->toRoute('auth-doctrine/default', array('controller' => 'admin', 'action' => 'index'));
}

public function getUsersTable()
Expand Down
74 changes: 74 additions & 0 deletions module/AuthDoctrine/src/AuthDoctrine/Form/UserFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
namespace AuthDoctrine\Form;

use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;

class UserFilter extends InputFilter
{
public function __construct()
{
// self::__construct(); // parnt::__construct(); - trows and error
$this->add(array(
'name' => 'usr_name',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
));

$this->add(array(
'name' => 'usr_email',
'required' => false,
'validators' => array(
array(
'name' => 'EmailAddress'
),
),
));

$this->add(array(
'name' => 'usr_password',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 6,
'max' => 12,
),
),
),
));

$this->add(array(
'name' => 'usr_active',
'required' => false,
'filters' => array(
array('name' => 'Int'),
),
'validators' => array(
array(
'name' => 'Digits',
),
),
));

}
}
162 changes: 162 additions & 0 deletions module/AuthDoctrine/src/AuthDoctrine/Form/UserForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php
namespace AuthDoctrine\Form;

use Zend\Form\Form;

class UserForm extends Form
{
public function __construct($name = null)
{
parent::__construct('registration');
$this->setAttribute('method', 'post');

$this->add(array(
'name' => 'usr_name',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Username',
),
));

$this->add(array(
'name' => 'usr_password',
'attributes' => array(
'type' => 'password',
),
'options' => array(
'label' => 'Password',
),
));

$this->add(array(
'name' => 'usr_email',
'attributes' => array(
'type' => 'email',
),
'options' => array(
'label' => 'E-mail',
),
));

$this->add(array(
'name' => 'usrl_id',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Role',
'value_options' => array(
'1' => 'Public',
'2' => 'Member',
'3' => 'Admin',
),
),
));

$this->add(array(
'name' => 'lng_id',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Language',
'value_options' => array(
'1' => 'English',
'2' => 'French',
'3' => 'German',
),
),
));

$this->add(array(
'name' => 'usr_active',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Active',
'value_options' => array(
'0' => 'No',
'1' => 'Yes',
),
),
));

$this->add(array(
'name' => 'usr_question',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Question',
),
));

$this->add(array(
'name' => 'usr_answer',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Answer',
),
));

$this->add(array(
'name' => 'usr_picture',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Picture URL',
),
));

$this->add(array(
'name' => 'usr_password_salt',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Password Salt',
),
));

$this->add(array(
'name' => 'usr_registration_date',
'attributes' => array(
'type' => 'Zend\Form\Element\DateTime', // 'text'
),
'options' => array(
'label' => 'Registration Date',
),
));

$this->add(array(
'name' => 'usr_registration_token',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Registration Token',
),
));

$this->add(array(
'name' => 'usr_email_confirmed',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'E-mail was confirmed?',
'value_options' => array(
'0' => 'No',
'1' => 'Yes',
),
),
));

$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}
2 changes: 1 addition & 1 deletion module/AuthDoctrine/view/auth-doctrine/admin/create.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ echo '<h1>Create</h1>';
// $form = $this->form;
$form->prepare();
// Assuming the "contact/process" route exists...
$form->setAttribute('action', $this->url('auth/default', array('controller' => 'admin', 'action' => 'create'))); //'contact/process'));
$form->setAttribute('action', $this->url('auth-doctrine/default', array('controller' => 'admin', 'action' => 'create'))); //'contact/process'));
// Set the method attribute for the form
$form->setAttribute('method', 'post');

Expand Down
6 changes: 3 additions & 3 deletions module/AuthDoctrine/view/auth-doctrine/admin/index.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>Index = Retrieve</h1>
<a href="<?php echo $this->url('auth/default', array('controller' => 'admin', 'action' => 'create')); ?>">Create</a>
<a href="<?php echo $this->url('auth-doctrine/default', array('controller' => 'admin', 'action' => 'create')); ?>">Create</a>
<table>
<tr>
<th>usr_id</th>
Expand All @@ -13,8 +13,8 @@
<td><?php echo $row['usr_id']; ?></td>
<td><?php echo $row['usr_name']; ?></td>
<td><?php echo $row['usr_email']; ?></td>
<td><a href="<?php echo $this->url('auth/default', array('controller' => 'admin', 'action' => 'update', 'id' => $row['usr_id'])); ?>">Edit</a></td>
<td><a href="<?php echo $this->url('auth/default', array('controller' => 'admin', 'action' => 'delete', 'id' => $row['usr_id']));?>" onclick="return confirm('Do you rely want to delete the record;')">Delete</a></td>
<td><a href="<?php echo $this->url('auth-doctrine/default', array('controller' => 'admin', 'action' => 'update', 'id' => $row['usr_id'])); ?>">Edit</a></td>
<td><a href="<?php echo $this->url('auth-doctrine/default', array('controller' => 'admin', 'action' => 'delete', 'id' => $row['usr_id']));?>" onclick="return confirm('Do you rely want to delete the record;')">Delete</a></td>
</tr>
<?php
}
Expand Down
2 changes: 1 addition & 1 deletion module/AuthDoctrine/view/auth-doctrine/admin/update.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ echo '<h1>Update</h1>';
// $form = $this->form;
$form->prepare();
// Assuming the "contact/process" route exists...
$form->setAttribute('action', $this->url('auth/default', array('controller' => 'admin', 'action' => 'update', 'id' => $id))); //'contact/process'));
$form->setAttribute('action', $this->url('auth-doctrine/default', array('controller' => 'admin', 'action' => 'update', 'id' => $id))); //'contact/process'));
// Set the method attribute for the form
$form->setAttribute('method', 'post');

Expand Down

0 comments on commit a831cb3

Please sign in to comment.