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');
11 $this->_helper->SyjMedias->addStyleSheets('account');
13 $this->view->headTitle($this->view->translate("my account"));
16 public function indexAction() {
17 $user = $this->_helper->SyjUserManager->current();
18 $request = $this->getRequest();
20 $form = new Syj_Form_Account(array('name' => 'accountform'));
21 $formData = $request->getPost();
24 if (!empty($formData) and $form->isValid($formData)) {
26 if ($user->password != sha1($formData['account_password_current'])) {
28 $form->account_password_current->addError(__("Wrong password"));
30 $user->email = $formData['account_email'];
31 $user->password = sha1($formData['account_password']);
32 $userMapper = new Syj_Model_UserMapper();
35 $userMapper->save ($user);
36 } catch(Zend_Db_Statement_Exception $e) {
37 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
38 $message = $e->getMessage();
39 if (strpos($message, 'users_email_key') !== false) {
41 $form->account_email->addError(__("an user is already registered with this email"));
52 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/success.:suffix');
56 if (empty($formData)) {
57 $form->account_email->setValue($user->email);
59 $form->account_email->setValue($formData['account_email']);
62 $this->_jsLocaleStrings();
63 $this->view->form = $form;
66 protected function _jsLocaleStrings() {
67 $this->view->jslocales = array(
68 'notEmptyField' => __("Value is required"),
69 'passwordNoMatchWarn' => __("Password do not match"),
70 'passwordLenghtWarn' => array(__("At least %d characters"), 6),
71 'nochangeWarn' => __("You have made no change"),