예제 #1
0
 public function findmentorAction()
 {
     if (!$this->getRequest()->isPost()) {
         return $this->page404();
     }
     $data = $this->getRequest()->getPost();
     $form = new SearchDetail($this->getServiceLocator());
     $form->setData($data);
     if ($form->isValid()) {
         $user = new User();
         $user->setEmail($data['email']);
         $activeKey = md5($user->getEmail() . DateBase::getCurrentDateTime());
         $user->setActiveKey($activeKey);
         $user->setRole(User::ROLE_MEMBER);
         $user->setCreatedDateTime(DateBase::getCurrentDateTime());
         $user->setCreatedDate(DateBase::getCurrentDate());
         /** @var \User\Model\UserMapper $userMapper */
         $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
         if (!$userMapper->isExistedEmail($user)) {
             $userMapper->save($user);
             Uri::autoLink('/user/user/sendemail', ['email' => $data['email'], 'activeKey' => $user->getActiveKey()]);
             $this->getJsonModel()->setVariables(['code' => 2, 'data' => 'Email kích hoạt tài khoản đã được gửi đến địa chỉ email của bạn. Kiểm tra hòm thư và làm theo hướng dẫn đễ kích hoạt tài khoản.']);
             return $this->getJsonModel();
         }
         return $this->getViewModel();
     } else {
         $this->getJsonModel()->setVariables(['code' => 1, 'data' => $form->getErrorMessagesList()]);
     }
     return $this->getJsonModel();
 }
예제 #2
0
 public function insert(UserModel $user)
 {
     $data = array('user_id' => $user->getUserId(), 'email' => $user->getEmail(), 'display_name' => $user->getDisplayName(), 'password' => $user->getPassword(), 'salt' => $user->getSalt(), 'register_time' => new Expr('NOW()'), 'register_ip' => new Expr("INET_ATON('{$_SERVER['REMOTE_ADDR']}')"));
     $db = $this->getWriteAdapter();
     $db->insert($this->getTableName(), $data);
     $userId = $db->lastInsertId();
     $user->setUserId($userId);
     return $user;
 }
예제 #3
0
 public function testUserInitialState()
 {
     $user = new User();
     $this->assertNull($user->getLidnr());
     $this->assertNull($user->getEmail());
     $this->assertNull($user->getPassword());
     $this->assertNull($user->getMember());
     $this->assertEmpty($user->getRoleNames());
     $this->assertEquals('user_', $user->getRoleId());
     $this->assertEquals('user', $user->getResourceId());
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $user->getRoles());
     $this->assertEquals(0, count($user->getRoles()));
 }
예제 #4
0
 public function signupemailAction()
 {
     $viewModels = new ViewModel();
     if (!$this->getRequest()->isPost()) {
         $viewModels->setTemplate('error/404');
         return $viewModels;
     }
     if ($this->getRequest()->isPost()) {
         $email = $this->getRequest()->getPost('email');
         $user = new User();
         $user->setEmail($email);
         $activeKey = md5($user->getEmail() . DateBase::getCurrentDateTime());
         $user->setActiveKey($activeKey);
         $user->setRole(User::ROLE_MEMBER);
         $user->setCreatedDateTime(DateBase::getCurrentDateTime());
         $user->setCreatedDate(DateBase::getCurrentDate());
         /** @var \User\Model\UserMapper $userMapper */
         $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
         $jsonModel = new JsonModel();
         if (!$userMapper->isExistedEmail($user)) {
             $userMapper->save($user);
             Uri::autoLink('/user/user/sendemail', ['email' => $email, 'activeKey' => $user->getActiveKey()]);
             $jsonModel->setVariables(['code' => 2, 'data' => 'Email kích hoạt tài khoản đã được gửi đến địa chỉ email của bạn. Kiểm tra hòm thư và làm theo hướng dẫn đễ kích hoạt tài khoản.']);
         } else {
             $jsonModel->setVariables(['code' => 1, 'data' => 'Email này đã được đăng ký, bạn vui lòng đăng nhập.']);
         }
     }
     return $jsonModel;
 }
