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();
10 $this->_helper->SyjMedias->addScripts('account');
12 $this->view->headLink()->appendStylesheet('css/generic.css', 'all');
13 $this->view->headLink()->appendStylesheet('css/account.css', 'all');
14 $this->view->headTitle($this->view->translate("my account"));
17 public function indexAction() {
18 $user = $this->_helper->SyjSession->user();
19 $request = $this->getRequest();
21 $form = new Syj_Form_Account(array('name' => 'accountform'));
22 $formData = $request->getPost();
25 if (!empty($formData) and $form->isValid($formData)) {
27 if ($user->password != sha1($formData['account_password_current'])) {
29 $form->account_password_current->addError(__("Wrong password"));
31 $user->email = $formData['account_email'];
32 $user->password = sha1($formData['account_password']);
33 $userMapper = new Syj_Model_UserMapper();
36 $userMapper->save ($user);
37 } catch(Zend_Db_Statement_Exception $e) {
38 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
39 $message = $e->getMessage();
40 if (strpos($message, 'users_email_key') !== false) {
42 $form->account_email->addError(__("an user is already registered with this email"));
53 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/success.:suffix');
57 if (empty($formData)) {
58 $form->account_email->setValue($user->email);
60 $form->account_email->setValue($formData['account_email']);
63 $this->_jsLocaleStrings();
64 $this->view->form = $form;
67 protected function _jsLocaleStrings() {
68 $this->view->jslocales = array(
69 'notEmptyField' => __("Value is required"),
70 'passwordNoMatchWarn' => __("Password do not match"),
71 'passwordLenghtWarn' => array(__("At least %d characters"), 6),
72 'nochangeWarn' => __("You have made no change"),