PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/Ecart/Account/controllers/AuthController.php

https://code.google.com/p/ecartcommerce/
PHP | 114 lines | 70 code | 14 blank | 30 comment | 5 complexity | ef19a36a829bc2944d24c4d30b8c9527 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Ecart
  4. *
  5. * This file is part of Ecart.
  6. *
  7. * Ecart is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Ecart is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Ecart. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @category Ecart
  21. * @package Ecart_Account
  22. * @copyright Copyright 2008-2009 E-Cart LLC
  23. * @license GNU Public License V3.0
  24. */
  25. /**
  26. *
  27. * @category Ecart
  28. * @package Ecart_Account
  29. * @subpackage Controller
  30. * @author Ecart Core Team <core@ecartcommerce.com>
  31. */
  32. class Ecart_Account_AuthController extends Ecart_Core_Controller_Front
  33. {
  34. protected function _generatePassword()
  35. {
  36. mt_srand((double)microtime(1)*1000000);
  37. return md5(mt_rand());
  38. }
  39. public function init()
  40. {
  41. parent::init();
  42. $this->view->crumbs()->add(
  43. Ecart::translate('account')->__('Auth'), '/account/auth'
  44. );
  45. }
  46. public function indexAction()
  47. {
  48. $this->view->pageTitle = Ecart::translate('account')->__(
  49. 'Log in or create an account'
  50. );
  51. if (Ecart::getCustomerId()) {
  52. $this->_redirect('account');
  53. }
  54. $this->render();
  55. }
  56. public function loginAction()
  57. {
  58. Ecart::single('account/customer')->login(
  59. $this->_getParam('username'),
  60. $this->_getParam('password')
  61. );
  62. $this->_redirect($this->_hasSnapshot() ?
  63. $this->_getSnapshot() :
  64. $this->getRequest()->getServer('HTTP_REFERER'));
  65. }
  66. public function logoutAction()
  67. {
  68. Ecart::single('account/customer')->logout();
  69. $this->_redirect($this->getRequest()->getServer('HTTP_REFERER'));
  70. }
  71. public function registerAction()
  72. {
  73. if (Ecart::getCustomerId()) {
  74. $this->_redirect('account');
  75. }
  76. $this->view->pageTitle = Ecart::translate('account')->__(
  77. 'Create an Account'
  78. );
  79. $form = Ecart::single('account/form_signup');
  80. if ($this->_request->isPost()) {
  81. $request = $this->_request->getPost();
  82. if ($form->isValid($request)) {
  83. $mCustomer = Ecart::single('account/customer');
  84. $request['site_id'] = Ecart::getSiteId();
  85. $request['is_active'] = 1;
  86. $result = $mCustomer->save($request);
  87. $mCustomer->login($request['email'], $request['password']);
  88. Ecart::dispatch('account_customer_register_success', array(
  89. 'customer' => $mCustomer->find($result['id'])->current(),
  90. 'password' => $result['password']
  91. ));
  92. return $this->_redirect('account');
  93. } else {
  94. $form->populate($request);
  95. }
  96. }
  97. $this->view->formSignup = $form;
  98. $this->render();
  99. }
  100. }