LoginController.php
00001 <?php
00017 class User_LoginController extends Dsao_Controller_Action
00018 {
00019 public function preDispatch()
00020 {
00021 $this->_setDefaultModelClass('User_Login');
00022 }
00023
00029 public function loginAction()
00030 {
00031 if ($this->getRequest()->isPost())
00032 {
00033
00034 if (!$this->getRequest()->getPost('username'))
00035 {
00036 return false;
00037 }
00038
00039 $username = $this->getRequest()->getPost('username');
00040 $password = $this->getRequest()->getPost('password');
00041
00042 $validatorUsername = new Dsao_Validate_Username();
00043 $validatorPassword = new Dsao_Validate_Password();
00044
00045
00046 if ($validatorUsername->isValid($username)
00047 && $validatorPassword->isValid($password))
00048 {
00049
00050 $user = new Dsao_User(array
00051 (
00052 'username' => $username,
00053 'password' => md5($password),
00054 ), false, true);
00055
00056
00057 if ($this->_getModel()->login($user, $this->getRequest()->getPost('autologin')))
00058 {
00059 $uriReturn = new Dsao_Uri_Http(str_replace('_', '/',
00060 $this->getUri()->getParameters('redirect', '_')));
00061
00062
00063 $uriReturn->setParameters(array(
00064 'action' => 'show',
00065 'controller' => 'index',
00066 'module' => 'default'), false);
00067
00068
00069 $this->_gotoSimple($uriReturn->action, $uriReturn->controller,
00070 $uriReturn->module, $uriReturn->getParameters());
00071
00072 return true;
00073 }
00074 }
00075
00076 $this->getLog()->err('user_login_login_error_wrong_data');
00077 }
00078
00079
00080 $this->getView()->assign
00081 ('userLoginRedirect', $this->getUri()->redirect);
00082
00083 return true;
00084 }
00085
00091 public function logoutAction()
00092 {
00093
00094 if (!$this->getHelper('SessionToken')->hasValidToken())
00095 {
00096 return;
00097 }
00098
00099
00100 $this->_getModel()->logout();
00101
00102
00103 $this->_gotoSimple('show', 'index', 'default');
00104 }
00105
00116 public function passwordAction()
00117 {
00118 $this->getHelper('History')->setAddToHistory(true, false);
00119
00120
00121 if ($this->getRequest()->isPost())
00122 {
00123
00124 if (!$this->getRequest()->getPost('username')
00125 && !$this->getRequest()->getPost('emailAddress'))
00126 {
00127 return false;
00128 }
00129
00130
00131 $user = new Dsao_User(array
00132 (
00133 'username' => $this->getRequest()->getPost('username'),
00134 'emailAddress' => $this->getRequest()->getPost('emailAddress'),
00135 ));
00136
00137
00138 if (!$user->isSynchronous(true))
00139 {
00140
00141 $this->getLog()->err('user_login_password_error_user_not_found');
00142
00143 return false;
00144 }
00145
00146
00147 $user->passwordNew = Dsao_Hash_Password::factory();
00148
00149
00150 $user->hash = Dsao_Hash_User::factory($user->passwordNew->getHash(),
00151 '/user/login/password', array('idUser' => $user->getId()));
00152
00153
00154 $user->hash->insert();
00155
00156
00157
00158 if (!$this->_getModel()->sendNewPasswordMail($user))
00159 {
00160 $this->getLog()->err('email_error_sent');
00161
00162 return false;
00163 }
00164
00165
00166 $this->getLog()->affirm
00167 ('user_login_password_affirmation_email_sent');
00168
00169 return true;
00170 }
00171
00172
00173
00174 if ($this->getUri()->hasParameters())
00175 {
00176
00177 $hashUser = Dsao_Hash_User::factory(null, $this->getUri());
00178
00179
00180 if (!$hashUser->isValid())
00181 {
00182 $this->getLog()->err('user_login_password_error_invalid_link');
00183
00184 return false;
00185 }
00186
00187
00188 $user = new Dsao_User(array
00189 (
00190 'id' => $hashUser->idUser,
00191 'password' => $hashUser->hash,
00192 ));
00193
00194
00195 $user->updateData('password');
00196
00197
00198 $this->getLog()->affirm
00199 ('user_login_password_affirmation_changed');
00200
00201 return true;
00202 }
00203
00204
00205 $this->getLog()->info('user_login_password_info_new');
00206
00207 return true;
00208 }
00209 }