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->view->headScript()->appendFile('js/prototype.js');
10 $this->view->headScript()->appendFile('js/utils.js');
11 $this->view->headScript()->appendFile('js/account.js');
12 $this->view->headLink()->appendStylesheet('css/generic.css');
13 $this->view->headLink()->appendStylesheet('css/account.css');
14 $this->view->headTitle($this->view->translate("my account"));
17 public function indexAction() {
18 $user = $this->_helper->SyjSession->user();
19 $request = $this->getRequest();
22 $encodeduri = implode('/', array_map('urlencode', explode('/', $request->getRequestUri())));
23 $loginurl = $this->view->addParamToUrl($this->view->baseUrl() . '/' . 'login', 'redirect', $encodeduri);
24 $translator = Zend_Registry::get('Zend_Translate');
25 $lang = Zend_Controller_Front::getInstance()->getRequest()->getQuery('lang');
27 $adapter = $translator->getAdapter();
28 if ($adapter->isAvailable($lang)) {
29 $loginurl = $this->view->addParamToUrl($loginurl, 'lang', $lang);
32 $this->_helper->Redirector->gotoURL($loginurl, array('prependBase' => false));
35 $form = new Syj_Form_Account(array('name' => 'accountform'));
36 $formData = $request->getPost();
39 if (!empty($formData) and $form->isValid($formData)) {
41 if ($user->password != sha1($formData['account_password_current'])) {
43 $form->account_password_current->addError(__("Wrong password"));
45 $user->email = $formData['account_email'];
46 $user->password = sha1($formData['account_password']);
47 $userMapper = new Syj_Model_UserMapper();
50 $userMapper->save ($user);
51 } catch(Zend_Db_Statement_Exception $e) {
52 if ($e->getCode() == 23505) { // 23505: Unique violation throw new Syj_Exception_Request();
53 $message = $e->getMessage();
54 if (strpos($message, 'users_email_key') !== false) {
56 $form->account_email->addError(__("an user is already registered with this email"));
67 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/success.:suffix');
71 if (empty($formData)) {
72 $form->account_email->setValue($user->email);
74 $form->account_email->setValue($formData['account_email']);
77 $this->_jsLocaleStrings();
78 $this->view->form = $form;
81 protected function _jsLocaleStrings() {
82 $this->view->jslocales = array(
83 'notEmptyField' => __("Value is required and can't be empty"),
84 'passwordNoMatchWarn' => __("Password do not match"),
85 'passwordLenghtWarn' => array(__("At least %d characters"), 6),
86 'nochangeWarn' => __("You have made no change"),