public function indexAction() { $linkedIn = new LinkedIn($this->getServiceLocator()->get('config')['linkedin_keys']['aapId'], $this->getServiceLocator()->get('config')['linkedin_keys']['app_secret']); if ($linkedIn->isAuthenticated()) { //we know that the user is authenticated now. Start query the API $user = $linkedIn->api('v1/people/~:(id,firstName,lastName,emailAddress)'); //Check user exist or not $api = new Api(); $api_url = $this->getServiceLocator()->get('Config')['api_url']['value']; $url = $api_url . "/api/useractivity/"; $data = array('op' => 'check_exist_user', 'user_name' => $user['emailAddress'], 'email' => $user['emailAddress']); $res = $api->curl($url, $data, "POST"); //Set value in session $lk_login = new Container('linkedin'); $lk_login->first_name = $user['firstName']; $lk_login->last_name = $user['lastName']; $lk_login->user_name = $user['emailAddress']; $lk_login->email = $user['emailAddress']; $lk_login->social_id = $user['id']; // END :- Set value in session //$facebook1->destroySession(); die; // For new user if ($res->getStatusCode() != 200) { $redirectUrl = 'register/index#register-a'; return $this->redirect()->toUrl($redirectUrl); } else { $auth = new FrontEndAuth(); $session = new Container('frontend'); $content = json_decode($res->getBody(), true); $session->status_id = $content['status_id']; $session->userid = $content['id']; if ($content['status_id'] != 3) { $session->first_name = $content['first_name']; $session->last_name = $content['last_name']; $session->email = $content['email']; $session->user_name = $content['user_name']; $session->user_type_id = $content['user_type_id']; $session->user_data = $content; $session->last_login = $content['last_login_prev']; $auth->wordpress_login($fbuname); //$redirectUrl = ($session->user_type_id == 4)?array('controller' => 'practitioner', 'action' => 'list'):array('controller' => 'practitioner', 'action' => 'dashboard'); $redirectUrl = $session->user_type_id == 4 ? 'list' : 'dashboard'; $url = "practitioner/" . $redirectUrl; return $this->redirect()->toUrl($url); } else { return $this->redirect()->toRoute('login', array('action' => 'index')); } } } elseif ($linkedIn->hasError()) { echo "User canceled the login."; exit; } //if not authenticated $url = $linkedIn->getLoginUrl(); return $this->redirect()->toUrl($url); die; }
public function indexAction() { //session_start(); $google_login = new Container('google'); $google_client_id = $this->getServiceLocator()->get('config')['gplus_keys']['google_client_id']; $google_client_secret = $this->getServiceLocator()->get('config')['gplus_keys']['google_client_secret']; $google_redirect_url = $this->getServiceLocator()->get('config')['gplus_keys']['google_redirect_url']; $google_developer_key = $this->getServiceLocator()->get('config')['gplus_keys']['google_developer_key']; $gClient = new \Google_Client(); $gClient->setClientId($google_client_id); $gClient->setClientSecret($google_client_secret); $gClient->setRedirectUri($google_redirect_url); $gClient->setDeveloperKey($google_developer_key); $google_oauthV2 = new \Google_Oauth2Service($gClient); $id = (int) $this->params()->fromRoute('code', 0); //var_dump($id); if ($_GET['code']) { $gClient->authenticate($_GET['code']); //$_SESSION['token'] = $gClient->getAccessToken(); $google_login->token = $gClient->getAccessToken(); //header('Location: ' . filter_var($google_redirect_url, FILTER_SANITIZE_URL)); //return; } /*print"<pre>"; print_r($google_oauthV2);*/ //print_r($_SESSION); //die; if (isset($google_login->token)) { $gClient->setAccessToken($google_login->token); } if ($gClient->getAccessToken()) { //For logged in user, get details from google using access token $user = $google_oauthV2->userinfo->get(); $user_id = $user['id']; $first_name = filter_var($user['given_name'], FILTER_SANITIZE_SPECIAL_CHARS); $last_name = filter_var($user['family_name'], FILTER_SANITIZE_SPECIAL_CHARS); $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); $google_login->token = $gClient->getAccessToken(); //Check user exist or not $api = new Api(); $api_url = $this->getServiceLocator()->get('Config')['api_url']['value']; $url = $api_url . "/api/useractivity/"; $data = array('op' => 'check_exist_user', 'user_name' => $email, 'email' => $email); $res = $api->curl($url, $data, "POST"); //Set value in session $google_login->first_name = $first_name; $google_login->last_name = $last_name; $google_login->user_name = $email; $google_login->email = $email; $google_login->social_id = $user_id; // END :- Set value in session // For new user if ($res->getStatusCode() != 200) { $redirectUrl = 'register/index#register-a'; return $this->redirect()->toUrl($redirectUrl); } else { $auth = new FrontEndAuth(); $session = new Container('frontend'); $content = json_decode($res->getBody(), true); $session->status_id = $content['status_id']; $session->userid = $content['id']; if ($content['status_id'] != 3) { $session->first_name = $content['first_name']; $session->last_name = $content['last_name']; $session->email = $content['email']; $session->user_name = $content['user_name']; $session->user_type_id = $content['user_type_id']; $session->last_login = $content['last_login_prev']; $session->user_data = $content; $auth->wordpress_login($fbuname); $redirectUrl = $session->user_type_id == 4 ? array('controller' => 'practitioner', 'action' => 'list') : array('controller' => 'practitioner', 'action' => 'dashboard'); //$redirectUrl = array('controller' => 'practitioner', 'action' => 'dashboard'); return $this->redirect()->toRoute(null, $redirectUrl); } else { $redirectUrl = array('controller' => 'login', 'action' => 'index'); return $this->redirect()->toRoute(null, $redirectUrl); } } } else { //For Guest user, get google login url $authUrl = $gClient->createAuthUrl(); return $this->redirect()->toUrl($authUrl); } die; }
public function authenticateAction() { $form = $this->getForm(); $redirect = 'admin/login'; $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { //check authentication... $this->getAuthService()->getAdapter()->setIdentity($request->getPost('username'))->setCredential($request->getPost('password')); $result = $this->getAuthService()->authenticate(); foreach ($result->getMessages() as $message) { //save message temporary into flashmessenger $this->flashmessenger()->addMessage($message); } if ($result->isValid()) { $redirect = 'admin'; /* //check if it has rememberMe : if ($request->getPost('rememberme') == 1 ) { $this->getSessionStorage() ->setRememberMe(1); //set storage again $this->getAuthService()->setStorage($this->getSessionStorage()); } */ // SET Cookies $time = $request->getPost('rememberme') == 1 ? time() + 365 * 60 * 60 * 24 : time() - 4; $cookie = new SetCookie('username', $request->getPost('username'), $time); // now + 1 year $cookie1 = new SetCookie('password', $request->getPost('password'), $time); // now + 1 year $cookie2 = new SetCookie('rememberme', $request->getPost('rememberme'), $time); // now + 1 year $response = $this->getResponse()->getHeaders(); $response->addHeader($cookie); $response->addHeader($cookie1); $response->addHeader($cookie2); // End set cookies $this->getAuthService()->setStorage($this->getSessionStorage()); $this->getAuthService()->getStorage()->write($request->getPost('username')); $wp_auth = new FrontEndAuth(); $wp_auth->wordpress_login($request->getPost('username')); // logging in wordpress account /* Setting logged in user details in session */ $user_details = new Container('user_details'); $user_details->details = array('user_id' => $result->user_id, 'user_type_id' => $result->user_type_id, 'user_name' => $result->getIdentity()); $user_permission = new Container('user_permission'); $user_permission->rights = $this->getServiceLocator()->get('Admin\\Model\\UserRightsTable')->getUserRightsArr($result->user_id); /* set last login time for user - starts here */ $username = $request->getPost('username'); $result = $this->getUsersTable()->getUser($username, 'user_name'); $result->last_login = date('Y-m-d H:i:s', time()); $this->getUsersTable()->saveUser($result, 'update_last_login'); /* set last login time for user - ends here */ } } } /* $session = new Container('user_permission'); print_r($session['rights']); exit; */ return $this->redirect()->toRoute($redirect); }
public function indexAction() { $keys = $this->getServiceLocator()->get('config')['fb_keys']; $facebook = new \Facebook($keys); $user = $facebook->getUser(); if ($user) { try { $user_profile = $facebook->api('/me'); //Check user exist or not $api = new Api(); $api_url = $this->getServiceLocator()->get('Config')['api_url']['value']; $url = $api_url . "/api/useractivity/"; $data = array('op' => 'check_exist_user', 'user_name' => $user_profile['email'], 'email' => $user_profile['email']); $res = $api->curl($url, $data, "POST"); //Set value in session $fb_login = new Container('facebook'); $fb_login->first_name = $user_profile['first_name']; $fb_login->last_name = $user_profile['last_name']; $fb_login->user_name = $user_profile['email']; $fb_login->email = $user_profile['email']; $fb_login->social_id = $user_profile['id']; $fb_login->token = $facebook->getAccessToken(); // END :- Set value in session //$facebook1->destroySession(); die; // For new user if ($res->getStatusCode() != 200) { $redirectUrl = 'register/index#register-a'; return $this->redirect()->toUrl($redirectUrl); } else { $auth = new FrontEndAuth(); $session = new Container('frontend'); $content = json_decode($res->getBody(), true); $session->status_id = $content['status_id']; $session->userid = $content['id']; if ($content['status_id'] != 3) { $session->first_name = $content['first_name']; $session->last_name = $content['last_name']; $session->email = $content['email']; $session->user_name = $content['user_name']; $session->user_type_id = $content['user_type_id']; $session->user_data = $content; $session->last_login = $content['last_login_prev']; $auth->wordpress_login($fbuname); $redirectUrl = $session->user_type_id == 4 ? array('controller' => 'practitioner', 'action' => 'list') : array('controller' => 'practitioner', 'action' => 'dashboard'); //$redirectUrl = array('controller' => 'practitioner', 'action' => 'dashboard'); return $this->redirect()->toRoute(null, $redirectUrl); } else { $redirectUrl = array('controller' => 'login', 'action' => 'index'); return $this->redirect()->toRoute(null, $redirectUrl); } } } catch (FacebookApiException $e) { error_log($e); $user = null; } } else { $loginUrl = $facebook->getLoginUrl(array('scope' => 'email,read_stream')); return $this->redirect()->toUrl($loginUrl); } die; }
public function indexAction() { $api = new Api(); $auth = new FrontEndAuth(); $session = new Container('frontend'); $loginError = ""; $seturl = $this->getRequest()->getQuery('last_url'); //$redirectUrl = 'http://blog.ovessence.in/'; if ($auth->hasIdentity()) { if ($session->status_id != 3) { //$redirectUrl = array('controller' => 'practitioner', 'action' => 'list'):array('controller' => 'practitioner', 'action' => 'dashboard'); return $session->user_type_id == 4 ? $this->redirect()->toRoute('consumer', array('action' => 'dashboard')) : $this->redirect()->toRoute('practitioner', array('action' => 'dashboard')); } else { $loginError = "Sorry your are suspended to access this site ..!! "; $auth->logout($redirectUrl); } } $form = new LoginForm(); $register_form = new RegisterForm(); //$forWishlist = new Container('last_url'); $request = $this->getRequest(); if ($request->isPost()) { $login = new Login(); $form->setInputFilter($login->getInputFilter()); $data = $request->getPost()->toArray(); $form->setData($data); if ($form->isValid()) { //unset($data['rememberme'], $data['submit']); $bookingData = new Container('bookingData'); $api_url = $this->getServiceLocator()->get('Config')['api_url']['value']; $url = $api_url . "/api/useractivity/"; //$data = array("username" => "sazid1s", "password" => "123456", "op" => "login"); $data['op'] = 'login'; $res = $api->curl($url, $data, "POST"); //var_dump($res); die; if ($res->getStatusCode() == 200) { $content = json_decode($res->getBody(), true); if ($content['status_id'] != 3) { //Get verifiy status $url = $api_url . "/api/userverification/?user_id=" . $content['id']; $res = $api->curl($url, array(), "GET"); $result = json_decode($res->getBody(), true); $emailStatus = 0; $smsStatus = 0; if (count($result) > 0) { // retrieving verification code foreach ($result as $userid) { // email validation where 1:- email if ($userid['verification_type_id'] == 1) { $emailStatus = $userid['verification_status']; } // sms validation where 2:- for sms if ($userid['verification_type_id'] == 2) { $smsStatus = $userid['verification_status']; } } } //End:- Get verifiy status $session->userid = $content['id']; $session->first_name = $content['first_name']; $session->last_name = $content['last_name']; $session->email = $content['email']; $session->user_name = $content['user_name']; $session->user_type_id = $content['user_type_id']; $session->user_data = $content; $session->status_id = $content['status_id']; $session->last_login = $content['last_login_prev']; $session->email_verification_status = $emailStatus; $session->sms_verification_status = $smsStatus; // SET Cookies $time = $data['rememberme'] == 'yes' ? time() + 365 * 60 * 60 * 24 : time() - 4; $cookie = new SetCookie('username', $content['user_name'], $time); // now + 1 year $cookie1 = new SetCookie('password', $data['Pass'], $time); // now + 1 year $cookie2 = new SetCookie('rememberme', $data['rememberme'], $time); // now + 1 year $response = $this->getResponse()->getHeaders(); $response->addHeader($cookie); $response->addHeader($cookie1); $response->addHeader($cookie2); // End set cookies if ($data['rememberme'] == 'yes') { setcookie("user_name", $content['user_name'], time() + 60 * 60 * 1); setcookie("password", $data['Pass'], time() + 60 * 60 * 1); /* expire in 1 hour */ } $auth->wordpress_login($session->user_name); $redirectUrl = $session->user_type_id == 4 ? array('controller' => 'consumer', 'action' => 'dashboard') : array('controller' => 'practitioner', 'action' => 'dashboard'); if (isset($bookingData->bookingData)) { return $this->redirect()->toRoute('booking', array('action' => 'schedule', 'id' => $bookingData->sp)); } else { if ($this->getRequest()->getQuery('lasturl') != '') { return $this->redirect()->toUrl($this->getRequest()->getQuery('lasturl')); } else { return $session->user_type_id == 4 ? $this->redirect()->toRoute('consumer', array('action' => 'dashboard')) : $this->redirect()->toRoute('practitioner', array('action' => 'dashboard')); } } } //Status check $loginError = "Sorry your are suspended to access this site ..!! "; //return $this->redirect()->toUrl($redirectUrl); } else { $loginError = "Username or Password is incorrect"; } } } else { $username = $this->getRequest()->getHeaders()->get('Cookie')->username ? $this->getRequest()->getHeaders()->get('Cookie')->username : ''; $password = $this->getRequest()->getHeaders()->get('Cookie')->password ? $this->getRequest()->getHeaders()->get('Cookie')->password : ''; $rememberme = $this->getRequest()->getHeaders()->get('Cookie')->password ? $this->getRequest()->getHeaders()->get('Cookie')->rememberme : ''; $form->get('Pass')->setValue($password); $form->get('user_name')->setValue($username); $form->get('rememberme')->setValue($rememberme); } return new ViewModel(array('form' => $form, 'register_form' => $register_form, 'loginError' => $loginError, 'setUrl' => $seturl)); }
public function indexAction() { $fb_login = new Container('facebook'); $google_login = new Container('google'); $linkedin_login = new Container('linkedin'); $social_media_id = ''; if (isset($fb_login->social_id)) { $common_object = $fb_login; $social_media_id = $fb_login->social_id; } if (isset($google_login->social_id)) { $common_object = $google_login; $social_media_id = $google_login->social_id; } if (isset($linkedin_login->social_id)) { $common_object = $linkedin_login; $social_media_id = $linkedin_login->social_id; } $api = new Api(); $auth = new FrontEndAuth(); $session = new Container('frontend'); $loginError = ""; $redirectUrl = array('controller' => 'index'); if ($auth->hasIdentity()) { //$redirectUrl = array('controller'=>'index'); //$redirectUrl = array('controller'=>'login', 'action' => 'dashboard'); return $this->redirect()->toRoute(null, $redirectUrl); } //var_dump($session->user_name); die; $common = new Common(); $form = new LoginForm(); $register_form = new RegisterForm(); $request = $this->getRequest(); if ($request->isPost()) { //die('hello'); $register = new Register(); $register_form->setInputFilter($register->getInputFilter()); $data = $request->getPost()->toArray(); $register_form->setData($data); //$validation_result = json_decode($this->passwordValidation($data['confirm_password']), true); if ($register_form->isValid()) { $loginError = $validation_result['msg']; //if(!$validation_result['error']){ $loginError = ''; unset($data['confirm_password'], $data['register_submit']); //die('hello'); $api_url = $this->getServiceLocator()->get('Config')['api_url']['value']; $url = $api_url . "/api/users/"; $data['op'] = 'register'; $data['social_media_id'] = $social_media_id; $data['status_id'] = $data['user_type_id'] == 4 ? 9 : 5; $res = $api->curl($url, $data, "POST"); if ($res->getStatusCode() == 201) { $content = json_decode($res->getBody(), true); $common->addChatAccount($this->getServiceLocator()->get('Config')['chatpath']['url'], $content, $data, $request); // Creating account for live chat $newsletter = $content['user_type_id'] == 3 ? 1 : 4; $common->addFeature($api_url, array('user_id' => $content['id'], 'email' => 1, 'sms' => 1, 'chat' => 0, 'newsletter' => $newsletter)); // Adding user feature setting $common->sendMail($api_url, $content['email'], '', 21, '', array('/{{user_name}}/i'), array($content['first_name'] . ' ' . $content['last_name'])); $session->userid = $content['id']; $session->first_name = $content['first_name']; $session->last_name = $content['last_name']; $session->email = $content['email']; $session->user_name = $content['user_name']; $session->user_type_id = $content['user_type_id']; $session->user_data = $content; // adding default subscription if ($session->user_type_id == 3) { $common->addSubscription($api_url, array('user_id' => $session->userid)); } $auth->wordpress_create_user($session->user_name, $session->email, $data['confirm_password']); $auth->wordpress_login($session->user_name); $bookingData = new Container('bookingData'); //var_dump($res); die; //return ($session->user_type_id == 4) ? $this->redirect()->toRoute('consumer', array('action' => 'dashboard')) : $this->redirect()->toRoute('practitioner', array('action' => 'dashboard')); if (isset($bookingData->bookingData)) { return $this->redirect()->toRoute('booking', array('action' => 'schedule', 'id' => $bookingData->sp)); } else { if ($this->getRequest()->getQuery('lasturl') != '') { return $this->redirect()->toUrl($this->getRequest()->getQuery('lasturl')); } else { return $session->user_type_id == 4 ? $this->redirect()->toRoute('consumer', array('action' => 'dashboard')) : $this->redirect()->toRoute('practitioner', array('action' => 'dashboard')); } } //return $this->redirect()->toRoute(null, $redirectUrl); } else { $errors = json_decode($res->getBody(), true); foreach ($errors as $key => $value) { if (isset($value[0])) { $register_form->setMessages(array($key => array($value[0]))); } } $this->errors = $register_form->getMessages(); // added by Ritesh to get error messages } //var_dump($errors); die; //}// validation condition } else { $this->errors = $register_form->getMessages(); } } $view = new ViewModel(array('form' => $form, 'register_form' => $register_form, 'loginError' => $loginError, 'fb_login' => $common_object, 'errors' => $this->errors)); $view->setTemplate('application/login/index.phtml'); return $view; }