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->view->headLink()->appendStylesheet('css/generic.css', 'all');
11 $this->view->headLink()->appendStylesheet('css/form.css', 'all');
12 $this->view->headLink()->appendStylesheet('css/newpwd.css', 'all');
15 public function indexAction() {
16 $form = new Syj_Form_Newpwd(array('name' => 'newpwdform'));
17 $request = $this->getRequest();
18 $formData = $request->getPost();
19 $this->view->form = $form;
20 $httprequest = $request->isXmlHttpRequest();
23 $this->_jsLocaleStrings();
26 if (empty($formData)) {
27 $loggeduser = $this->_helper->SyjUserManager->current();
29 $form->newpwd_email->setValue($loggeduser->email)
30 ->setAttrib('readonly', 'true');
34 if (empty ($formData) or !$form->isValid($formData)) {
36 throw new Syj_Exception_Request();
42 /* form has been filled */
43 $userMapper = new Syj_Model_UserMapper();
44 $user = new Syj_Model_User();
45 if ($userMapper->findByEmail($formData['newpwd_email'], $user)) {
46 // if no user exist with posted email, pretend everything went correct
47 $loggeduser = isset($loggeduser) ? $loggeduser: $this->_helper->SyjUserManager->current();
48 if ($loggeduser and ($loggeduser != $user)) {
49 throw new Syj_Exception_Request();
51 $pending = new Syj_Model_Pending_ResetPassword();
52 $pending->setUser($user);
53 if (!$pending->notify()) {
54 throw new Zend_Exception();
59 $api = $this->_helper->SyjApi->setCode(200);
61 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/success.:suffix');
66 protected function _jsLocaleStrings() {
67 $this->view->jslocales = array(
68 'notEmptyField' => __("Value is required"),