2 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class NewpwdController extends Zend_Controller_Action
8 public function init() {
9 $this->view->headScript()->appendFile('js/prototype.js');
10 $this->view->headScript()->appendFile('js/newpwd.js');
11 $this->view->headScript()->appendFile('js/utils.js');
12 $this->view->headLink()->appendStylesheet('css/generic.css');
13 $this->view->headLink()->appendStylesheet('css/newpwd.css');
16 public function indexAction() {
17 $form = new Syj_Form_Newpwd(array('name' => 'newpwdform'));
18 $request = $this->getRequest();
19 $formData = $request->getPost();
20 $this->view->form = $form;
21 $httprequest = $request->isXmlHttpRequest();
24 $this->_jsLocaleStrings();
27 if (empty($formData)) {
28 $loggeduser = $this->_helper->SyjSession->user();
30 $form->newpwd_email->setValue($loggeduser->email)
31 ->setAttrib('readonly', 'true');
35 if (empty ($formData) or !$form->isValid($formData)) {
37 throw new Syj_Exception_Request();
43 /* form has been filled */
44 $userMapper = new Syj_Model_UserMapper();
45 $user = new Syj_Model_User();
46 if ($userMapper->findByEmail($formData['newpwd_email'], $user)) {
47 // if no user exist with posted email, pretend everything went correct
48 $loggeduser = isset($loggeduser) ? $loggeduser: $this->_helper->SyjSession->user();
49 if ($loggeduser and ($loggeduser != $user)) {
50 throw new Syj_Exception_Request();
52 $pending = new Syj_Model_Pending_ResetPassword();
53 $pending->setUser($user);
54 if (!$pending->notify()) {
55 throw new Zend_Exception();
60 $api = $this->_helper->SyjApi->setCode(200);
62 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/success.:suffix');
67 protected function _jsLocaleStrings() {
68 $this->view->jslocales = array(
69 'notEmptyField' => __("Value is required and can't be empty"),