To actually log in, we direct the form to the action identify within the auth
controller. The identify action??™s job is to use Zend_Auth to check that the supplied username and password is
valid and is shown in listing 6.6.
Listing 6.6 The auth/identify Action
public function identifyAction()
{
$success = false;
$message = '';
if ($this->_request->isPost()) { #1
// collect the data from the user
$formData = $this->_getFormData(); #2
if (empty($formData['username'])
|| empty($formData['password'])) {
$message = 'Please provide a username and password.';
} else {
// do the authentication
$authAdapter = $this->_getAuthAdapter(); #3
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter); #4
if ($result->isValid()) {
// success: store database row to auth's storage
// (Not the password though!)
$data = $authAdapter->getResultRowObject(null,
'password');
$auth->getStorage()->write($data); 5
$success = true;
$redirectUrl = $this->_redirectUrl;
} else {
$message = 'Login failed';
}
}
}
if(!$success) {
$flashMessenger = $this->_helper->FlashMessenger; |#6
$flashMessenger->setNamespace('actionErrors'); |
$flashMessenger->addMessage($message); |
$redirectUrl = '/auth/login'; |
}
$this->_redirect($redirectUrl);
}
(annotation) <#1.
Pages:
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193