예제 #5
0
 /**
  * @return array|null
  * @param \User\Model\User $user
  */
 public function isActive($user)
 {
     if (!$user->getEmail()) {
         return null;
     }
     $select = $this->getDbSql()->select(array('u' => self::TABLE_NAME));
     if ($this->isExistedEmail($user)) {
         $select->where(['active IS NULL']);
     }
     $select->limit(1);
     $query = $this->getDbSql()->buildSqlString($select);
     $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE);
     if ($results->count()) {
         $data = $results->current();
         $user->exchangeArray((array) $results->current());
         return false;
     }
     return true;
 }
예제 #6
0
 /**
  * @param \User\Model\User $user
  * @return boolean
  */
 public function updateUser(\User\Model\User $user)
 {
     if (!$user->getId() && !$user->getEmail() && !$user->getUsername()) {
         return false;
     }
     /* @var $userMapper \User\Model\UserMapper */
     $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
     if ($user->getPassword()) {
         $user->setSalt(substr(md5(rand(2000, 5000) . time() . rand(2000, 5000)), 0, 20));
         $user->setPassword(md5($user->getSalt() . $user->getPassword()));
     }
     return $userMapper->updateUser($user);
 }
예제 #7
0
파일: User.php 프로젝트: venril/blogger3
 public function update(UserModel $user)
 {
     $sql = 'UPDATE user SET
             email=:email,
             username=:username,
             password=:password,
             firstname=:firstname,
             lastname=:lastname,
             birthdate=:birthdate,
             isActive=:isActive
             WHERE id=:id
            ';
     $this->getDb()->beginTransaction();
     try {
         $stmt = $this->getDb()->prepare($sql);
         $stmt->execute(array('email' => $user->getEmail(), 'username' => $user->getUsername(), 'password' => $user->getPassword(), 'firstname' => $user->getFirstname(), 'lastname' => $user->getLastname(), 'birthdate' => $user->getBirthdate()->format('Y-m-d'), 'isActive' => $user->getIsActive(), 'id' => (int) $user->getId()));
         $this->getDb()->commit();
     } catch (PDOException $e) {
         $this->getDb()->rollBack();
         throw $e;
     }
 }
예제 #8
0
파일: User.php 프로젝트: venril/blogger2
 public function insert(UserModel $user)
 {
     $sql = 'INSERT INTO user VALUES (' . 'NULL, ' . "'" . $user->getEmail() . "'," . "'" . $user->getUsername() . "'," . "'" . $user->getPassword() . "'," . "'" . $user->getFirstname() . "'," . "'" . $user->getLastname() . "'," . "'" . $user->getBirthdate()->format('Y-m-d') . "'," . "'" . (int) $user->getIsActive() . "'" . ")";
     echo $sql;
     $this->getDb()->exec($sql);
 }
