/** * Register new user */ public function registerAction() { // if the user is logged in, we don't need to register if ($this->zfcUserAuthentication()->hasIdentity()) { // redirect to the login redirect route return $this->redirect()->toRoute($this->options->getLoginRedirectRoute()); } // if registration is disabled if (!$this->options->getEnableRegistration()) { return array('enableRegistration' => false); } $request = $this->getRequest(); $service = $this->userService; $form = $this->registerForm; if ($this->options->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) { $redirect = $request->getQuery()->get('redirect'); } else { $redirect = false; } $redirectUrl = $this->url()->fromRoute(static::ROUTE_REGISTER) . ($redirect ? '?redirect=' . rawurlencode($redirect) : ''); $prg = $this->prg($redirectUrl, true); if ($prg instanceof Response) { return $prg; } elseif ($prg === false) { return array('registerForm' => $form, 'enableRegistration' => $this->options->getEnableRegistration(), 'redirect' => $redirect); } $post = $prg; $user = $service->register($post); $redirect = isset($prg['redirect']) ? $prg['redirect'] : null; // THS surcouche recaptcha $recaptcha = new \ZendService\ReCaptcha\ReCaptcha($this->getServiceLocator()->get('config')['google']['publicKey'], $this->getServiceLocator()->get('config')['google']['privateKey']); if (empty($prg['g-recaptcha-response'])) { $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Veuillez valider votre captcha."), 'error'); return array('registerForm' => $form, 'enableRegistration' => $this->options->getEnableRegistration(), 'redirect' => $redirect); } $result = $recaptcha->verify($prg['g-recaptcha-response']); if (!$result->isValid()) { $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Veuillez verifier votre captcha."), 'error'); return array('registerForm' => $form, 'enableRegistration' => $this->options->getEnableRegistration(), 'redirect' => $redirect); } // THS END if (!$user) { return array('registerForm' => $form, 'enableRegistration' => $this->options->getEnableRegistration(), 'redirect' => $redirect); } if ($service->getOptions()->getLoginAfterRegistration()) { $identityFields = $service->getOptions()->getAuthIdentityFields(); if (in_array('email', $identityFields)) { $post['identity'] = $user->getEmail(); } elseif (in_array('username', $identityFields)) { $post['identity'] = $user->getUsername(); } $post['credential'] = $post['password']; $request->setPost(new Parameters($post)); return $this->forward()->dispatch(static::CONTROLLER_NAME, array('action' => 'authenticate')); } // TODO: Add the redirect parameter here... // ths return $this->redirect()->toRoute('register-sendmail', array('mail' => base64_encode($post['email']))); // return $this->redirect()->toUrl($this->url()->fromRoute(static::ROUTE_LOGIN) . ($redirect ? '?redirect='. rawurlencode($redirect) : '')); }
/** * Register new user */ public function registerAction() { // if the user is logged in, we don't need to register if ($this->zfcUserAuthentication()->hasIdentity()) { // redirect to the login redirect route return $this->redirect()->toRoute($this->options->getLoginRedirectRoute()); } // if registration is disabled if (!$this->options->getEnableRegistration()) { return array('enableRegistration' => false); } $request = $this->getRequest(); $service = $this->userService; $form = $this->registerForm; if ($this->options->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) { $redirect = $request->getQuery()->get('redirect'); } else { $redirect = false; } $redirectUrl = $this->url()->fromRoute(static::ROUTE_REGISTER) . ($redirect ? '?redirect=' . rawurlencode($redirect) : ''); $prg = $this->prg($redirectUrl, true); if ($prg instanceof Response) { return $prg; } elseif ($prg === false) { return array('registerForm' => $form, 'enableRegistration' => $this->options->getEnableRegistration(), 'redirect' => $redirect); } $post = $prg; $user = $service->register($post); $redirect = isset($prg['redirect']) ? $prg['redirect'] : null; if (!$user) { return array('registerForm' => $form, 'enableRegistration' => $this->options->getEnableRegistration(), 'redirect' => $redirect); } if ($service->getOptions()->getLoginAfterRegistration()) { $identityFields = $service->getOptions()->getAuthIdentityFields(); if (in_array('email', $identityFields)) { $post['identity'] = $user->getEmail(); } elseif (in_array('username', $identityFields)) { $post['identity'] = $user->getUsername(); } $post['credential'] = $post['password']; $request->setPost(new Parameters($post)); return $this->forward()->dispatch(static::CONTROLLER_NAME, array('action' => 'authenticate')); } // TODO: Add the redirect parameter here... return $this->redirect()->toUrl($this->url()->fromRoute(static::ROUTE_LOGIN) . ($redirect ? '?redirect=' . rawurlencode($redirect) : '')); }