public function signupAction() { $form = new AccountForm(); $request = $this->getRequest(); if ($request->isPost()) { $user = new User(); $form->setInputFilter($user->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $user->exchangeArray($form->getData()); $username = $this->getUserTable()->getUserByName($user->username); if (!empty($username)) { $this->redirect()->toRoute('user', array('action' => 'signup')); echo '<div class="alert alert-error"> <button type="button" class="close" data-dismiss="alert">×</button> <h4>Warning!</h4> User already exist!. </div>'; } else { $this->getUserTable()->createAccount($user); $this->redirect()->toRoute('user'); } } } return array('form' => $form); }
public function testInputFiltersAreSetCorrectly() { $user = new User(); $inputFilter = $user->getInputFilter(); $this->assertSame(8, $inputFilter->count()); $this->assertTrue($inputFilter->has('userId')); $this->assertTrue($inputFilter->has('firstName')); $this->assertTrue($inputFilter->has('lastName')); }
public function addAction() { $form = new UserForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $user = new User(); $form->setInputFilter($user->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $user->exchangeArray($form->getData()); $this->getUserTable()->saveUser($user); return $this->redirect()->toRoute('user'); } } return array('form' => $form); }
public function doAddAction() { if (!$this->getRequest()->isPost()) { return $this->redirect()->toRoute('user', ['action' => 'add']); } $data = $this->getRequest()->getPost(); $user = new User(); if ($user->getInputFilter()->setData($data)->isValid()) { $user->exchangeArray($data); $userID = $this->userMapper->addUser($user); $addressID = $this->addressMapper->addAddress($user); $this->userAddressMapper->addRelation($userID, $addressID); $this->flashMessenger()->addMessage('User is successfully created.'); return $this->redirect()->toRoute('user'); } else { $this->flashMessenger()->addMessage('Some data are invalid, try again.'); return $this->redirect()->toRoute('user', ['action' => 'add']); } }
public function loginAction() { $authStorage = new AuthenticationStorage(self::NAMESPACE_ZENDSTORE_FRONT); $authService = new AuthenticationService($authStorage); if ($authService->hasIdentity()) { echo 'You have logined'; exit; } $form = new UserForm(); $request = $this->getRequest(); if ($request->isPost()) { $user = new User(); $form->setInputFilter($user->getInputFilter()); $form->setData($request->post()); if ($form->isValid()) { $data = $form->getData(); // Authentication $sm = $this->getServiceLocator(); $db = $sm->get('db-adapter'); //$authAdapter = new AuthenticationAdapter($db, 'user', 'email', 'password', 'MD5(?)'); $authAdapter = new AuthenticationAdapter($db, 'user', 'email', 'password', 'MD5(CONCAT(?, password_salt))'); $authAdapter->setIdentity($data['email']); $authAdapter->setCredential($data['password']); $result = $authService->authenticate($authAdapter); if ($result->isValid()) { return $this->redirect()->toRoute('user-front-user'); } else { var_dump($result->getMessages()); exit; } } else { echo '<h1>ERROR: Form data is invalid.</h1>'; echo '<pre>'; print_r($form->getMessages()); exit; } } $viewVars = array('form' => $form); $viewModel = $this->getViewModel(); $viewModel->setVariables($viewVars); return $viewModel; }
public function addAction() { $form = new UserForm(); $request = $this->getRequest(); if ($request->isPost()) { $User = new User(); $form->setInputFilter($User->getInputFilter()); $form->setData($request->getPost()); $User->user_nom = $request->getPost('User_nom'); $User->user_prenom = $request->getPost('User_prenom'); $User->user_password = $request->getPost('Passwd'); $bcrypt = new Bcrypt(); $securePass = $bcrypt->create($User->user_password); $User->user_password = $securePass; // Sauvegarde $user_id = $this->getUserTable()->saveUser($User); return $this->redirect()->toRoute('User', array('user_id' => $user_id, 'action' => 'index')); } return array('form' => $form, 'erreur' => @$erreur); }
public function addAction() { // $user_session = new \Zend\Session\Container('user'); // if ($user_session->email == null) { // return $this->redirect()->toRoute('signin', array( // 'action' => 'signin' // )); // } // if ($user_session->role == 'Operator') { // return array('error' => 'You don\'t have permission to do this action'); // } $auth = new \Zend\Authentication\AuthenticationService(); if ($auth->hasIdentity()) { $user = $auth->getIdentity(); } else { return $this->redirect()->toRoute('signin', array('action' => 'index')); } if ($user->role == 'Operator') { //$this->flashMessenger()->addMessage('You don\'t have permission to do this action'); //$this->redirect()->toRoute('add'); return array('error' => 'You don\'t have permission to do this action'); } $form = new UserForm(null, $user->role); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $user = new User(); $form->setInputFilter($user->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $user->exchangeArray($form->getData()); $this->getUserTable()->saveUser($user); return $this->redirect()->toRoute('user'); } else { echo "Fail to add new user"; } } return array('form' => $form, 'flashMessages' => $this->flashMessenger()->getMessages()); }
public function signinAction() { $form = new LoginForm(); $request = $this->getRequest(); if ($request->isPost()) { $user = new User(); $form->setInputFilter($user->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $post = $request->getPost(); $sm = $this->getServiceLocator(); $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter'); $authAdapter = new AuthAdapter($dbAdapter); $authAdapter->setTableName('user')->setIdentityColumn('username')->setCredentialColumn('password'); $authAdapter->setIdentity($post->get('username'))->setCredential(sha1($post->get('password'))); $authService = new AuthenticationService(); $authService->setAdapter($authAdapter); $result = $authService->authenticate(); if ($result->isValid()) { $user = $this->getUserTable()->getUserByName($post->get('username')); $session = new Container('user'); $session->offsetUnset('username'); $session->offsetSet('username', $user->username); $session->offsetUnset('id'); $session->offsetSet('id', $user->id); return $this->redirect()->toRoute('image'); } else { echo '<div class="alert alert-error"> <button type="button" class="close" data-dismiss="alert">×</button> <h4>Warning!</h4> Log in failed!. </div>'; } } } return array('form' => $form); }
public function editAction() { $this->accessRights(13); //Accept Parent Module, Return Main Menu Lists with Active Menu Indicator $this->childModuleAccessRights(24, 'edit'); //Accept Child Module ID & it's Actions: add, edit, view, disable $msgs = ''; //Get user id and validate $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('user', array('action' => 'add')); } //Generate Adapter $this->adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); // Get the User with the specified id. An exception is thrown // if it cannot be found, in which case go to the index page. try { $user_data = $this->getUserTable()->getUser($this->adapter, $id); //Get user data } catch (\Exception $ex) { return $this->redirect()->toRoute('user', array('action' => 'index')); } $from = (array) $user_data; $form = new UserEditForm($this->adapter); $form->setData($user_data); //Update record after data posting $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); //get previously posted data //Check if user is trying to update a password if ($request->getPost('password') != $request->getPost('confirm_password')) { $msgs = 'Set new password and confirm new password fields doesn\'t match.'; } else { //Update user credentials $user = new User(); $form->setInputFilter($user->getInputFilter()); $form->setData($request->getPost()); $form->isValid(); //Save to Audit Trail //prepare audit trail parameters $to = $this->getRequest()->getPost()->toArray(); $diff = array_diff_assoc($to, $from); //User Role Update if (array_key_exists("role_id", $diff)) { $from_role_name = (array) $this->getRoleTable()->getRole($this->adapter, $from['role_id']); $from['role_name'] = $from_role_name['role_name']; $to_role_name = (array) $this->getRoleTable()->getRole($this->adapter, $to['role_id']); $to['role_name'] = $to_role_name['role_name']; $diff_role_name = (array) $this->getRoleTable()->getRole($this->adapter, $to['role_id']); $diff['role_name'] = $diff_role_name['role_name']; } //Company Update if (array_key_exists("company_id", $diff)) { $from_company_name = (array) $this->getCompanyTable()->getCompany($from['company_id']); $from['company_name'] = $from_company_name['company_name']; $to_company_name = (array) $this->getCompanyTable()->getCompany($to['company_id']); $to['company_name'] = $to_company_name['company_name']; $diff_company_name = (array) $this->getCompanyTable()->getCompany($to['company_id']); $diff['company_name'] = $diff_company_name['company_name']; } unset($diff['submit'], $diff['app_user_credentials_id'], $diff['user_detail_id'], $diff['role_id'], $diff['company_id'], $diff['password'], $diff['confirm_password']); //Remove IDs $changes = $this->prepare_modified_data($from, $to, $diff); $this->save_to_audit_trail($to['username'], $changes['pre'], $changes['post'], 'edit', 24); // end audit trail parameters $user->exchangeArray($request->getPost()); $this->getUserTable()->saveUser($request->getPost()); $user_data = $this->getUserTable()->getUser($this->adapter, $id); //Get user data //Verify if admin had reset a user password $this->passwordHadBeenChanged('Newswire Password Reset', $request->getPost(), $request->getPost('email')); //Redirect to index $this->flashMessenger()->addMessage(['content' => $request->getPost('username') . ' has been updated!', 'type' => 'success']); $this->redirect()->toRoute('user'); } } $view = new ViewModel(array('form' => $form, 'msgs' => $msgs, 'users' => $this->getUserTable()->fetchAll($this->adapter), 'companies' => $this->getUserTable()->getAllCompany($this->adapter), 'action' => 'edit', 'user_id' => $id, 'user_data' => $user_data, 'tab_menus' => $this->getTabMenu('User & Role'), 'access_rights' => $this->getSubModuleAccessRights(24))); $view->setTemplate('user/index'); return $view; }