Esempio n. 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();
 }
Esempio n. 2
0
 /**
  * active user
  */
 public function activeaccountAction()
 {
     /** @var \Zend\Http\Request $request */
     $request = $this->getRequest();
     $email = $request->getQuery('u');
     $activeKey = $request->getQuery('c');
     if (!$email || !$activeKey) {
         $this->redirect()->toUrl('/');
     }
     $form = new ActiveAccount();
     /* @var $userMapper \User\Model\UserMapper */
     $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
     /** @var \User\Model\User $user */
     $user = new User();
     $translator = $this->getServiceLocator()->get('translator');
     $user->setActiveKey($activeKey);
     $user->setEmail($email);
     $user = $userMapper->getUserNotActive($user);
     $viewModel = new ViewModel();
     if (!$user) {
         return $viewModel->setTemplate('error/404');
     }
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $form->setData($data);
         if ($form->isValid()) {
             $user->exchangeArray((array) $data);
             $user->setActiveKey(null);
             /** @var \User\Service\User $userService */
             $userService = $this->getServiceLocator()->get('User\\Service\\User');
             $userService->signup($user);
             vdump($user);
             die;
             if ($userService->authenticate($user->getEmail(), $data['password'])) {
                 return $this->forward()->dispatch('Home\\Controller\\Index', ['action' => 'index', 'user' => $user]);
             }
         }
     }
     $viewModel->setVariables(['email' => $email]);
     $viewModel->setVariables(['form' => $form]);
     return $viewModel;
 }
Esempio n. 3
0
 /**
  * @param \User\Model\User $user
  */
 public function signup(\User\Model\User $user)
 {
     $user->setSalt(substr(md5(time() . rand(2000, 5000)), 0, 20));
     $user->setCreatedDate(DateBase::getCurrentDate());
     $user->setCreatedDateTime(DateBase::getCurrentDateTime());
     $user->setPassword(md5($user->getSalt() . $user->getPassword()));
     $user->setRegisteredDate(date('Y-m-d'));
     $user->setRegisteredFrom(str_replace('www.', '', strtolower($_SERVER['HTTP_HOST'])));
     $user->setActiveKey(md5($user->getUsername() . $user->getPassword() . time()));
     $user->setActiveLink('http://' . $_SERVER['HTTP_HOST'] . '/user/active?u=' . $user->getUsername() . '&c=' . $user->getActiveKey());
     $user->setRole(\User\Model\User::ROLE_MEMBER);
     $sl = $this->getServiceLocator();
     $translator = $this->getServiceLocator()->get('translator');
     /** @var $mapper \User\Model\UserMapper */
     $mapper = $sl->get('User\\Model\\Usermapper');
     $mapper->save($user);
 }
 /**
  * active user
  */
 public function activeAction()
 {
     /** @var \Zend\Http\Request $request */
     $request = $this->getRequest();
     $userName = $request->getQuery('u');
     $activeKey = $request->getQuery('c');
     if (!$userName || !$activeKey) {
         $this->redirect()->toUrl('/');
     }
     /* @var $userMapper \User\Model\UserMapper */
     $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
     $user = new User();
     $translator = $this->getServiceLocator()->get('translator');
     $user->setActiveKey($activeKey);
     $user->setUsername($userName);
     if ($userMapper->activeUser($user)) {
         $message = '<p class="success">' . $translator->translate('Chúc mừng bạn đã kích hoạt tài khoản thành công') . '</p>';
     } else {
         $message = '<p class="error">' . $translator->translate('Tài khoản đã được kích hoạt hoặc không tồn tại') . '</p>';
     }
     return new ViewModel(array('message' => $message));
 }