public function settingsAction()
 {
     $auth = new FrontEndAuth();
     if (!$auth->hasIdentity(3)) {
         return $this->redirect()->toUrl('/login');
     }
     $session = new Container('frontend');
     $common = new Common();
     $api = new Api();
     $api_url = $this->getServiceLocator()->get('config')['api_url']['value'];
     $featureData = $common->getFeatures($api_url, $session->userid);
     $subscriptionData = $this->getSpsubscription($session->userid, $api, $api_url);
     $result_newsletter = $common->chkNewsletter($api_url);
     $unsubscribe_reasons = $common->getUnsubscribereason($api_url);
     $model = new Practitioners();
     $notifications = $model->getNotifications($api_url);
     $sp_details = $model->getSPDetails($api_url, $session->userid);
     $form = new SPChangePasswordForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($this->getRequest()->isXmlHttpRequest()) {
         $request = $this->getRequest();
         $error = false;
         $request->getPost('action') != '' ? $action = $request->getPost('action') : ($action = '');
         if ($action == "change_password") {
             if (preg_match('/^.*(?=.{6,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\\s).*$/', $request->getPost('Pass'))) {
                 $request->getPost('old_pass') != '' ? $old_pass = $request->getPost('old_pass') : ($old_pass = '');
                 $request->getPost('Pass') != '' ? $Pass = $request->getPost('Pass') : ($Pass = '');
                 $request->getPost('confirm_password') != '' ? $confirm_password = $request->getPost('confirm_password') : ($confirm_password = '');
                 if ($old_pass != '' && $Pass != '' && $confirm_password != '') {
                     if ($Pass == $confirm_password) {
                         $data = array('op' => 'changepassword', 'old_password' => md5($old_pass), 'new_password' => md5($Pass), 'user_id' => $session->userid);
                         $url = $api_url . "/api/useractivity/";
                         $res = $api->curl($url, $data, "POST");
                         if ($res->getStatusCode() == 200) {
                             $msg = "Success!! Password changed sucessfully";
                         } else {
                             if ($res->getStatusCode() == 404) {
                                 $error = true;
                                 $msg = "Error!! Old password is not correct";
                             } else {
                                 $error = true;
                                 $msg = "Error!! Password could not be updated";
                             }
                         }
                     } else {
                         // Password and confirm password do not match
                         $error = true;
                         $msg = "Error!! Confirm password do not match";
                     }
                 } else {
                     $error = true;
                     $msg = "Error!! Invalid form data";
                 }
             } else {
                 $error = true;
                 $msg = "Password must be at least 6 characters and must contain at least one lower case letter, one upper case letter, one digit and one special character.";
             }
             echo json_encode(array('error' => $error, 'msg' => $msg));
             exit;
         } else {
             if ($action == "change_features") {
                 $request->getPost('feature_email') != '' ? $feature_email = $request->getPost('feature_email') : ($feature_email = '');
                 $request->getPost('feature_sms') != '' ? $feature_sms = $request->getPost('feature_sms') : ($feature_sms = '');
                 $request->getPost('feature_chat') != '' ? $feature_chat = $request->getPost('feature_chat') : ($feature_chat = '');
                 $request->getPost('feature_table_id') != '' ? $feature_table_id = $request->getPost('feature_table_id') : ($feature_table_id = '');
                 $data = array('email' => $feature_email, 'sms' => $feature_sms, 'chat' => $feature_chat, 'user_id' => $session->userid);
                 $data['id'] = $featureData['id'];
                 if ($common->addFeature($api_url, $data)) {
                     $msg = "Feature setting updated successfully";
                 } else {
                     $error = true;
                     $msg = "Feature setting updated successfully";
                 }
                 echo json_encode(array('error' => $error, 'msg' => $msg));
                 exit;
             } else {
                 if ($action == "newletter-chk") {
                     $request->getPost('newletter_chk') != '' ? $newletter_chk = $request->getPost('newletter_chk') : ($newletter_chk = '');
                     $data = array('user_id' => $session->userid, 'newsletter' => $newletter_chk);
                     if (isset($featureData['id'])) {
                         // update
                         $url = $api_url . '/api/userfeaturesetting/' . $featureData['id'] . '/';
                         $res = $api->curlUpdate($url, $data, "PUT");
                     } else {
                         $url = $api_url . '/api/userfeaturesetting/';
                         $res = $api->curlUpdate($url, $data, "POST");
                     }
                     if ($res) {
                         $msg = "Feature setting updated successfully";
                     } else {
                         $error = true;
                         $msg = "Feature setting updated successfully";
                     }
                     echo json_encode(array('error' => $error, 'msg' => $msg));
                     exit;
                 } else {
                     if ($action == "auto-renewal") {
                         $autorenew = $request->getPost('auto_renewal') != '' ? $request->getPost('auto_renewal') : '0';
                         $subscription_id = $request->getPost('subscription_id') != '' ? $request->getPost('subscription_id') : '';
                         $result = $common->autorenew($api_url, $subscription_id, $autorenew);
                         echo json_encode($result);
                         exit;
                     } else {
                         if ($action == "close-acc") {
                             $reason_id = $request->getPost('reason_id') != '' ? $request->getPost('reason_id') : '';
                             $other_reason = $request->getPost('other_reason') != '' ? $request->getPost('other_reason') : '';
                             if ($reason_id !== '') {
                                 $result = $common->isaccountRemovable($api_url);
                                 if (!$result) {
                                     $error = true;
                                     $msg = "Sorry!! you cannot deactivate your account untill you clear all your pending bookings.";
                                 } else {
                                     if ($reason_id == 5 && $other_reason == '') {
                                         $error = true;
                                         $msg = "Please provide other reason in the text area";
                                     } else {
                                         $result = $common->closeAccount($api_url, $reason_id, $other_reason);
                                         if ($result) {
                                             // close acc here
                                             $msg = "You account has been deactivated successfully..you will be logged out in 5 seconds";
                                         } else {
                                             // error acc could not be closed
                                             $error = true;
                                             $msg = "Some Error occured , Could not close your account , please try after some time";
                                         }
                                     }
                                 }
                             } else {
                                 $error = true;
                                 $msg = "Please provide us a reason to close your account";
                             }
                             echo json_encode(array('error' => $error, 'msg' => $msg));
                             exit;
                         } else {
                             if ($action == "unsubscribe") {
                                 $subscription_id = $request->getPost('subscription_id') != '' ? $request->getPost('subscription_id') : '';
                                 $result = $common->unsubscribeMembership($api_url, $subscription_id);
                                 if ($result) {
                                     $msg = "Unsubscribed Successfully";
                                 } else {
                                     $error = true;
                                     $msg = "Error, could not unsubscribe";
                                 }
                                 echo json_encode(array('error' => $error, 'msg' => $msg));
                                 exit;
                             } else {
                                 if ($action == "update_card") {
                                     $trans = new Transactions();
                                     echo json_encode($trans->updateCard($this->getServiceLocator()->get('config'), $request->getPost('card_data')));
                                     exit;
                                 } else {
                                     $error = true;
                                     $msg = "Invalid request";
                                     echo json_encode(array('error' => $error, 'msg' => $msg));
                                     exit;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // getting banner for this page
     $banners = $common->getBanner($api_url, 4);
     return new ViewModel(array('form' => $form, 'featureData' => $featureData, 'subscriptionData' => $subscriptionData, 'notifications' => $notifications, 'avtar_url' => $sp_details['avtar_url'], 'first_name' => $sp_details['first_name'], 'last_name' => $sp_details['last_name'], 'newsletter_chk' => $result_newsletter, 'reasonsList' => $unsubscribe_reasons, 'card_details' => $common->getUserCardDetails($api_url, array('user_id' => $session->userid)), 'banners' => $banners));
 }
Exemplo n.º 2
0
 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;
 }