All pastes #805506 Raw Edit

Untitled

public php v1 · immutable
·published 2007-12-04 12:50 UTC
rendered paste body
<?phpclass UsersController extends AppController{    function index()    {        }    function search()    {        // The site's primary search function        // By default a search will not be performed without sufficent params        $search = false;        // Params will be assigned from HTTP GET into an array        $searchParams = array();        // Check if required params were submitted        if (!empty($_GET['name']))        {            $searchParams['name'] = $_GET['name'];            $search = true;        }        else        {            $search = false;        }        // Redirect back to homepage if a search cannot be performed        if (!$search)        {            // Remember the $error var in the view? Let's set that to true:            $this->set('error', true);            $this->redirect('/');        }        // Assign conditions        $conditions = array("User.family_name" => "LIKE %{$searchParams['name']}%");        // Perform search in database with user table        $results = $this->User->findAll($conditions);        // Assign results to global        $this->set('results', $results);    }    function login()    {        //Don't show the error message if no data has been submitted.        $this->set('error', false);         // If a user has submitted form data:        if (!empty($this->data))        {            // First, let's see if there are any users in the database            // with the username supplied by the user using the form:            $someone = $this->User->findByUsername($this->data['User']['username']);            // At this point, $someone is full of user data, or its empty.            // Let's compare the form-submitted password with the one in             // the database.            if(!empty($someone['User']['password']) && $someone['User']['password'] == $this->data['User']['password'])            {                // Note: hopefully your password in the DB is hashed,                 // so your comparison might look more like:                // md5($this->data['User']['password']) == ...                // This means they were the same. We can now build some basic                // session information to remember this user as 'logged-in'.                $this->Session->write('User', $someone['User']);                // Now that we have them stored in a session, forward them on                // to a landing page for the application.                 $this->redirect('/');            }            // Else, they supplied incorrect data:            else            {                // Remember the $error var in the view? Let's set that to true:                $this->set('error', true);            }        }    }    function logout()    {        // Redirect users to this action if they click on a Logout button.        // All we need to do here is trash the session information:        $this->Session->delete('User');        // And we should probably forward them somewhere, too...             $this->redirect('/');    }    function info()    {        $this->checkSession();    }    function create()    {        if (empty($this->data))        {            $this->render();        }        else        {            if ($this->User->validates())            {             //ok cool, the stuff is valid                $this->redirect('/fook');            }            else            {                //Danger, Will Robinson. Validation errors.                $this->set('errorMessage', 'Please correct errors below.');                $this->render();            }        }    }}?>