Ejemplo n.º 1
0
 public function confirmAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_redirect('dashboard');
     }
     // action body
     define("MEMBER", 2);
     $request = $this->getRequest();
     $bootstrap = $this->getInvokeArg('bootstrap');
     $db = $bootstrap->getResource('db');
     // Start a transaction explicitly.
     $db->beginTransaction();
     try {
         // Update the User
         $userMapper = new Application_Model_UserMapper();
         $userMapper->confirm($request->getParams());
         // Add the UserHasRole
         // By default a user has a member role
         $userHasRoleMapper = new Application_Model_UserHasRoleMapper();
         $userHasRole = new Application_Model_UserHasRole();
         $userHasRole->setUserId($request->getParam('id'));
         $userHasRole->setRoleId(MEMBER);
         // @TODO 2 is the role id of member; should be a constant?
         $userHasRoleMapper->save($userHasRole);
         $db->commit();
         $url = $this->view->url(array('action' => 'login', 'controller' => 'auth'));
         // Display success message
         $this->view->msg = "Your registration is complete. You may now <a href='{$url}'>login</a>. ";
     } catch (Exception $e) {
         $db->rollBack();
         throw new Exception($e->getMessage(), $e->getCode());
     }
     //@TODO Send an email with the user's username and password for reference
 }