00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Adminhtml_System_AccountController extends Mage_Adminhtml_Controller_Action
00036 {
00037 public function indexAction()
00038 {
00039 $this->loadLayout();
00040 $this->_setActiveMenu('system/account');
00041 $this->_addContent($this->getLayout()->createBlock('adminhtml/system_account_edit'));
00042 $this->renderLayout();
00043 }
00044
00045 public function saveAction()
00046 {
00047 $userId = Mage::getSingleton('admin/session')->getUser()->getId();
00048 $pwd = null;
00049
00050 $user = Mage::getModel("admin/user")
00051 ->setId($userId)
00052 ->setUsername($this->getRequest()->getParam('username', false))
00053 ->setFirstname($this->getRequest()->getParam('firstname', false))
00054 ->setLastname($this->getRequest()->getParam('lastname', false))
00055 ->setEmail(strtolower($this->getRequest()->getParam('email', false)));
00056 if ( $this->getRequest()->getParam('password', false) ) {
00057 $user->setPassword($this->getRequest()->getParam('password', false));
00058 }
00059
00060 try {
00061 try {
00062 $_isValid = Zend_Validate::is($user->getUsername(), 'NotEmpty')
00063 && Zend_Validate::is($user->getFirstname(), 'NotEmpty')
00064 && Zend_Validate::is($user->getLastname(), 'NotEmpty')
00065 && Zend_Validate::is($user->getEmail(), 'EmailAddress');
00066
00067 if (!$_isValid) {
00068 Mage::throwException(Mage::helper('adminhtml')->__('Error while saving account. Please check all required fields'));
00069 }
00070 if ($user->userExists()) {
00071 Mage::throwException(Mage::helper('adminhtml')->__('User with the same User Name or Email aleady exists'));
00072 }
00073 $user->save();
00074 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Account successfully saved'));
00075 }
00076 catch (Mage_Core_Exception $e) {
00077 throw $e;
00078 }
00079 catch (Exception $e) {
00080 throw new Exception(Mage::helper('adminhtml')->__('Error while saving account. Please try again later'));
00081 }
00082 }
00083 catch (Exception $e) {
00084 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00085 }
00086 $this->getResponse()->setRedirect($this->getUrl("*/*/"));
00087 }
00088
00089 protected function _isAllowed()
00090 {
00091 return Mage::getSingleton('admin/session')->isAllowed('system/myaccount');
00092 }
00093 }