예제 #1
0
 public function runAction()
 {
     $em = $this->getEntityManager();
     $console = $this->getServiceLocator()->get('console');
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $console->writeLine('建立資料表中, 請稍待!!', ColorInterface::GREEN);
     $classes = $em->getMetadataFactory()->getAllMetadata();
     if ($this->params()->fromRoute('re-create-database')) {
         $schemaTool->dropSchema($classes);
     }
     $schemaTool->createSchema($classes);
     // 安裝預設管理人員及選單
     $username = '******';
     $password = \Zend\Math\Rand::getString(8, null, true);
     $user = new \Base\Entity\User();
     $user->setUsername($username);
     $user->setPassword(\Zend\Ldap\Attribute::createPassword($password));
     $user->setDisplayName('管理者');
     $user->setRole('admin');
     $em->persist($user);
     $em->flush();
     $menu = new \Base\Entity\Menu();
     $menu->setName('首頁');
     $menu->setUser($user);
     $params = ['max_records' => 10, 'order_kind' => 'desc', 'term' => ''];
     $menu->setParams(serialize($params));
     $em->persist($menu);
     $em->flush();
     $console->writeLine('建立完成!!', ColorInterface::GREEN);
     $console->writeLine('預設帳號 ' . $username . ', 密碼 ' . $password, ColorInterface::GREEN);
 }
예제 #2
0
 public function saveAction()
 {
     $jsonModel = new JsonModel();
     if ($this->getRequest()->isPost()) {
         $data = $this->params()->fromPost();
         $em = $this->getEntityManager();
         if (!($userRes = $em->getRepository('Base\\Entity\\User')->find($data['id']))) {
             $userRes = new \Base\Entity\User();
         }
         $form = new UserForm();
         $roleArr = $em->getRepository('Base\\Entity\\User')->getRoleArray();
         $form->get('role')->setValueOptions($roleArr);
         $form->setData($data);
         if ($form->isValid()) {
             $userRes->setDisplayName($data['display_name']);
             $userRes->setUsername($data['username']);
             $userRes->setRole($data['role']);
             $userRes->setPassword(\Zend\Ldap\Attribute::createPassword($data['password']));
             $em->persist($userRes);
             $em->flush();
             $jsonModel->setVariable('success', true);
         } else {
             $jsonModel->setVariable('success', false);
             $jsonModel->setVariable('message', $form->getMessages());
         }
     }
     return $jsonModel;
 }
예제 #3
0
 public function runAction()
 {
     $username = $this->params()->fromRoute('username');
     $password = $this->params()->fromRoute('password');
     $em = $this->getEntityManager();
     $qb = $em->createQueryBuilder()->select('u')->from('Base\\Entity\\User', 'u')->where('u.username=:username')->setParameter('username', $username)->getQuery()->getResult();
     if (count($qb)) {
         $userRes = $qb[0];
     } else {
         $userRes = new \Base\Entity\User();
         $userRes->setUsername($username);
         $userRes->setDisplayName('管理者');
     }
     $userRes->setPassword(\Zend\Ldap\Attribute::createPassword($password));
     $userRes->setRole('admin');
     $em->persist($userRes);
     $em->flush();
     echo "\n {$username} 設定成功 \n ";
 }
예제 #4
0
 public function testPasswordGenerationUnicodePwd()
 {
     $password = '******';
     $unicodePwd = Attribute::createPassword($password, Attribute::PASSWORD_UNICODEPWD);
     $this->assertEquals(10, strlen($unicodePwd));
     $this->assertEquals("\"new\"", $unicodePwd);
 }
예제 #5
0
 public function changePasswordAction()
 {
     $viewModel = new ViewModel();
     $username = $this->getAuthService()->getIdentity()->getUsername();
     $registerForm = new RegisterForm();
     $form = new \Zend\Form\Form('changePasswordForm');
     $form->add($registerForm->get('password'));
     $form->add($registerForm->get('re_password'));
     //  $form->add($registerForm->get('submit')->setAttribute('value', '修改密碼'));
     $accountFilter = new AccountFIlter();
     $filter = new InputFilter();
     $filter->add($accountFilter->get('password'))->add($accountFilter->get('re_password'));
     $form->setInputFilter($filter);
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $form->setData($data);
         if ($form->isValid()) {
             $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
             $user = $em->getRepository('Base\\Entity\\User')->findOneBy(array('username' => $username));
             if ($user) {
                 //$user->setPassword(md5($form->get('password')->getValue()));
                 $user->setPassword(\Zend\Ldap\Attribute::createPassword($form->get('password')->getValue()));
                 $em->persist($user);
                 $em->flush();
                 $this->getServiceLocator()->get('Zend\\Log')->info($username . ' changed password');
                 $this->flashMessenger()->addSuccessMessage('更改密碼成功!');
                 return $this->redirect()->refresh();
             }
         }
     }
     $viewModel->setVariable('form', $form);
     return $viewModel;
 }
예제 #6
0
 private function write($isUpdate = false, $employeeNumber = null)
 {
     // Get the request body (prepared by \Slim\Middleware\ContentTypes)
     $env = $this->app->environment();
     $data = $env['slim.input'];
     if ($data === '{}') {
         $data = array();
     }
     // Build the entry
     $entry = $this->formatJsonForEntry($data);
     $entry['objectClass'] = array('person', 'organizationalPerson', 'inetOrgPerson', 'personMailDelivery');
     $entry['employeeNumber'] = $isUpdate === false ? $this->ldap->getUUID('employeeNumber') : $employeeNumber;
     // Validate the data
     $dn = $this->assertValidEntry($entry, $isUpdate);
     unset($entry['passwordConfirmation']);
     if (isset($entry['userPassword'])) {
         $entry['userPassword'] = Attribute::createPassword($entry['userPassword'], Attribute::PASSWORD_HASH_SSHA);
     }
     // Adi/Update to LDAP
     if ($isUpdate !== true) {
         $this->ldap->add($dn, $entry);
     } else {
         $this->ldap->update($dn, $entry);
     }
     // Return the created/updated entry
     $this->getById($entry['employeeNumber']);
 }
예제 #7
0
 public function testPasswordGenerationUnicodePwd()
 {
     $password = '******';
     $unicodePwd = Ldap\Attribute::createPassword($password, Ldap\Attribute::PASSWORD_UNICODEPWD);
     $this->assertEquals(10, strlen($unicodePwd));
     $this->assertEquals("\x22\x00\x6E\x00\x65\x00\x77\x00\x22\x00", $unicodePwd);
 }
예제 #8
0
파일: User.php 프로젝트: hamichen/CMS
 public static function hashPassword($player, $password)
 {
     return $player->getPassword() === \Zend\Ldap\Attribute::createPassword($password);
 }