2 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class AccountController extends Zend_Controller_Action
8 public function init() {
9 $this->_helper->SyjSession->needsLogin();
11 $this->view->headScript()->appendFile('js/prototype.js');
12 $this->view->headScript()->appendFile('js/utils.js');
13 $this->view->headScript()->appendFile('js/account.js');
14 $this->view->headLink()->appendStylesheet('css/generic.css');
15 $this->view->headLink()->appendStylesheet('css/account.css');
16 $this->view->headTitle($this->view->translate("my account"));
19 public function indexAction() {
20 $user = $this->_helper->SyjSession->user();
21 $request = $this->getRequest();
23 $form = new Syj_Form_Account(array('name' => 'accountform'));
24 $formData = $request->getPost();
27 if (!empty($formData) and $form->isValid($formData)) {
29 if ($user->password != sha1($formData['account_password_current'])) {
31 $form->account_password_current->addError(__("Wrong password"));
33 $user->email = $formData['account_email'];
34 $user->password = sha1($formData['account_password']);
35 $userMapper = new Syj_Model_UserMapper();
38 $userMapper->save ($user);
39 } catch(Zend_Db_Statement_Exception $e) {
40 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
41 $message = $e->getMessage();
42 if (strpos($message, 'users_email_key') !== false) {
44 $form->account_email->addError(__("an user is already registered with this email"));
55 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/success.:suffix');
59 if (empty($formData)) {
60 $form->account_email->setValue($user->email);
62 $form->account_email->setValue($formData['account_email']);
65 $this->_jsLocaleStrings();
66 $this->view->form = $form;
69 protected function _jsLocaleStrings() {
70 $this->view->jslocales = array(
71 'notEmptyField' => __("Value is required and can't be empty"),
72 'passwordNoMatchWarn' => __("Password do not match"),
73 'passwordLenghtWarn' => array(__("At least %d characters"), 6),
74 'nochangeWarn' => __("You have made no change"),