2 /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class AccountController extends Zend_Controller_Action
8 public function init() {
9 $this->_helper->SyjUserManager->needsLogin();
10 $this->_helper->SyjMedias->addScripts('account');
12 $this->view->headLink()->appendStylesheet('css/generic.css', 'all');
13 $this->view->headLink()->appendStylesheet('css/form.css', 'all');
14 $this->view->headLink()->appendStylesheet('css/account.css', 'all');
15 $this->view->headTitle($this->view->translate("my account"));
18 public function indexAction() {
19 $user = $this->_helper->SyjUserManager->current();
20 $request = $this->getRequest();
22 $form = new Syj_Form_Account(array('name' => 'accountform'));
23 $formData = $request->getPost();
26 if (!empty($formData) and $form->isValid($formData)) {
28 if ($user->password != sha1($formData['account_password_current'])) {
30 $form->account_password_current->addError(__("Wrong password"));
32 $user->email = $formData['account_email'];
33 $user->password = sha1($formData['account_password']);
34 $userMapper = new Syj_Model_UserMapper();
37 $userMapper->save ($user);
38 } catch(Zend_Db_Statement_Exception $e) {
39 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
40 $message = $e->getMessage();
41 if (strpos($message, 'users_email_key') !== false) {
43 $form->account_email->addError(__("an user is already registered with this email"));
54 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/success.:suffix');
58 if (empty($formData)) {
59 $form->account_email->setValue($user->email);
61 $form->account_email->setValue($formData['account_email']);
64 $this->_jsLocaleStrings();
65 $this->view->form = $form;
68 protected function _jsLocaleStrings() {
69 $this->view->jslocales = array(
70 'notEmptyField' => __("Value is required"),
71 'passwordNoMatchWarn' => __("Password do not match"),
72 'passwordLenghtWarn' => array(__("At least %d characters"), 6),
73 'nochangeWarn' => __("You have made no change"),