예제 #9
0
 /**
  *
  * @param \User\Model\User $item
  * @param unknown $options
  */
 public function search($item, $options)
 {
     $select = $this->getDbSql()->select(array('u' => self::TABLE_NAME));
     if ($item->getId()) {
         $select->where(['u.id' => $item->getId()]);
     }
     if ($item->getUsername()) {
         $select->where(['(u.username LIKE ? OR u.fullName LIKE ?)' => ['%' . $item->getUsername() . '%', '%' . $item->getUsername() . '%']]);
     }
     if ($item->getEmail()) {
         $select->where(['(u.email LIKE ?)' => '%' . $item->getEmail() . '%']);
     }
     if ($item->getActive()) {
         if ($item->getActive() > 0) {
             $select->where(['u.active' => 1]);
         } else {
             $select->where(['(u.active IS NULL OR u.active != ?)' => 1]);
         }
     }
     if ($item->getRole()) {
         $select->where(['u.role' => $item->getRole()]);
     }
     $select->order(['u.id' => 'DESC']);
     /* $query = $this->getDbSql()->buildSqlString($select);
        vdump($query);die; */
     $paginator = $this->preparePaginator($select, $options, new User());
     $userIds = [];
     $districIds = [];
     $cityIds = [];
     $ids = [];
     foreach ($paginator as $user) {
         /*@var $user \User\Model\User */
         if ($user->getCreatedById()) {
             $userIds[$user->getCreatedById()] = $user->getCreatedById();
         }
         if ($user->getDistrictId()) {
             $districIds[$user->getDistrictId()] = $user->getDistrictId();
         }
         if ($user->getCityId()) {
             $cityIds[$user->getCityId()] = $user->getCityId();
         }
         $ids[] = $user->getId();
     }
     $dbAdapter = $this->getDbAdapter();
     $users = [];
     if (count($userIds)) {
         $select = $this->getDbSql()->select(array('u' => self::TABLE_NAME));
         $select->where(['u.id' => $userIds]);
         $query = $this->getDbSql()->buildSqlString($select);
         $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
         if ($rows->count()) {
             foreach ($rows as $row) {
                 $createdBy = new User();
                 $createdBy->exchangeArray((array) $row);
                 $users[$createdBy->getId()] = $createdBy;
             }
         }
     }
     $cities = [];
     if (count($cityIds)) {
         $select = $this->getDbSql()->select(array('c' => \Address\Model\CityMapper::TABLE_NAME));
         $select->where(['id' => $cityIds]);
         $query = $this->getDbSql()->buildSqlString($select);
         $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
         if ($rows->count()) {
             foreach ($rows as $row) {
                 $city = new \Address\Model\City();
                 $city->exchangeArray((array) $row);
                 $cities[$city->getId()] = $city;
             }
         }
     }
     $districs = [];
     if (count($districIds)) {
         $select = $this->getDbSql()->select(array('c' => \Address\Model\DistrictMapper::TABLE_NAME));
         $select->where(['id' => $districIds]);
         $query = $this->getDbSql()->buildSqlString($select);
         $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
         if ($rows->count()) {
             foreach ($rows as $row) {
                 $distric = new \Address\Model\District();
                 $distric->exchangeArray((array) $row);
                 $districs[$distric->getId()] = $distric;
             }
         }
     }
     if (count($paginator->getCurrentModels())) {
         foreach ($paginator->getCurrentModels() as $user) {
             if ($user->getCreatedById() && isset($users[$user->getCreatedById()])) {
                 $user->addOption('createdBy', $users[$user->getCreatedById()]);
             }
             if ($user->getCityId() && isset($cities[$user->getCityId()])) {
                 $user->setCity($cities[$user->getCityId()]);
             }
             if ($user->getDistrictId() && isset($districs[$user->getDistrictId()])) {
                 $user->setDistrict($districs[$user->getDistrictId()]);
             }
         }
     }
     return $paginator;
 }
예제 #10
0
 /**
  *
  */
 public function getactivecodeAction()
 {
     /** @var \Zend\Http\Request $request */
     $request = $this->getRequest();
     $sl = $this->getServiceLocator();
     /* @var $userMapper \User\Model\UserMapper() */
     $userMapper = $sl->get('User\\Model\\UserMapper');
     /* @var $userService \User\Service\User() */
     $userService = $sl->get('User\\Service\\User');
     /* @var $form \User\Form\GetActiveCode() */
     $form = $sl->get('User\\Form\\GetActiveCode');
     $form->setInputFilter($sl->get('User\\Form\\GetActiveCodeFilter'));
     $message = '';
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $validator = new \Zend\Validator\EmailAddress();
             $user = new User();
             $translator = $sl->get('translator');
             if ($validator->isValid($request->getPost('inputStr')) && $request->getPost('captcha')) {
                 $user->setEmail($request->getPost('inputStr'));
             } else {
                 $user->setUsername($request->getPost('inputStr'));
             }
             $us = $userMapper->get(null, $user->getUsername(), $user->getEmail());
             if (!$us) {
                 $message = '<p class="error">' . $translator->translate('Địa chỉ email hoặc tên đăng nhập không chính xác') . '</p>';
             } else {
                 if ($us->getActive() != null) {
                     $message = '<p class="error">' . $translator->translate('Tài khoản của bạn đã được kích hoạt') . '</p>';
                 } else {
                     $userService->sendActiveLink($user);
                     $message = '<p>' . $translator->translate('Xác nhận gửi lại link kích hoạt tài khoản thành công, vui lòng kiểm tra lại địa chỉ email của bạn để nhận link kích hoạt tài khoản') . '</p>';
                 }
             }
         }
     }
     $viewModel = new ViewModel(array('form' => $form, 'message' => $message));
     return $viewModel;
 }