2 /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class NewpwdController extends Zend_Controller_Action
8 public function init() {
9 $this->_helper->SyjMedias->addScripts('newpwd');
10 $this->_helper->SyjMedias->addStyleSheets('newpwd');
13 public function indexAction() {
14 $form = new Syj_Form_Newpwd(array('name' => 'newpwdform'));
15 $request = $this->getRequest();
16 $formData = $request->getPost();
17 $this->view->form = $form;
18 $httprequest = $request->isXmlHttpRequest();
21 $this->_jsLocaleStrings();
24 if (empty($formData)) {
25 $loggeduser = $this->_helper->SyjUserManager->current();
27 $form->newpwd_email->setValue($loggeduser->email)
28 ->setAttrib('readonly', 'true');
32 if (empty ($formData) or !$form->isValid($formData)) {
34 throw new Syj_Exception_Request();
40 /* form has been filled */
41 $userMapper = new Syj_Model_UserMapper();
42 $user = new Syj_Model_User();
43 if ($userMapper->findByEmail($formData['newpwd_email'], $user)) {
44 // if no user exist with posted email, pretend everything went correct
45 $loggeduser = isset($loggeduser) ? $loggeduser: $this->_helper->SyjUserManager->current();
46 if ($loggeduser and ($loggeduser != $user)) {
47 throw new Syj_Exception_Request();
49 $pending = new Syj_Model_Pending_ResetPassword();
50 $pending->setUser($user);
51 if (!$pending->notify()) {
52 throw new Zend_Exception();
57 $api = $this->_helper->SyjApi->setCode(200);
59 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/success.:suffix');
64 protected function _jsLocaleStrings() {
65 $this->view->jslocales = array(
66 'notEmptyField' => __("Value is required"),