Skip to content

Commit

Permalink
Merge pull request ZF-Commons#120 from bjyoungblood/feature/change-no…
Browse files Browse the repository at this point in the history
…tifications

notify user when email and password are updated (or failed)
  • Loading branch information
EvanDotPro committed Aug 23, 2012
2 parents 7ffd684 + 7fa2c64 commit 0734493
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/ZfcUser/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,20 @@ public function registerAction()
*/
public function changepasswordAction() {
$form = $this->getChangePasswordForm();

$prg = $this->prg('zfcuser/changepassword');

$fm = $this->flashMessenger()->setNamespace('change-password')->getMessages();
if (isset($fm[0])) {
$status = $fm[0];
} else {
$status = null;
}

if ($prg instanceof Response) {
return $prg;
} else if ($prg === false) {
return array(
'status' => $status,
'changePasswordForm' => $form,
);
}
Expand All @@ -223,18 +231,20 @@ public function changepasswordAction() {

if (!$form->isValid()) {
return array(
'status' => false,
'changePasswordForm' => $form,
);
}

if (!$this->getUserService()->changePassword($form->getData())) {
$form->setMessages(array('credential' => array('Invalid password')));
return array(
'status' => false,
'changePasswordForm' => $form,
);
}

return $this->redirect()->toRoute('zfcuser/changepassword/query', array('success' => 1));
$this->flashMessenger()->setNamespace('change-password')->addMessage(true);
return $this->redirect()->toRoute('zfcuser/changepassword');
}

public function changeEmailAction()
Expand All @@ -243,11 +253,19 @@ public function changeEmailAction()
$request = $this->getRequest();
$request->getPost()->set('identity', $this->getUserService()->getAuthService()->getIdentity()->getEmail());

$fm = $this->flashMessenger()->setNamespace('change-email')->getMessages();
if (isset($fm[0])) {
$status = $fm[0];
} else {
$status = null;
}

$prg = $this->prg('zfcuser/changeemail');
if ($prg instanceof Response) {
return $prg;
} else if ($prg === false) {
return array(
'status' => $status,
'changeEmailForm' => $form,
);
}
Expand All @@ -256,20 +274,23 @@ public function changeEmailAction()

if (!$form->isValid()) {
return array(
'status' => false,
'changeEmailForm' => $form,
);
}

$change = $this->getUserService()->changeEmail($prg);

if (!$change) {
$form->setMessages(array('credential' => array('Invalid password')));
$this->flashMessenger()->setNamespace('change-email')->addMessage(false);
return array(
'status' => false,
'changeEmailForm' => $form,
);
}

return $this->redirect()->toRoute('zfcuser/changeemail/query', array('success' => 1));
$this->flashMessenger()->setNamespace('change-email')->addMessage(true);
return $this->redirect()->toRoute('zfcuser/changeemail');
}

/**
Expand Down
5 changes: 5 additions & 0 deletions view/zfc-user/user/changeemail.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<h3>Change Email for <?php echo $this->zfcUserDisplayName() ?></h3>
<?php if ($status === true) : ?>
<div class="alert alert-success">Email address changed successfully.</div>
<?php elseif ($status === false) : ?>
<div class="alert alert-error">Unable to update your email address. Please try again.</div>
<?php endif; ?>
<?php

$form = $this->changeEmailForm;
Expand Down
5 changes: 5 additions & 0 deletions view/zfc-user/user/changepassword.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<h3>Change Password for <?php echo $this->zfcUserDisplayName() ?></h3>
<?php if ($status === true) : ?>
<div class="alert alert-success">Password changed successfully.</div>
<?php elseif ($status === false) : ?>
<div class="alert alert-error">Unable to update your password. Please try again.</div>
<?php endif; ?>
<?php

$form = $this->changePasswordForm;
Expand Down

0 comments on commit 0734493

Please sign in to comment.