Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------ Controller ----------
- public function loginAction() {
- // action body
- $userForm = new Application_Form_Login();
- $this->view->form = $userForm;
- if ($this->_request->isPost() && $userForm->isValid($_POST)) {
- $username = $this->getRequest()->getParam('username');
- $password = $this->getRequest()->getParam('password');
- $db = Zend_Db::factory('Pdo_Mysql', array(
- 'host' => 'localhost',
- 'username' => 'root',
- 'password' => 'root',
- 'dbname' => 'test'
- ));
- $auth = new Zend_Auth_Adapter_DbTable($db);
- $auth->setTableName('users')
- ->setIdentityColumn('username')
- ->setCredentialColumn('password')
- ->setIdentity($username)
- ->setCredential($password);
- $result = $auth->authenticate();
- if($result->isValid()) {
- $this->_redirect('/secure');
- } else {
- $this->view->loginMessage = "Sorry, your username or password was incorrect: " . $username . "/". $password;
- }
- }
- }
- // -------- View -----------
- <h2>User Login</h2>
- <p>To login to your account please enter your username and password below...</p>
- <?php if($this->loginMessage) { ?>
- <p><?php echo $this->loginMessage?></p>
- <?php } ?>
- <form action="login" method="POST" action="">
- <input type="text" name="username" value="" /><br />
- <input type="text" name="password" value="" /><br />
- <input type="submit" value="submit" />
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement