From 9996bb7483bb9c5d2b95a4eccda6dec5bd4d6ca7 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 27 May 2012 14:18:18 +0200 Subject: [PATCH] Companies: edit user's data web page --- .../modules/user/actions/actions.class.php | 90 ++++++++++++++++++++++ apps/companyfront/modules/user/templates/_form.php | 25 ++++++ .../modules/user/templates/editSuccess.php | 4 + .../modules/user/templates/indexSuccess.php | 29 +++++++ .../modules/user/templates/newSuccess.php | 3 + .../modules/user/templates/showSuccess.php | 66 ++++++++++++++++ apps/companyfront/templates/layout.php | 4 +- .../sfGuardUserForm.class.php | 13 +++- test/functional/companyfront/userActionsTest.php | 19 +++++ 9 files changed, 249 insertions(+), 4 deletions(-) create mode 100644 apps/companyfront/modules/user/actions/actions.class.php create mode 100644 apps/companyfront/modules/user/templates/_form.php create mode 100644 apps/companyfront/modules/user/templates/editSuccess.php create mode 100644 apps/companyfront/modules/user/templates/indexSuccess.php create mode 100644 apps/companyfront/modules/user/templates/newSuccess.php create mode 100644 apps/companyfront/modules/user/templates/showSuccess.php create mode 100644 test/functional/companyfront/userActionsTest.php diff --git a/apps/companyfront/modules/user/actions/actions.class.php b/apps/companyfront/modules/user/actions/actions.class.php new file mode 100644 index 0000000..34263db --- /dev/null +++ b/apps/companyfront/modules/user/actions/actions.class.php @@ -0,0 +1,90 @@ +getUser()->getGuardUser()->getId(); + + $this->sf_guard_user = sfGuardUserTable::getInstance()->findOneById($userId); + } + + public function executeShow(sfWebRequest $request) + { + $this->sf_guard_user = Doctrine_Core::getTable('sfGuardUser')->find(array($request->getParameter('id'))); + $this->forward404Unless($this->sf_guard_user); + } + + public function executeNew(sfWebRequest $request) + { + $this->form = new sfGuardUserForm(); + } + + public function executeCreate(sfWebRequest $request) + { + $this->forward404Unless($request->isMethod(sfRequest::POST)); + + $this->form = new sfGuardUserForm(); + + $this->processForm($request, $this->form); + + $this->setTemplate('new'); + } + + public function executeEdit(sfWebRequest $request) + { + //Get user Id + $userId = $this->getUser()->getGuardUser()->getId(); + + $sf_guard_user = sfGuardUserTable::getInstance()->findOneById($userId); + + $this->form = new sfGuardUserForm($sf_guard_user); + } + + public function executeUpdate(sfWebRequest $request) + { + $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT)); + $this->forward404Unless($sf_guard_user = Doctrine_Core::getTable('sfGuardUser')->find(array($request->getParameter('id'))), sprintf('Object sf_guard_user does not exist (%s).', $request->getParameter('id'))); + + //Get user Id + $userId = $this->getUser()->getGuardUser()->getId(); + //Never trust data coming from users + $this->forward404Unless($userId == $sf_guard_user->getId(), sprintf('User does not exist')); + + $this->form = new sfGuardUserForm($sf_guard_user); + + $this->processForm($request, $this->form); + + $this->setTemplate('edit'); + } + + public function executeDelete(sfWebRequest $request) + { + $request->checkCSRFProtection(); + + $this->forward404Unless($sf_guard_user = Doctrine_Core::getTable('sfGuardUser')->find(array($request->getParameter('id'))), sprintf('Object sf_guard_user does not exist (%s).', $request->getParameter('id'))); + $sf_guard_user->delete(); + + $this->redirect('user/index'); + } + + protected function processForm(sfWebRequest $request, sfForm $form) + { + $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); + if ($form->isValid()) + { + $sf_guard_user = $form->save(); + + $this->redirect('user/edit?id='.$sf_guard_user->getId()); + } + } +} diff --git a/apps/companyfront/modules/user/templates/_form.php b/apps/companyfront/modules/user/templates/_form.php new file mode 100644 index 0000000..926b112 --- /dev/null +++ b/apps/companyfront/modules/user/templates/_form.php @@ -0,0 +1,25 @@ + + + +
isMultipart() and print 'enctype="multipart/form-data" ' ?>> +getObject()->isNew()): ?> + + + + + + + + + + renderGlobalErrors() ?> + + + + +
+ renderHiddenFields(false) ?> +   + +
+
diff --git a/apps/companyfront/modules/user/templates/editSuccess.php b/apps/companyfront/modules/user/templates/editSuccess.php new file mode 100644 index 0000000..ac23570 --- /dev/null +++ b/apps/companyfront/modules/user/templates/editSuccess.php @@ -0,0 +1,4 @@ +

