/** * Load user fixture * * @access public * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $faker = \Faker\Factory::create(); $userCredentials = UserCredentials::$userCredentials; $inflector = new Inflector(); foreach ($userCredentials as $userName => $userCredential) { $user = new UserEntity(); $date = new \DateTime(); $user->setFirstName($faker->firstName)->setMiddleName($faker->firstName)->setLastName($faker->lastName)->setCountry($faker->countryCode)->setLanguage($faker->languageCode)->setUsername($userName)->setPassword(UserEntity::hashPassword($userCredential["password"]))->setMobile($faker->numberBetween(1000000000, 2000000000))->setAddressOne($faker->address)->setAddressTwo($faker->address)->setCity($faker->city)->setZipCode($faker->postcode)->setPhone($faker->numberBetween(1000000000, 2000000000))->setNationality($faker->countryCode)->setIdentificationType($faker->word)->setIdentificationNumber($faker->numberBetween(999999))->setIdentificationExpiryDate($faker->dateTimeBetween('+2 years', '+20 years')->format(Time::DATE_FORMAT))->setEmail($faker->freeEmail)->setSecurityQuestion($faker->sentence)->setSecurityAnswer($faker->sentence)->setDateOfBirth($date->format(Time::DATE_FORMAT))->setPhoto('/upload/images/userdefault.png')->setPrivacyStatement(true)->setStatus(Status::STATUS_ACTIVE)->setStudentStatement(Status::STATUS_INACTIVE)->setInstructorStatement(Status::STATUS_INACTIVE)->setProctorStatement(Status::STATUS_INACTIVE)->setTestCenterAdministratorStatement(Status::STATUS_INACTIVE)->setTrainingManagerStatement(Status::STATUS_INACTIVE); $approvedStatementMethod = "set" . $inflector->camelize("{$userName}Statement"); if (method_exists($user, $approvedStatementMethod)) { $user->{$approvedStatementMethod}(Status::STATUS_ACTIVE); } $manager->persist($user); $this->addReference($userName . "User", $user); } $manager->flush(); }
/** * Signup if not logged in * * @return void */ public function indexAction() { $this->layout('layout/signup'); $viewData = array(); $signupForm = new SignupForm(); $signupForm->setAttribute('action', $this->url()->fromRoute('users-signup')); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost()->toArray(); $signupForm->setInputFilter(User::getInputFilter()); $signupForm->setData($data); if ($signupForm->isValid()) { $files = $request->getFiles()->toArray(); $data = $signupForm->getData(); $data['avatar'] = $files['avatar']['name'] != '' ? $files['avatar']['name'] : null; if ($data['avatar'] !== null) { $size = new Size(array('max' => 2048000)); $isImage = new IsImage(); $filename = $data['avatar']; $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setValidators(array($size, $isImage), $filename); if (!$adapter->isValid($filename)) { $errors = array(); foreach ($adapter->getMessages() as $key => $row) { $errors[] = $row; } $signupForm->setMessages(array('avatar' => $errors)); } $destPath = 'data/tmp/'; $adapter->setDestination($destPath); $fileinfo = $adapter->getFileInfo(); preg_match('/.+\\/(.+)/', $fileinfo['avatar']['type'], $matches); $newFilename = sprintf('%s.%s', sha1(uniqid(time(), true)), $matches[1]); $adapter->addFilter('File\\Rename', array('target' => $destPath . $newFilename, 'overwrite' => true)); if ($adapter->receive($filename)) { $data['avatar'] = base64_encode(file_get_contents($destPath . $newFilename)); if (file_exists($destPath . $newFilename)) { unlink($destPath . $newFilename); } } } unset($data['repeat_password']); unset($data['csrf']); unset($data['register']); $response = ApiClient::registerUser($data); if ($response['result'] == true) { $this->flashMessenger()->addMessage('Account created!'); return $this->redirect()->toRoute('wall', array('username' => $data['username'])); } } } $viewData['signupForm'] = $signupForm; return $viewData; }
/** * Run Method. * * Write your database seeder using this method. * * More information on writing seeders is available here: * http://docs.phinx.org/en/latest/seeding.html */ public function run() { $faker = Faker\Factory::create(); // dummy user to use his id ad foreign key in orgs $normalUser = array("firstName" => $faker->firstName, "middleName" => $faker->name, "lastName" => $faker->lastName, "country" => $faker->countryCode, "language" => $faker->languageCode, "username" => "testuser", "password" => User::hashPassword("testuser"), "mobile" => $faker->phoneNumber, "addressOne" => $faker->address, "addressTwo" => $faker->address, "city" => $faker->city, "zipCode" => $faker->postcode, "phone" => $faker->phoneNumber, "nationality" => $faker->countryCode, "identificationType" => $faker->word, "identificationNumber" => $faker->numberBetween(999999), "identificationExpiryDate" => $faker->dateTimeBetween('+2 years', '+20 years')->format('Y-m-d H:i:s'), "email" => $faker->freeEmail, "securityQuestion" => $faker->sentence, "securityAnswer" => $faker->sentence, "dateOfBirth" => date('Y-m-d H:i:s'), "photo" => '/upload/images/userdefault.png', "privacyStatement" => true, "studentStatement" => false, "proctorStatement" => false, "instructorStatement" => false, "testCenterAdministratorStatement" => false, "trainingManagerStatement" => false, "status" => true); $this->insert('user', $normalUser); $normalUserId = $this->getAdapter()->getConnection()->lastInsertId(); $atp[] = array('commercialName' => $faker->userName, 'status' => true, 'type' => 2, 'ownerName' => $faker->userName, 'ownerNationalId' => $faker->randomNumber(), 'longtitude' => $faker->randomFloat(), 'latitude' => $faker->randomFloat(), 'CRNo' => $faker->randomNumber(), 'CRExpiration' => date('Y-m-d H:i:s'), 'CRAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'phone1' => $faker->phoneNumber, 'phone2' => $faker->phoneNumber, 'phone3' => $faker->phoneNumber, 'fax' => $faker->randomNumber(), 'website' => $faker->url, 'email' => $faker->email, 'addressLine1' => $faker->address, 'addressLine2' => $faker->address, 'city' => $faker->city, 'zipCode' => $faker->randomNumber(), 'atpLicenseNo' => $faker->randomNumber(), 'atpLicenseExpiration' => date('Y-m-d H:i:s'), 'atpLicenseAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'classesNo' => $faker->randomDigitNotNull, 'pcsNo_class' => $faker->randomDigitNotNull, 'atcLicenseNo' => null, 'atcLicenseExpiration' => null, 'atcLicenseAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'labsNo' => null, 'pcsNo_lab' => null, 'operatingSystem' => null, 'operatingSystemLang' => null, 'internetSpeed_lab' => null, 'officeLang' => null, 'officeVersion' => null, 'focalContactPerson_id' => $normalUserId); $this->insert('organization', $atp); $atc[] = array('commercialName' => $faker->userName, 'status' => true, 'type' => 1, 'ownerName' => $faker->userName, 'ownerNationalId' => $faker->randomNumber(), 'longtitude' => $faker->randomFloat(), 'latitude' => $faker->randomFloat(), 'CRNo' => $faker->randomNumber(), 'CRExpiration' => date('Y-m-d H:i:s'), 'CRAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'phone1' => $faker->phoneNumber, 'phone2' => $faker->phoneNumber, 'phone3' => $faker->phoneNumber, 'fax' => $faker->randomNumber(), 'website' => $faker->url, 'email' => $faker->email, 'zipCode' => $faker->randomNumber(), 'addressLine1' => $faker->address, 'addressLine2' => $faker->address, 'city' => $faker->city, 'atpLicenseNo' => null, 'atpLicenseExpiration' => null, 'atpLicenseAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'classesNo' => null, 'pcsNo_class' => null, 'atcLicenseNo' => $faker->randomNumber(), 'atcLicenseExpiration' => date('Y-m-d H:i:s'), 'atcLicenseAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'labsNo' => $faker->randomDigitNotNull, 'pcsNo_lab' => $faker->randomDigitNotNull, 'operatingSystem' => $faker->biasedNumberBetween(0, 5), 'operatingSystemLang' => $faker->biasedNumberBetween(0, 5), 'internetSpeed_lab' => $faker->randomNumber(), 'officeLang' => $faker->biasedNumberBetween(0, 5), 'officeVersion' => $faker->biasedNumberBetween(0, 5), 'focalContactPerson_id' => $normalUserId); $this->insert('organization', $atc); $both[] = array('commercialName' => $faker->userName, 'status' => true, 'type' => 3, 'ownerName' => $faker->userName, 'ownerNationalId' => $faker->randomNumber(), 'longtitude' => $faker->randomFloat(), 'latitude' => $faker->randomFloat(), 'CRNo' => $faker->randomNumber(), 'CRExpiration' => date('Y-m-d H:i:s'), 'CRAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'phone1' => $faker->phoneNumber, 'phone2' => $faker->phoneNumber, 'phone3' => $faker->phoneNumber, 'fax' => $faker->randomNumber(), 'zipCode' => $faker->randomNumber(), 'website' => $faker->url, 'email' => $faker->email, 'addressLine1' => $faker->address, 'addressLine2' => $faker->address, 'city' => $faker->city, 'atpLicenseNo' => $faker->randomNumber(), 'atpLicenseExpiration' => date('Y-m-d H:i:s'), 'atpLicenseAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'classesNo' => $faker->randomDigitNotNull, 'pcsNo_class' => $faker->randomDigitNotNull, 'atcLicenseNo' => $faker->randomNumber(), 'atcLicenseExpiration' => date('Y-m-d H:i:s'), 'atcLicenseAttachment' => 'public/upload/attachments/crAttachments/1481954966569cc429ba594538397168ff703afaeed43172867529e3c1929a39_2016.01.18_10:53:29am.docx', 'labsNo' => $faker->randomDigitNotNull, 'pcsNo_lab' => $faker->randomDigitNotNull, 'operatingSystem' => $faker->biasedNumberBetween(0, 5), 'operatingSystemLang' => $faker->biasedNumberBetween(0, 5), 'internetSpeed_lab' => $faker->randomNumber(), 'officeLang' => $faker->biasedNumberBetween(0, 5), 'officeVersion' => $faker->biasedNumberBetween(0, 5), 'focalContactPerson_id' => $normalUserId); $this->insert('organization', $both); }
/** * Upload a new image * * @param Zend\Form\Form $form * @param Users\Entity\User $user * @param array $data */ protected function createImage($form, $user, $data) { if ($data['image']['error'] != 0) { $data['image'] = NULL; } $form->setData($data); $size = new Size(array('max' => 2048000)); $isImage = new IsImage(); $filename = $data['image']['name']; $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setValidators(array($size, $isImage), $filename); if (!$adapter->isValid($filename)) { $errors = array(); foreach ($adapter->getMessages() as $key => $row) { $errors[] = $row; } $form->setMessages(array('image' => $errors)); } if ($form->isValid()) { $destPath = 'data/tmp/'; $adapter->setDestination($destPath); $fileinfo = $adapter->getFileInfo(); preg_match('/.+\\/(.+)/', $fileinfo['image']['type'], $matches); $extension = $matches[1]; $newFilename = sprintf('%s.%s', sha1(uniqid(time(), true)), $extension); $adapter->addFilter('File\\Rename', array('target' => $destPath . $newFilename, 'overwrite' => true)); if ($adapter->receive($filename)) { $data = array(); $data['image'] = base64_encode(file_get_contents($destPath . $newFilename)); $data['user_id'] = $user->getId(); unlink($destPath . $newFilename); $response = ApiClient::postWallContent($user->getUsername(), $data); return $response['result']; } } return $form; }
/** * Method to login the user on the application * * @return void */ public function loginAction() { $viewData = array(); $flashMessenger = $this->flashMessenger(); $loginForm = new LoginForm(); $loginForm->setAttribute('action', $this->url()->fromRoute('users-login')); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost()->toArray(); $loginForm->setInputFilter(User::getLoginInputFilter()); $loginForm->setData($data); if ($loginForm->isValid()) { $data = $loginForm->getData(); $auth = new AuthenticationService(); $authAdapter = new AuthAdapter($data['username'], $data['password']); $result = $auth->authenticate($authAdapter); if (!$result->isValid()) { foreach ($result->getMessages() as $msg) { $flashMessenger->addMessage($msg); } } else { return $this->redirect()->toRoute('wall', array('username' => $data['username'])); } } } $viewData['loginForm'] = $loginForm; if ($flashMessenger->hasMessages()) { $viewData['flashMessages'] = $flashMessenger->getMessages(); } return $viewData; }
/** * Validate that the record in the result set is indeed a record * that matched the identity provided to this adapter. * * * @access protected * @param array $resultIdentities * @return Result */ protected function validateResult($resultIdentities) { if (count($resultIdentities) < 1) { $this->_authenticateResultInfo['code'] = Result::FAILURE_IDENTITY_NOT_FOUND; $this->_authenticateResultInfo['messages'][] = 'A record with the supplied identity could not be found.'; return $this->authenticateCreateAuthResult(); } elseif (count($resultIdentities) > 1) { $this->_authenticateResultInfo['code'] = Result::FAILURE_IDENTITY_AMBIGUOUS; $this->_authenticateResultInfo['messages'][] = 'More than one record matches the supplied identity.'; return $this->authenticateCreateAuthResult(); } elseif (count($resultIdentities) == 1) { $resultIdentity = $resultIdentities[0]; $password = $resultIdentity->{$this->_credentialColumn}; if (!User::verifyPassword($this->_credential, $password)) { $this->_authenticateResultInfo['code'] = Result::FAILURE_CREDENTIAL_INVALID; $this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.'; } else { $this->_authenticateResultInfo['code'] = Result::SUCCESS; $this->_authenticateResultInfo['identity'] = $this->_identity; $this->_authenticateResultInfo['messages'][] = 'Authentication successful.'; } } else { $this->_authenticateResultInfo['code'] = Result::FAILURE_UNCATEGORIZED; } return $this->authenticateCreateAuthResult(); }
/** * Run Method. * * Write your database seeder using this method. * * More information on writing seeders is available here: * http://docs.phinx.org/en/latest/seeding.html */ public function run() { $faker = Faker\Factory::create(); // $instructorRole = array('name' => Role::INSTRUCTOR_ROLE); // $this->insert('role', $instructorRole); $instructorRoleId = $this->fetchRow('select id from role where name = "Instructor"')['id']; $proctorRole = array('name' => Role::PROCTOR_ROLE); $this->insert('role', $proctorRole); $proctorRoleId = $this->getAdapter()->getConnection()->lastInsertId(); $studentRole = array('name' => Role::STUDENT_ROLE); $this->insert('role', $studentRole); $studentRoleId = $this->getAdapter()->getConnection()->lastInsertId(); $testCenterAdminRole = array('name' => Role::TEST_CENTER_ADMIN_ROLE); $this->insert('role', $testCenterAdminRole); $testCenterAdminRoleId = $this->getAdapter()->getConnection()->lastInsertId(); $trainingManagerRole = array('name' => Role::TRAINING_MANAGER_ROLE); $this->insert('role', $trainingManagerRole); $trainingManagerRoleId = $this->getAdapter()->getConnection()->lastInsertId(); $userRole = array('name' => Role::USER_ROLE); $this->insert('role', $userRole); $normalUserRoleId = $this->getAdapter()->getConnection()->lastInsertId(); $adminRole = array('name' => Role::ADMIN_ROLE); $this->insert('role', $adminRole); $adminRoleId = $this->getAdapter()->getConnection()->lastInsertId(); $userModule = "Users"; $userEditRoute = "userEdit"; $userAcls = array(array('role_id' => $instructorRoleId, 'module' => $userModule, 'route' => $userEditRoute), array('role_id' => $proctorRoleId, 'module' => $userModule, 'route' => $userEditRoute), array('role_id' => $studentRoleId, 'module' => $userModule, 'route' => $userEditRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $userModule, 'route' => $userEditRoute), array('role_id' => $trainingManagerRoleId, 'module' => $userModule, 'route' => $userEditRoute), array('role_id' => $normalUserRoleId, 'module' => $userModule, 'route' => $userEditRoute)); $this->insert('acl', $userAcls); $courseModule = "Courses"; $coursesCalendarRoute = "coursesCalendar"; $coursesMoreRoute = "coursesMore"; $courseOutlines = "courseOutlines"; $coursesEnrollRoute = "coursesEnroll"; $coursesLeaveRoute = "coursesLeave"; $coursesEditRoute = "coursesEdit"; $coursesNewRoute = "coursesNew"; $coursesPendingRoute = "coursesPending"; $coursesListRoute = "courses"; $coursesVoteRoute = "studentEvaluation"; $courseEvaluation = "courseEvaluations"; $newCourseEvaluation = "newCourseEvaluation"; $editCourseEvaluation = "editCourseEvaluation"; $instructorCalendar = "coursesInstructorCalendar"; $coursesInstructorTrainingRoute = "coursesInstructorTraining"; $examBookingRoute = "examBooking"; $coursesAcls = array(array('role_id' => $studentRoleId, 'module' => $courseModule, 'route' => $coursesCalendarRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $courseModule, 'route' => $coursesCalendarRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $coursesCalendarRoute), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $coursesCalendarRoute), array('role_id' => $studentRoleId, 'module' => $courseModule, 'route' => $coursesMoreRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $courseModule, 'route' => $coursesMoreRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $coursesMoreRoute), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $coursesMoreRoute), array('role_id' => $studentRoleId, 'module' => $courseModule, 'route' => $coursesEnrollRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $courseModule, 'route' => $coursesEnrollRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $coursesEnrollRoute), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $coursesEnrollRoute), array('role_id' => $studentRoleId, 'module' => $courseModule, 'route' => $coursesLeaveRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $courseModule, 'route' => $coursesLeaveRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $coursesLeaveRoute), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $coursesLeaveRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $coursesNewRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $coursesEditRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $coursesListRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $coursesPendingRoute), array('role_id' => $studentRoleId, 'module' => $courseModule, 'route' => $coursesVoteRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $courseEvaluation), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $newCourseEvaluation), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $editCourseEvaluation), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $coursesInstructorTrainingRoute), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $instructorCalendar), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $courseOutlines), array('role_id' => $normalUserRoleId, 'module' => $courseModule, 'route' => $courseOutlines), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $courseOutlines), array('role_id' => $testCenterAdminRoleId, 'module' => $courseModule, 'route' => $courseOutlines), array('role_id' => $studentRoleId, 'module' => $courseModule, 'route' => $courseOutlines), array('role_id' => $testCenterAdminRoleId, 'module' => $courseModule, 'route' => $examBookingRoute)); $this->insert('acl', $coursesAcls); $resourcesListPerCourseRoute = "resourcesListPerCourse"; $resourcesResourceDownloadRoute = "resourcesResourceDownload"; $resourcesNewPerCourseRoute = "resourcesNewPerCourse"; $resourcesEditRoute = "resourcesEdit"; $resourcesAcls = array(array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $resourcesListPerCourseRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $resourcesNewPerCourseRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $resourcesEditRoute), array('role_id' => $studentRoleId, 'module' => $courseModule, 'route' => $resourcesResourceDownloadRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $courseModule, 'route' => $resourcesResourceDownloadRoute), array('role_id' => $trainingManagerRoleId, 'module' => $courseModule, 'route' => $resourcesResourceDownloadRoute), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $resourcesResourceDownloadRoute), array('role_id' => $instructorRoleId, 'module' => $courseModule, 'route' => $resourcesListPerCourseRoute)); $this->insert('acl', $resourcesAcls); $organizationModule = "Organizations"; $organizationUsersRoute = "organizationUsers"; $organizationUsersListRoute = "organizationUsersList"; $organizationUsersNewRoute = "organizationUsersNew"; $organizationUsersEditRoute = "organizationUsersEdit"; $organizationUsersDeleteRoute = "organizationUsersDelete"; $organizationsPendingRoute = "organizationsPending"; $organizationsDownloadRoute = "organizationsDownload"; $listAtcOrgsRoute = "list_atc_orgs"; $listAtpOrgsRoute = "list_atp_orgs"; $orgTypeRoute = "org_type"; $orgMoreRoute = "more"; $orgNewRoute = "new_org"; $orgEditRoute = "edit_org"; $saveStateRoute = "saveState"; $organizationAcls = array(array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $organizationsDownloadRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $organizationsDownloadRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $organizationsPendingRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $organizationsPendingRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $organizationUsersRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $organizationUsersRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $organizationUsersListRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $organizationUsersListRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $organizationUsersNewRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $organizationUsersNewRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $organizationUsersEditRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $organizationUsersEditRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $organizationUsersDeleteRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $organizationUsersDeleteRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $listAtcOrgsRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $listAtpOrgsRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $orgTypeRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $orgTypeRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $saveStateRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $saveStateRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $orgEditRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $orgEditRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $orgNewRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $orgNewRoute), array('role_id' => $testCenterAdminRoleId, 'module' => $organizationModule, 'route' => $orgMoreRoute), array('role_id' => $trainingManagerRoleId, 'module' => $organizationModule, 'route' => $orgMoreRoute)); $this->insert('acl', $organizationAcls); $adminUser = array("firstName" => $faker->firstName, "middleName" => $faker->name, "lastName" => $faker->lastName, "country" => $faker->countryCode, "language" => $faker->languageCode, "username" => "admin", "password" => User::hashPassword("adminadmin"), "mobile" => $faker->phoneNumber, "addressOne" => $faker->address, "addressTwo" => $faker->address, "city" => $faker->city, "zipCode" => $faker->postcode, "phone" => $faker->phoneNumber, "nationality" => $faker->countryCode, "identificationType" => $faker->word, "identificationNumber" => $faker->numberBetween(999999), "identificationExpiryDate" => $faker->dateTimeBetween('+2 years', '+20 years')->format('Y-m-d H:i:s'), "email" => $faker->freeEmail, "securityQuestion" => $faker->sentence, "securityAnswer" => $faker->sentence, "dateOfBirth" => date('Y-m-d H:i:s'), "photo" => '/upload/images/userdefault.png', "privacyStatement" => true, "studentStatement" => false, "proctorStatement" => false, "instructorStatement" => false, "testCenterAdministratorStatement" => false, "trainingManagerStatement" => false, "status" => true); $this->insert('user', $adminUser); $adminUserId = $this->getAdapter()->getConnection()->lastInsertId(); $normalUser = array("firstName" => $faker->firstName, "middleName" => $faker->name, "lastName" => $faker->lastName, "country" => $faker->countryCode, "language" => $faker->languageCode, "username" => "user", "password" => User::hashPassword("useruser"), "mobile" => $faker->phoneNumber, "addressOne" => $faker->address, "addressTwo" => $faker->address, "city" => $faker->city, "zipCode" => $faker->postcode, "phone" => $faker->phoneNumber, "nationality" => $faker->countryCode, "identificationType" => $faker->word, "identificationNumber" => $faker->numberBetween(999999), "identificationExpiryDate" => $faker->dateTimeBetween('+2 years', '+20 years')->format('Y-m-d H:i:s'), "email" => $faker->freeEmail, "securityQuestion" => $faker->sentence, "securityAnswer" => $faker->sentence, "dateOfBirth" => date('Y-m-d H:i:s'), "photo" => '/upload/images/userdefault.png', "privacyStatement" => true, "studentStatement" => false, "proctorStatement" => false, "instructorStatement" => false, "testCenterAdministratorStatement" => false, "trainingManagerStatement" => false, "status" => true); $this->insert('user', $normalUser); $normalUserId = $this->getAdapter()->getConnection()->lastInsertId(); $userRoles = array(array('user_id' => $adminUserId, 'role_id' => $adminRoleId), array('user_id' => $normalUserId, 'role_id' => $normalUserRoleId)); $this->insert('user_role', $userRoles); }
/** * Create new user * * * @access public * @uses User * @uses UserForm * * @return ViewModel */ public function newAction() { $variables = array(); $query = $this->getServiceLocator()->get('wrapperQuery')->setEntity('Users\\Entity\\User'); $countriesService = $this->getServiceLocator()->get('losi18n-countries'); $languagesService = $this->getServiceLocator()->get('losi18n-languages'); $userModel = $this->getServiceLocator()->get('Users\\Model\\User'); $userObj = new User(); $options = array(); $options['query'] = $query; $locale = "en"; $options['countries'] = $countriesService->getAllCountries($locale); $options['languages'] = $languagesService->getAllLanguages($locale); $options['excludedRoles'] = array(Role::USER_ROLE); $auth = new AuthenticationService(); $storage = $auth->getIdentity(); if (!$auth->hasIdentity() || $auth->hasIdentity() && !in_array(Role::ADMIN_ROLE, $storage['roles'])) { $options['excludedRoles'][] = Role::ADMIN_ROLE; } $isAdminUser = false; if ($auth->hasIdentity() && in_array(Role::ADMIN_ROLE, $storage['roles'])) { $isAdminUser = true; } $form = new UserForm(null, $options); $request = $this->getRequest(); if ($request->isPost()) { // Make certain to merge the files info! $fileData = $request->getFiles()->toArray(); $data = array_merge_recursive($request->getPost()->toArray(), $fileData); $query->setEntity('Users\\Entity\\User'); $form->setInputFilter($userObj->getInputFilter($query)); $form->setData($data); $isCustomValidationValid = true; if ($data['email'] != $data['confirmEmail']) { $form->get('confirmEmail')->setMessages(array("email doesnt match")); $isCustomValidationValid = false; } if ($data['password'] != $data['confirmPassword']) { $form->get('confirmPassword')->setMessages(array("password doesnt match")); $isCustomValidationValid = false; } if ($form->isValid() && $isCustomValidationValid === true) { $userModel->saveUser($data, null, $isAdminUser); if ($isAdminUser) { $url = $this->getEvent()->getRouter()->assemble(array('action' => 'index'), array('name' => 'users')); $this->redirect()->toUrl($url); } else { $variables['success'] = true; } } } $variables['userForm'] = $this->getFormView($form); $statement = new Statement(); $variables['statements'] = $statement->statements; return new ViewModel($variables); }