PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/application/admin/controllers/AuthController.php

http://digitalus-site-manager.googlecode.com/
PHP | 139 lines | 86 code | 16 blank | 37 comment | 17 complexity | 94f29b0412128fa8eb050f4c87b3aa15 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * DSF CMS
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://digitalus-media.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to info@digitalus-media.com so we can send you a copy immediately.
  14. *
  15. * @category DSF CMS
  16. * @package DSF_CMS_Controllers
  17. * @copyright Copyright (c) 2007 - 2008, Digitalus Media USA (digitalus-media.com)
  18. * @license http://digitalus-media.com/license/new-bsd New BSD License
  19. * @version $Id: AuthController.php Mon Dec 24 20:48:35 EST 2007 20:48:35 forrest lyman $
  20. */
  21. class Admin_AuthController extends Zend_Controller_Action
  22. {
  23. function init()
  24. {
  25. $this->view->breadcrumbs = array(
  26. $this->view->GetTranslation('Login') => '/admin/auth/login'
  27. );
  28. }
  29. /**
  30. * if the form has not been submitted this renders the login form
  31. * if it has then it validates the data
  32. * if it is sound then it runs the DSF_Auth_Adapter function
  33. * to authorise the request
  34. * on success it redirct to the admin home page
  35. *
  36. */
  37. function loginAction()
  38. {
  39. if ($this->_request->isPost()) {
  40. $username = DSF_Filter_Post::get('adminUsername');
  41. $password = DSF_Filter_Post::raw('adminPassword');
  42. $e = new DSF_View_Error();
  43. if($username == ''){
  44. $e->add($this->view->GetTranslation("You must enter a username."));
  45. }
  46. if($password == ''){
  47. $e->add($this->view->GetTranslation("You must enter a password."));
  48. }
  49. if (!$e->hasErrors()) {
  50. $auth = new DSF_Auth($username, $password);
  51. $result = $auth->authenticate();
  52. Zend_Debug::dump($result);
  53. if($result){
  54. $url = DSF_Filter_Post::get('uri');
  55. if($url == '' || $url == '/admin/auth/login'){
  56. $url = '/admin';
  57. }
  58. }else{
  59. $e = new DSF_View_Error();
  60. $e->add($this->view->GetTranslation('The username or password you entered was not correct.'));
  61. $url = "/admin/auth/login";
  62. }
  63. }else{
  64. $url = "/admin/auth/login";
  65. }
  66. $this->_redirect($url);
  67. }
  68. }
  69. /**
  70. * kills the authorized user object
  71. * then redirects to the main index page
  72. *
  73. */
  74. function logoutAction()
  75. {
  76. DSF_Auth::destroy();
  77. $this->_redirect("/");
  78. }
  79. function resetPasswordAction()
  80. {
  81. if (strtolower($_SERVER["REQUEST_METHOD"]) == "post") {
  82. $email = DSF_Filter_Post::get('email');
  83. $user = new User();
  84. $match = $user->getUserByUsername($email);
  85. if($match){
  86. //create the password
  87. $password = DSF_Toolbox_String::random(10); //10 character random string
  88. //load the email data
  89. $data['first_name'] = $match->first_name;
  90. $data['last_name'] = $match->last_name;
  91. $data['username'] = $match->email;
  92. $data['password'] = $password;
  93. //get standard site settings
  94. $s = new SiteSettings();
  95. $settings = $s->toObject();
  96. //attempt to send the email
  97. $mail = new DSF_Mail();
  98. if($mail->send($match->email, array($sender), "Password Reminder", 'passwordReminder', $data))
  99. {
  100. //update the user's password
  101. $match->password = md5($password);
  102. $match->save();//save the new password
  103. $m = new DSF_View_Message();
  104. $m->add(
  105. $this->view->GetTranslation("Your password has been reset for security and sent to your email address")
  106. );
  107. }else{
  108. $e = new DSF_View_Error();
  109. $e->add(
  110. $this->view->GetTranslation("Sorry, there was an error sending you your updated password. Please contact us for more help.")
  111. );
  112. }
  113. }else{
  114. $e = new DSF_View_Error();
  115. $e->add(
  116. $this->view->GetTranslation("Sorry, we could not locate your account. Please contact us to resolve this issue.")
  117. );
  118. }
  119. $url = "/admin/auth/login";
  120. $this->_redirect($url);
  121. }
  122. }
  123. }