+ + + $form)) ?> diff --git a/apps/companyfront/modules/user/templates/indexSuccess.php b/apps/companyfront/modules/user/templates/indexSuccess.php new file mode 100644 index 0000000..28249a8 --- /dev/null +++ b/apps/companyfront/modules/user/templates/indexSuccess.php @@ -0,0 +1,29 @@ +

+ + + + + + + + + + + + + + + + + + + + + + + + +
getFirstName() ?>
getLastName() ?>
getEmailAddress() ?>
getLastLogin() ?>
getLanguage()->getLanguageName() ?>
+ + + diff --git a/apps/companyfront/modules/user/templates/newSuccess.php b/apps/companyfront/modules/user/templates/newSuccess.php new file mode 100644 index 0000000..480f447 --- /dev/null +++ b/apps/companyfront/modules/user/templates/newSuccess.php @@ -0,0 +1,3 @@ +

New Sf guard user

+ + $form)) ?> diff --git a/apps/companyfront/modules/user/templates/showSuccess.php b/apps/companyfront/modules/user/templates/showSuccess.php new file mode 100644 index 0000000..d85fee1 --- /dev/null +++ b/apps/companyfront/modules/user/templates/showSuccess.php @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id:getId() ?>
First name:getFirstName() ?>
Last name:getLastName() ?>
Email address:getEmailAddress() ?>
Username:getUsername() ?>
Algorithm:getAlgorithm() ?>
Salt:getSalt() ?>
Password:getPassword() ?>
Is active:getIsActive() ?>
Is super admin:getIsSuperAdmin() ?>
Last login:getLastLogin() ?>
Language:getLanguageId() ?>
Created at:getCreatedAt() ?>
Updated at:getUpdatedAt() ?>
+ +
+ +Edit +  +List diff --git a/apps/companyfront/templates/layout.php b/apps/companyfront/templates/layout.php index f62cac1..4ad66ea 100644 --- a/apps/companyfront/templates/layout.php +++ b/apps/companyfront/templates/layout.php @@ -90,7 +90,7 @@
  • - + - + diff --git a/lib/form/doctrine/sfDoctrineGuardPlugin/sfGuardUserForm.class.php b/lib/form/doctrine/sfDoctrineGuardPlugin/sfGuardUserForm.class.php index 1ad828f..79cd4a7 100644 --- a/lib/form/doctrine/sfDoctrineGuardPlugin/sfGuardUserForm.class.php +++ b/lib/form/doctrine/sfDoctrineGuardPlugin/sfGuardUserForm.class.php @@ -5,12 +5,21 @@ * * @package mobiads * @subpackage form - * @author Your name here - * @version SVN: $Id: sfDoctrinePluginFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ + * @author Gustavo Martin Morcuende + * @version */ class sfGuardUserForm extends PluginsfGuardUserForm { public function configure() { + $this->useFields(array('first_name', 'last_name', 'email_address', 'language_id')); + + + $this->widgetSchema['language_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), + 'add_empty' => false)); + + + $this->validatorSchema['language_id'] = new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), + 'required' => true)); } } diff --git a/test/functional/companyfront/userActionsTest.php b/test/functional/companyfront/userActionsTest.php new file mode 100644 index 0000000..a8156ff --- /dev/null +++ b/test/functional/companyfront/userActionsTest.php @@ -0,0 +1,19 @@ + + get('/user/index')-> + + with('request')->begin()-> + isParameter('module', 'user')-> + isParameter('action', 'index')-> + end()-> + + with('response')->begin()-> + isStatusCode(200)-> + checkElement('body', '!/This is a temporary page/')-> + end() +; -- 2.1.4