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();
 }
 public function googleAction()
 {
     $request = $this->getRequest();
     if (trim($request->getQuery('redirect'))) {
         $_SESSION['redirect'] = trim($request->getQuery('redirect'));
     }
     $viewModel = new ViewModel();
     $viewModel->setTerminal(true);
     $response = $this->getResponse();
     /* @var $googleLogin \User\Service\GoogleLogin */
     require_once 'Google/Client.php';
     require_once 'Google/Service/Oauth2.php';
     require_once 'Google/Http/REST.php';
     require_once 'Google/Http/Request.php';
     require_once 'Google/Service/Resource.php';
     require_once 'Google/Auth/OAuth2.php';
     $config = $this->getServiceLocator()->get('Config');
     $clientId = $config['login']['google']['clientId'];
     $clientSecret = $config['login']['google']['clientSecret'];
     $url = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
     $url .= $_SERVER['HTTP_HOST'] . '/user/signin/google';
     $client = new \Google_Client();
     $client->setApplicationName('MyFirstTest');
     $client->setClientId($clientId);
     $client->setClientSecret($clientSecret);
     $client->setRedirectUri($url);
     $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/plus.me'));
     $error = $this->getRequest()->getQuery('error');
     if ($error) {
         echo '<script>window.close()</script>';
     }
     $code = $this->getRequest()->getQuery('code');
     if ($code) {
         $client->authenticate($code);
         $_SESSION['access_token'] = $client->getAccessToken();
         $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
         header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
     } else {
         $authUrl = $client->createAuthUrl();
         return $this->redirect()->toUrl(filter_var($authUrl, FILTER_SANITIZE_URL));
     }
     //TODO: xoa vi cam giac dau co can
     if (isset($_SESSION['access_token'])) {
         $client->setAccessToken($_SESSION['access_token']);
     }
     if ($client->isAccessTokenExpired()) {
         $authUrl = $client->createAuthUrl();
         return $this->redirect()->toUrl(filter_var($authUrl, FILTER_SANITIZE_URL));
     }
     //End TODO
     if ($client->getAccessToken()) {
         $oauth2 = new \Google_Service_Oauth2($client);
         $userInfoPlus = $oauth2->userinfo->get();
         $_SESSION['access_token'] = $client->getAccessToken();
         if (!$userInfoPlus->getEmail()) {
             echo '<script>window.opener.alert("Không tồn tại thông tin Email của tài khoản trên");window.close()</script>';
         }
         $arrResponse = array('email' => $userInfoPlus->getEmail(), 'name' => $userInfoPlus->getName());
         $user = new User();
         $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
         $serviceUser = $this->getServiceLocator()->get('User\\Service\\User');
         if (!$serviceUser->authenticateGoogle($arrResponse['email'])) {
             $user->setActive('1');
             $user->setEmail($arrResponse['email']);
             $user->setRole(\User\Model\User::ROLE_MEMBER);
             $user->setFullName($arrResponse['name']);
             $user->setCreatedDate(DateBase::getCurrentDate());
             $user->setCreatedDateTime(DateBase::getCurrentDateTime());
             $userMapper->save($user);
             // check nếu user đó đã dc mời tham gia dự án sẽ gắn luôn nó với dự án
             $projectUser = new \Work\Model\ProjectUser();
             $projectUser->setUserEmail($user->getEmail());
             $projectUser->setUserId($user->getId());
             $projectUserMapper = $this->getServiceLocator()->get('\\Work\\Model\\ProjectUserMapper');
             $projectUserMapper->updateUserId($projectUser);
             $this->redirect()->toUrl($url);
         } else {
             // check nếu user đó đã dc mời tham gia dự án sẽ gắn luôn nó với dự án
             $projectUser = new \Work\Model\ProjectUser();
             $projectUser->setUserEmail($serviceUser->getUser()->getEmail());
             $projectUser->setUserId($serviceUser->getUser()->getId());
             $projectUserMapper = $this->getServiceLocator()->get('\\Work\\Model\\ProjectUserMapper');
             $projectUserMapper->updateUserId($projectUser);
             if (!$_SESSION['redirect']) {
                 return $this->redirect()->toUrl('/');
             } else {
                 $redirect = $_SESSION['redirect'];
                 unset($_SESSION['redirect']);
                 return $this->redirect()->toUrl($redirect);
             }
         }
     } else {
         $this->redirect()->toUrl($client->createAuthUrl());
     }
     return $response;
 }
Beispiel #3
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;
 }
Beispiel #4
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);
 }
 public function addAction()
 {
     /** @var \Zend\Http\Request $request */
     $request = $this->getRequest();
     $sl = $this->getServiceLocator();
     /* @var $cityMapper \Address\Model\CityMapper */
     $cityMapper = $sl->get('Address\\Model\\CityMapper');
     $city = new \Address\Model\City();
     /* @var $districtMapper \Address\Model\DistrictMapper */
     $districtMapper = $sl->get('Address\\Model\\DistrictMapper');
     $district = new \Address\Model\District();
     $districts = array();
     if (!!($cityId = $request->getPost('cityId'))) {
         $district->setCityId($cityId);
         $districts = $districtMapper->fetchAll($district);
     }
     $form = new \System\Form\User\Add($this->getServiceLocator());
     $form->setCities($city->toSelectBoxArray($cityMapper->fetchAll()));
     $form->setDistricts($district->toSelectBoxArray($districts));
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $form->setData($data);
         if ($form->isValid()) {
             $user = new User();
             $user->exchangeArray($form->getData());
             $user->setSalt($user->generateSalt());
             $user->setPassword($user->createPassword());
             if (!$user->getRole()) {
                 $user->setRole(User::ROLE_GUEST);
             }
             if ($user->getBirthdate()) {
                 $user->setBirthdate(DateBase::toCommonDate($user->getBirthdate()));
             }
             $user->setActive(1);
             $user->setCreatedById($this->user()->getIdentity());
             $user->setCreatedDate(DateBase::getCurrentDate());
             $user->setCreatedDateTime(DateBase::getCurrentDateTime());
             $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper');
             $userMapper->save($user);
             if ($form->get('afterSubmit')->getValue()) {
                 return $this->redirect()->toUrl($form->get('afterSubmit')->getValue());
             }
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setVariable('form', $form);
     return $viewModel;
 }