public function registerAction(Request $request) { /****Check language session*******/ $session = $request->getSession(); $this->langsession($session); $lan = $session->get('language'); $request->setLocale($lan); $twitter = $session->get('twittercontent'); if (empty($twitter)) { return $this->redirect($this->generateUrl('mytrip_user_homepage')); } $em = $this->getDoctrine()->getManager(); if ($request->getMethod() == "POST") { $emailcheck = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.email='" . $request->request->get('email') . "' AND p.status NOT IN ('Trash')")->getArrayResult(); if (empty($emailcheck)) { $randno = sha1($this->str_rand() . date('Y-m-d H:i:s')); $password = $this->str_rand(6); $member = new \Mytrip\AdminBundle\Entity\User(); $member->setFirstname($twitter->name); $member->setLastname(' '); $member->setEmail($request->request->get('email')); $member->setPassword(sha1($password)); $member->setLan($lan); $member->setUserKey($randno); $member->setStatus('Active'); $member->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $member->setModifyDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($member); $em->flush(); $uid = $member->getUserId(); $social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink(); $social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid)); $social_links->setSocialLink('Twitter'); $social_links->setId($twitter->id); $social_links->setImage($twitter->profile_image_url); $em->persist($social_links); $em->flush(); $user = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.userId='" . $uid . "'")->getArrayResult(); $session->set('user', $user[0]); $session->set('UserLogin', "True"); $emaillist = $em->getRepository('MytripAdminBundle:EmailList')->findOneBy(array('emailListId' => '14')); $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '14', 'lan' => $lan)); if (!empty($emailcontent)) { $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '14', 'lan' => 'en')); } $link = $this->getRequest()->getSchemeAndHttpHost() . $this->generateUrl('mytrip_user_confirm') . "?u_my_code=" . $randno . "_" . sha1($uid); //$message=str_replace(array('{name}','{username}','{password}','{link}'),array($user[0]['firstname'].' '.$user[0]['lastname'],$user[0]['email'],$password,$link),$emailcontent->getEmailContent()); $message = str_replace(array('{name}', '{link}'), array($twitter->name, $link), $emailcontent->getEmailContent()); $subject = str_replace(array('{name}', '{link}'), array($twitter->name, $link), $emailcontent->getSubject()); /*******Contact mail send to admin***********/ $this->mailsend($emaillist->getFromname(), $emaillist->getFromemail(), $user[0]['email'], $subject, $message, $emaillist->getCcmail()); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Successfully Registered. Confirmation link sent to your mail id.')); return $this->redirect($this->generateUrl('mytrip_user_profile')); } else { $uid = $emailcheck[0]['userId']; $check_social_link = $em->createQuery("SELECT p FROM MytripAdminBundle:UserSocialLink p WHERE p.user='******' AND p.socialLink='Twitter' AND p.id='" . $twitter->id . "'")->getArrayResult(); if (empty($check_social_link)) { $social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink(); $social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid)); $social_links->setSocialLink('Twitter'); $social_links->setId($twitter->id); $social_links->setImage($twitter->profile_image_url); $em->persist($social_links); $em->flush(); } $user = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.userId='" . $uid . "'")->getArrayResult(); $session->set('user', $user[0]); $session->set('UserLogin', "True"); return $this->redirect($this->generateUrl('mytrip_user_profile')); } } return $this->redirect($this->generateUrl('mytrip_user_homepage')); }
public function indexAction(Request $request) { /****Check language session*******/ $session = $request->getSession(); $this->langsession($session); $lan = $session->get('language'); $request->setLocale($lan); $username = $session->get('user'); $em = $this->getDoctrine()->getManager(); $appkey = $this->container->get('mytrip_admin.helper.google')->getOption('apikey'); $appsecretkey = $this->container->get('mytrip_admin.helper.google')->getOption('apisecretkey'); $developerkey = $this->container->get('mytrip_admin.helper.google')->getOption('developerkey'); $product = $this->container->get('mytrip_admin.helper.google')->getOption('productname'); $redirect_url = $this->getRequest()->getSchemeAndHttpHost() . $this->generateUrl('mytrip_user_google'); $gClient = new \Google_Client(); $gClient->setApplicationName($product); $gClient->setClientId($appkey); $gClient->setClientSecret($appsecretkey); $gClient->setRedirectUri($redirect_url); $gClient->setDeveloperKey($developerkey); $google_oauthV2 = new \Google_Oauth2Service($gClient); if (isset($_REQUEST['reset'])) { $session->remove('token'); //unset($_SESSION['token']); $gClient->revokeToken(); return $this->redirect(filter_var($redirect_url, FILTER_SANITIZE_URL)); //header('Location: ' . filter_var($google_redirect_url, FILTER_SANITIZE_URL)); //redirect user back to page } if (isset($_GET['code'])) { $gClient->authenticate($_GET['code']); $session->set('token', $gClient->getAccessToken()); return $this->redirect(filter_var($redirect_url, FILTER_SANITIZE_URL)); } if ($session->get('token')) { $gClient->setAccessToken($session->get('token')); } if ($gClient->getAccessToken()) { //For logged in user, get details from google using access token $user = $google_oauthV2->userinfo->get(); $user_id = $user['id']; $user_name = filter_var($user['name'], FILTER_SANITIZE_SPECIAL_CHARS); $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL); $profile_url = filter_var($user['link'], FILTER_VALIDATE_URL); $profile_image_url = filter_var($user['picture'], FILTER_VALIDATE_URL); $personMarkup = "{$email}<div><img src='{$profile_image_url}?sz=50'></div>"; $session->set('token', $gClient->getAccessToken()); if (empty($username)) { $emailcheck = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.email='" . $email . "' AND p.status NOT IN ('Trash')")->getArrayResult(); if (empty($emailcheck)) { $randno = sha1($this->str_rand() . date('Y-m-d H:i:s')); $password = $this->str_rand(6); $member = new \Mytrip\AdminBundle\Entity\User(); $member->setFirstname($user_name); $member->setLastname(' '); $member->setEmail($email); $member->setPassword(sha1($password)); $member->setLan($lan); $member->setUserKey($randno); $member->setStatus('Active'); $member->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $member->setModifyDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($member); $em->flush(); $uid = $member->getUserId(); $social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink(); $social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid)); $social_links->setSocialLink('Google'); $social_links->setId($user_id); $social_links->setImage($profile_image_url); $social_links->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($social_links); $em->flush(); $user = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.userId='" . $uid . "'")->getArrayResult(); $session->set('user', $user[0]); $session->set('UserLogin', "True"); $emaillist = $em->getRepository('MytripAdminBundle:EmailList')->findOneBy(array('emailListId' => '14')); $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '14', 'lan' => $lan)); if (!empty($emailcontent)) { $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '14', 'lan' => 'en')); } $link = $this->getRequest()->getSchemeAndHttpHost() . $this->generateUrl('mytrip_user_confirm') . "?u_my_code=" . $randno . "_" . sha1($uid); $message = str_replace(array('{name}', '{link}'), array($user[0]['firstname'] . ' ' . $user[0]['lastname'], $link), $emailcontent->getEmailContent()); //$message=str_replace(array('{name}','{username}','{password}','{link}'),array($user_name,$email,$password,$link),$emailcontent->getEmailContent()); $subject = str_replace(array('{name}', '{link}'), array($user[0]['firstname'] . ' ' . $user[0]['lastname'], $link), $emailcontent->getSubject()); /*******Contact mail send to admin***********/ $this->mailsend($emaillist->getFromname(), $emaillist->getFromemail(), $user[0]['email'], $subject, $message, $emaillist->getCcmail()); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Successfully Registered. Confirmation link sent to your mail id.')); return $this->redirect($this->generateUrl('mytrip_user_profile')); } else { $uid = $emailcheck[0]['userId']; $check_social_link = $em->createQuery("SELECT p FROM MytripAdminBundle:UserSocialLink p WHERE p.user='******' AND p.socialLink='Google' AND p.id='" . $user_id . "'")->getArrayResult(); if (empty($check_social_link)) { $social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink(); $social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid)); $social_links->setSocialLink('Google'); $social_links->setId($user_id); $social_links->setImage($profile_image_url); $social_links->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($social_links); $em->flush(); } $user = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.userId='" . $uid . "'")->getArrayResult(); $session->set('user', $user[0]); $session->set('UserLogin', "True"); return $this->redirect($this->generateUrl('mytrip_user_profile')); } } else { $uid = $username['userId']; $check_social_link = $em->createQuery("SELECT p FROM MytripAdminBundle:UserSocialLink p WHERE p.user='******' AND p.socialLink='Google' AND p.id='" . $user_profile['id'] . "'")->getArrayResult(); if (empty($check_social_link)) { $social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink(); $social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid)); $social_links->setSocialLink('Google'); $social_links->setId($user_id); $social_links->setImage($profile_image_url); $social_links->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($social_links); $em->flush(); } return $this->redirect($this->generateUrl('mytrip_user_profile')); } } else { //For Guest user, get google login url $authUrl = $gClient->createAuthUrl(); return $this->redirect($authUrl); } }
public function indexAction(Request $request) { /****Check language session*******/ $session = $request->getSession(); $this->langsession($session); $lan = $session->get('language'); $request->setLocale($lan); $username = $session->get('user'); $em = $this->getDoctrine()->getManager(); $appkey = $this->container->get('mytrip_admin.helper.facebook')->getOption('apikey'); $appsecretkey = $this->container->get('mytrip_admin.helper.facebook')->getOption('apisecretkey'); \Facebook::setAuth(array('appId' => $appkey, 'secret' => $appsecretkey)); // Get User ID $user = \Facebook::getUser(); if (isset($_REQUEST['error'])) { $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Sorry, Please try again')); if (empty($username)) { return $this->redirect($this->generateUrl('mytrip_user_homepage')); } else { return $this->redirect($this->generateUrl('mytrip_user_profile')); } } if (!empty($user)) { $user_profile = \Facebook::api('/me'); $userimage = "https://graph.facebook.com/" . $user_profile['id'] . "/picture?type=large"; if (empty($username)) { $emailcheck = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.email='" . $user_profile['email'] . "' AND p.status NOT IN ('Trash')")->getArrayResult(); if (empty($emailcheck)) { $randno = sha1($this->str_rand() . date('Y-m-d H:i:s')); $password = $this->str_rand(6); $member = new \Mytrip\AdminBundle\Entity\User(); $member->setFirstname($user_profile['first_name']); $member->setLastname($user_profile['last_name']); $member->setEmail($user_profile['email']); $member->setGender($user_profile['gender']); $member->setPassword(sha1($password)); $member->setLan($lan); $member->setUserKey($randno); $member->setStatus('Active'); $member->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $member->setModifyDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($member); $em->flush(); $uid = $member->getUserId(); $social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink(); $social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid)); $social_links->setSocialLink('Facebook'); $social_links->setId($user_profile['id']); $social_links->setImage($userimage); $social_links->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($social_links); $em->flush(); $user = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.userId='" . $uid . "'")->getArrayResult(); $session->set('user', $user[0]); $session->set('UserLogin', "True"); $emaillist = $em->getRepository('MytripAdminBundle:EmailList')->findOneBy(array('emailListId' => '14')); $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '14', 'lan' => $lan)); if (!empty($emailcontent)) { $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '14', 'lan' => 'en')); } $link = $this->getRequest()->getSchemeAndHttpHost() . $this->generateUrl('mytrip_user_confirm') . "?u_my_code=" . $randno . "_" . sha1($uid); //$message=str_replace(array('{name}','{username}','{password}','{link}'),array($user[0]['firstname'].' '.$user[0]['lastname'],$user[0]['email'],$password,$link),$emailcontent->getEmailContent()); $message = str_replace(array('{name}', '{link}'), array($user_profile['first_name'] . ' ' . $user_profile['last_name'], $link), $emailcontent->getEmailContent()); $subject = str_replace(array('{name}', '{link}'), array($user_profile['first_name'] . ' ' . $user_profile['last_name'], $link), $emailcontent->getSubject()); /*******Contact mail send to admin***********/ $this->mailsend($emaillist->getFromname(), $emaillist->getFromemail(), $user[0]['email'], $subject, $message, $emaillist->getCcmail()); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Successfully Registered. Confirmation link sent to your mail id.')); return $this->redirect($this->generateUrl('mytrip_user_profile')); } else { $uid = $emailcheck[0]['userId']; $check_social_link = $em->createQuery("SELECT p FROM MytripAdminBundle:UserSocialLink p WHERE p.user='******' AND p.socialLink='Facebook' AND p.id='" . $user_profile['id'] . "'")->getArrayResult(); if (empty($check_social_link)) { $social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink(); $social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid)); $social_links->setSocialLink('Facebook'); $social_links->setId($user_profile['id']); $social_links->setImage($userimage); $social_links->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($social_links); $em->flush(); } $user = $em->createQuery("SELECT p FROM MytripAdminBundle:User p WHERE p.userId='" . $uid . "'")->getArrayResult(); $session->set('user', $user[0]); $session->set('UserLogin', "True"); return $this->redirect($this->generateUrl('mytrip_user_profile')); } } else { $uid = $username['userId']; $check_social_link = $em->createQuery("SELECT p FROM MytripAdminBundle:UserSocialLink p WHERE p.user='******' AND p.socialLink='Facebook' AND p.id='" . $user_profile['id'] . "'")->getArrayResult(); if (empty($check_social_link)) { $social_links = new \Mytrip\AdminBundle\Entity\UserSocialLink(); $social_links->setUser($this->getDoctrine()->getRepository('MytripAdminBundle:User')->find($uid)); $social_links->setSocialLink('Facebook'); $social_links->setId($user_profile['id']); $social_links->setImage($userimage); $social_links->setCreatedDate(new \DateTime(date('Y-m-d H:i:s'))); $em->persist($social_links); $em->flush(); } return $this->redirect($this->generateUrl('mytrip_user_profile')); } } else { $loginUrl = \Facebook::getLoginUrl(array('scope' => 'email')); return $this->redirect($loginUrl); } }