/app/code/Ecart/Account/controllers/AuthController.php
PHP | 114 lines | 70 code | 14 blank | 30 comment | 5 complexity | ef19a36a829bc2944d24c4d30b8c9527 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
- <?php
- /**
- * Ecart
- *
- * This file is part of Ecart.
- *
- * Ecart is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Ecart is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category Ecart
- * @package Ecart_Account
- * @copyright Copyright 2008-2009 E-Cart LLC
- * @license GNU Public License V3.0
- */
- /**
- *
- * @category Ecart
- * @package Ecart_Account
- * @subpackage Controller
- * @author Ecart Core Team <core@ecartcommerce.com>
- */
- class Ecart_Account_AuthController extends Ecart_Core_Controller_Front
- {
- protected function _generatePassword()
- {
- mt_srand((double)microtime(1)*1000000);
- return md5(mt_rand());
- }
- public function init()
- {
- parent::init();
- $this->view->crumbs()->add(
- Ecart::translate('account')->__('Auth'), '/account/auth'
- );
- }
- public function indexAction()
- {
- $this->view->pageTitle = Ecart::translate('account')->__(
- 'Log in or create an account'
- );
- if (Ecart::getCustomerId()) {
- $this->_redirect('account');
- }
- $this->render();
- }
- public function loginAction()
- {
- Ecart::single('account/customer')->login(
- $this->_getParam('username'),
- $this->_getParam('password')
- );
- $this->_redirect($this->_hasSnapshot() ?
- $this->_getSnapshot() :
- $this->getRequest()->getServer('HTTP_REFERER'));
- }
- public function logoutAction()
- {
- Ecart::single('account/customer')->logout();
- $this->_redirect($this->getRequest()->getServer('HTTP_REFERER'));
- }
- public function registerAction()
- {
- if (Ecart::getCustomerId()) {
- $this->_redirect('account');
- }
- $this->view->pageTitle = Ecart::translate('account')->__(
- 'Create an Account'
- );
- $form = Ecart::single('account/form_signup');
- if ($this->_request->isPost()) {
- $request = $this->_request->getPost();
- if ($form->isValid($request)) {
- $mCustomer = Ecart::single('account/customer');
- $request['site_id'] = Ecart::getSiteId();
- $request['is_active'] = 1;
- $result = $mCustomer->save($request);
- $mCustomer->login($request['email'], $request['password']);
- Ecart::dispatch('account_customer_register_success', array(
- 'customer' => $mCustomer->find($result['id'])->current(),
- 'password' => $result['password']
- ));
- return $this->_redirect('account');
- } else {
- $form->populate($request);
- }
- }
- $this->view->formSignup = $form;
- $this->render();
- }
- }