function login()
 {
     $t_user = new ca_users();
     # --- pass form elements for reg form
     $this->view->setVar("fname", $t_user->htmlFormElement("fname", "<div><b>" . _t("First name") . "</b><br/>^ELEMENT</div>"));
     $this->view->setVar("lname", $t_user->htmlFormElement("lname", "<div><b>" . _t("Last name") . "</b><br/>^ELEMENT</div>"));
     $this->view->setVar("email", $t_user->htmlFormElement("email", "<div><b>" . _t("Email address") . "</b><br/>^ELEMENT</div>"));
     $this->view->setVar("password", $t_user->htmlFormElement("password", "<div><b>" . _t("Password") . "</b><br/>^ELEMENT</div>"));
     if (!$this->request->doAuthentication(array('dont_redirect' => true, 'user_name' => $this->request->getParameter('username', pString), 'password' => $this->request->getParameter('password', pString)))) {
         $this->view->setVar('loginMessage', _t("Login failed. Please try again."));
         $this->form($t_user);
     } else {
         if ($this->request->isLoggedIn()) {
             # --- login successful so redirect to search page
             $this->notification->addNotification(_t("You are now logged in"), __NOTIFICATION_TYPE_INFO__);
             $vo_session = $this->request->getSession();
             $vs_last_page = $vo_session->getVar('site_last_page');
             $vo_session->setVar('site_last_page', "");
             switch ($vs_last_page) {
                 case "Sets":
                     $this->response->setRedirect(caNavUrl($this->request, "", "Sets", "addItem", array("object_id" => $vo_session->getVar('site_last_page_object_id'))));
                     break;
                     # --------------------
                 # --------------------
                 case "ObjectDetail":
                     $this->response->setRedirect(caNavUrl($this->request, "Detail", "Object", "Show", array("object_id" => $vo_session->getVar('site_last_page_object_id'))));
                     break;
                     # --------------------
                 # --------------------
                 default:
                     if (!($vs_url = $this->request->session->getVar('pawtucket2_last_page'))) {
                         $vs_action = $vs_controller = $vs_module_path = '';
                         if ($vs_default_action = $this->request->config->get('default_action')) {
                             $va_tmp = explode('/', $vs_default_action);
                             $vs_action = array_pop($va_tmp);
                             if (sizeof($va_tmp)) {
                                 $vs_controller = array_pop($va_tmp);
                             }
                             if (sizeof($va_tmp)) {
                                 $vs_module_path = join('/', $va_tmp);
                             }
                         } else {
                             $vs_controller = 'Splash';
                             $vs_action = 'Index';
                         }
                         $vs_url = caNavUrl($this->request, $vs_module_path, $vs_controller, $vs_action);
                     }
                     $this->response->setRedirect($vs_url);
                     break;
                     # --------------------
             }
         } else {
             $va_errors["register"] = _t("Login failed.");
         }
         return;
     }
 }