public function registerAction() { // Check if user has submitted the form // Create Contact Us form $form = new RegistrationForm(); // Check if user has submitted the form $request = $this->getRequest(); if ($request->isPost()) { // Fill in the form with POST data $form->setInputFilter(new RegistrationFilter($this->getServiceLocator())); $form->setData($request->getPost()); // Validate form if ($form->isValid()) { // Get filtered and validated data $data = $form->getData(); $data = $this->prepareData($data); $user = new Register(); $user->exchangeArray($data); //$user->exchangeArray($form->getData()); $this->getRegisterTable()->saveUser($user); $mailSender = new \Application\Service\MailSender(); $messageBody = "Please, click the link to confirm your registration => " . $this->getRequest()->getServer('HTTP_ORIGIN') . $this->url()->fromRoute('application/default', array('controller' => 'registration', 'action' => 'confirm-email', 'id' => $user->usr_registration_token)); $mailSender->sendContactMail('*****@*****.**', $user->usr_email, 'Your App Confirmation Email', $messageBody); $this->flashMessenger()->addMessage($user->usr_email); return $this->redirect()->toRoute('application/default', array('controller' => 'registration', 'action' => 'registration-success')); } } // Pass form variable to view return new ViewModel(array('form' => $form)); }
public function loginAction() { $user = $this->identity(); $form = new LoginForm(); $form->get('submit')->setValue('Login'); $messages = null; $request = $this->getRequest(); if ($request->isPost()) { $registerFormFilters = new Register(); $form->setInputFilter($registerFormFilters->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); $sm = $this->getServiceLocator(); $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter'); $config = $this->getServiceLocator()->get('Config'); $staticSalt = $config['static_salt']; $authAdapter = new AuthAdapter($dbAdapter, 'registration', 'usr_name', 'usr_password', "MD5(CONCAT('{$staticSalt}', ?, usr_password_salt)) AND usr_active = 1"); $authAdapter->setIdentity($data['usr_name'])->setCredential($data['usr_password']); $auth = new AuthenticationService(); // or prepare in the globa.config.php and get it from there. Better to be in a module, so we can replace in another module. // $auth = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService'); // $sm->setService('Zend\Authentication\AuthenticationService', $auth); // You can set the service here but will be loaded only if this action called. $result = $auth->authenticate($authAdapter); switch ($result->getCode()) { case Result::FAILURE_IDENTITY_NOT_FOUND: // do stuff for nonexistent identity break; case Result::FAILURE_CREDENTIAL_INVALID: // do stuff for invalid credential break; case Result::SUCCESS: $storage = $auth->getStorage(); $storage->write($authAdapter->getResultRowObject(null, 'usr_password')); $time = 1209600; // 14 days 1209600/3600 = 336 hours => 336/24 = 14 days // if ($data['rememberme']) $storage->getSession()->getManager()->rememberMe($time); // no way to get the session if ($data['rememberme']) { $sessionManager = new \Zend\Session\SessionManager(); $sessionManager->rememberMe($time); } break; default: // do stuff for other failure break; } foreach ($result->getMessages() as $message) { $messages .= "{$message}\n"; } } } return new ViewModel(array('form' => $form, 'messages' => $messages)); }
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; }