Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Application_Model_Authenticate
- {
- function __construct(){
- }
- public function checkCreds($username, $password)
- {
- $db = Zend_Db_Table::getDefaultAdapter();
- $authAdapter = new Zend_Auth_Adapter_DbTable($db);
- $authAdapter
- ->setTableName('users')
- ->setIdentityColumn('username')
- ->setCredentialColumn('password')
- ->setIdentity($username)
- ->setCredential($password)
- ->setCredentialTreatment('MD5(?)');
- $result = $authAdapter->authenticate();
- return $result->isValid();
- }
- }
- //login view
- <br /><br />
- <div id="view-content">
- <p>Login to the app!</p>
- <form action="login" method="post" enctype="application/x-www-form-urlencoded">
- <fieldset>
- <legend>Login!</legend>
- <dl>
- <dt><label for="name">Your name:</label></dt>
- <dd><input type="text" name="name" value="<?php $this->nameValue; ?>" /></dd>
- </dl>
- <dl>
- <dt><label for="password">Your Password:</label></dt>
- <dd><input type="password" name="password" value="" /></dd>
- </dl>
- <dl>
- <dt><label for="submit">Login:</label></dt>
- <dd><input type="submit" name="submit" value="Login" /></dd>
- </dl>
- </fieldset>
- </form>
- <a href="/users/logout" title="logout">Logout</a>
- <br />
- <?php
- if ($this->auth){
- echo 'logged in correctly!';
- }else{
- echo 'not logged in!';
- }
- ?>
- </div>
- //users controller
- public function loginAction()
- {
- if ($this->getRequest()->isPost() )
- {
- $username = $this->getRequest()->getPost('name');
- $password = $this->getRequest()->getPost('password');
- $authObject = new Application_Model_Authenticate();
- $loginStatus = $authObject->checkCreds($username, $password);
- $this->view->auth = $loginStatus;
- $this->view->nameValue = $username;
- }
- }
- public function logoutAction(){
- Zend_Auth::getInstance()->clearIdentity();
- $this->_helper->redirector('login');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement