1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34:
35: class Mage_Adminhtml_System_AccountController extends Mage_Adminhtml_Controller_Action
36: {
37: public function indexAction()
38: {
39: $this->_title($this->__('System'))->_title($this->__('My Account'));
40:
41: $this->loadLayout();
42: $this->_setActiveMenu('system/account');
43: $this->_addContent($this->getLayout()->createBlock('adminhtml/system_account_edit'));
44: $this->renderLayout();
45: }
46:
47: 48: 49:
50: public function saveAction()
51: {
52: $userId = Mage::getSingleton('admin/session')->getUser()->getId();
53: $pwd = null;
54:
55: $user = Mage::getModel("admin/user")->load($userId);
56:
57: $user->setId($userId)
58: ->setUsername($this->getRequest()->getParam('username', false))
59: ->setFirstname($this->getRequest()->getParam('firstname', false))
60: ->setLastname($this->getRequest()->getParam('lastname', false))
61: ->setEmail(strtolower($this->getRequest()->getParam('email', false)));
62: if ( $this->getRequest()->getParam('new_password', false) ) {
63: $user->setNewPassword($this->getRequest()->getParam('new_password', false));
64: }
65:
66: if ($this->getRequest()->getParam('password_confirmation', false)) {
67: $user->setPasswordConfirmation($this->getRequest()->getParam('password_confirmation', false));
68: }
69:
70: $result = $user->validate();
71: if (is_array($result)) {
72: foreach($result as $error) {
73: Mage::getSingleton('adminhtml/session')->addError($error);
74: }
75: $this->getResponse()->setRedirect($this->getUrl("*/*/"));
76: return;
77: }
78:
79: try {
80: $user->save();
81: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The account has been saved.'));
82: }
83: catch (Mage_Core_Exception $e) {
84: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
85: }
86: catch (Exception $e) {
87: Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('An error occurred while saving account.'));
88: }
89: $this->getResponse()->setRedirect($this->getUrl("*/*/"));
90: }
91:
92: protected function _isAllowed()
93: {
94: return Mage::getSingleton('admin/session')->isAllowed('system/myaccount');
95: }
96: }
97: