Skip to content

Commit

Permalink
refactor register action to use prg plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bjyoungblood committed Aug 15, 2012
1 parent b1cc965 commit d0a8ede
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/ZfcUser/Controller/UserController.php
Expand Up @@ -148,7 +148,9 @@ public function authenticateAction()
*/
public function registerAction()
{
// if the user is logged in, we don't need to register
if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) {
// redirect to the login redirect route
return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
}

Expand All @@ -162,23 +164,20 @@ public function registerAction()
$redirect = false;
}

if ($request->isPost()) {
$this->flashMessenger()->setNamespace('zfcuser-register-form')->addMessage($request->getPost()->toArray());
// See http://en.wikipedia.org/wiki/Post/Redirect/Get
return $this->redirect()->toUrl($this->url()->fromRoute('zfcuser/register') . ($redirect ? '?redirect='.$redirect : ''));
}

$post = $this->flashMessenger()->setNamespace('zfcuser-register-form')->getMessages();
$redirectUrl = $this->url()->fromRoute('zfcuser/register') . ($redirect ? '?redirect=' . $redirect : '');
$prg = $this->prg($redirectUrl, true);

if (!isset($post[0]) || !$service->getOptions()->getEnableRegistration()) {
if ($prg instanceof Response) {
return $prg;
} else if ($prg === false) {
return array(
'registerForm' => $form,
'enableRegistration' => $this->getOptions()->getEnableRegistration(),
'redirect' => $redirect,
);
}

$post = $post[0];
$post = $prg;
$user = $service->register($post);

if (!$user) {
Expand Down

0 comments on commit d0a8ede

Please sign in to comment.