public function saveAction()
 {
     $profile = $this->_getProfile();
     $form = new Users_Form_PersonalInfo(null, $profile);
     $formData = $this->_request->getPost();
     $form->populate($formData);
     if (!$form->isValid($formData)) {
         $appSession = Zend_Registry::get('appSession');
         $appSession->personalInfoForm = $form;
         $this->_forward('edit');
         return;
     }
     $fieldsValues = new Model_FieldsValues();
     if ($this->_getParam('profile')) {
         $fieldsValues->deleteForProfile($profile);
     } else {
         $profile->user_id = $this->user->id;
         $profile->name = $form->getValue('profileName');
         $profile->save();
     }
     foreach ($form->getValues() as $fieldName => $fieldValue) {
         if ($fieldName == 'profileName' || !$fieldValue) {
             continue;
         }
         $fieldsValue = $fieldsValues->createRow();
         $fieldsValue->user_id = $this->user->id;
         $fieldsValue->profile_id = $profile->id;
         list(, $fieldId) = explode('_', $fieldName);
         $fieldsValue->field_id = $fieldId;
         $fieldsValue->value = $fieldValue;
         $fieldsValue->save();
     }
     $this->_helper->FlashMessenger->addMessage($this->view->translate('Profile has been saved'));
     $this->_redirect('/users/personalinfo');
 }
 public function indexAction()
 {
     $this->view->queryString = $this->_queryString();
     $server = $this->_getOpenIdProvider();
     $request = $server->decodeRequest();
     $this->view->fields = array();
     $this->view->policyUrl = false;
     $profiles = new Users_Model_Profiles();
     $this->view->profiles = $profiles->getForUser($this->user);
     $requestedProfileId = $this->_getParam('profile');
     foreach ($this->view->profiles as $profile) {
         if ($requestedProfileId == 0 || $requestedProfileId == $profile->id) {
             $this->view->profileId = $profile->id;
             $personalInfoForm = Users_Form_PersonalInfo::getForm($request, $profile);
             $this->view->fields = $personalInfoForm->getElements();
             if ($personalInfoForm->getPolicyUrl()) {
                 $this->view->policyUrl = $personalInfoForm->getPolicyUrl();
             }
             break;
         }
     }
     //$this->view->profiles->rewind();
 }
 public function proceedAction()
 {
     // needed for unit tests
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNeverRender(true);
     $server = $this->_getOpenIdProvider();
     $request = $server->decodeRequest();
     if ($request->idSelect()) {
         $id = $this->user->openid;
     } else {
         $id = null;
     }
     $response = $request->answer(true, null, $id);
     if ($this->_hasSreg($request) && $this->_getParam('profileId')) {
         $profiles = new Users_Model_Profiles();
         $profile = $profiles->getRowInstance($this->_getParam('profileId'));
         $personalInfoForm = Users_Form_PersonalInfo::getForm($request, $profile);
         $formData = $this->_request->getPost();
         $personalInfoForm->populate($formData);
         // not planning on validating stuff here yet, but I call this
         // for the date element to be filled properly
         $foo = $personalInfoForm->isValid($formData);
         $sregResponse = Auth_OpenID_SRegResponse::extractResponse($personalInfoForm->getSregRequest(), $personalInfoForm->getUnqualifiedValues());
         $sregResponse->toMessage($response->fields);
     }
     $trustRoot = $this->_getTrustRoot($request);
     if ($this->_getParam('allow')) {
         if ($this->_getParam('forever')) {
             $sites = new Model_Sites();
             $sites->deleteForUserSite($this->user, $trustRoot);
             $siteObj = $sites->createRow();
             $siteObj->user_id = $this->user->id;
             $siteObj->site = $trustRoot;
             $siteObj->creation_date = date('Y-m-d');
             if (isset($personalInfoForm)) {
                 $trusted = array();
                 // using this key name for BC pre 1.1 when we used Zend_OpenId
                 $trusted['Zend_OpenId_Extension_Sreg'] = $personalInfoForm->getUnqualifiedValues();
             } else {
                 $trusted = true;
             }
             $siteObj->trusted = serialize($trusted);
             $siteObj->save();
         }
         $this->_saveHistory($trustRoot, Model_History::AUTHORIZED);
         require_once 'libs/Auth/OpenID/PAPE.php';
         if ($papeRequest = Auth_OpenID_PAPE_Request::fromOpenIDRequest($request)) {
             $this->_processPape($papeRequest, $response);
         }
         $webresponse = $server->encodeResponse($response);
         foreach ($webresponse->headers as $k => $v) {
             if ($k == 'location') {
                 $this->_response->setRedirect($v);
             } else {
                 $this->_response->setHeader($k, $v);
             }
         }
         $this->_response->setHeader('Connection', 'close');
         $this->_response->appendBody($webresponse->body);
     } elseif ($this->_getParam('deny')) {
         if ($this->_getParam('forever')) {
             $sites = new Model_Sites();
             $sites->deleteForUserSite($this->user, $trustRoot);
             $siteObj = $sites->createRow();
             $siteObj->user_id = $this->user->id;
             $siteObj->site = $trustRoot;
             $siteObj->creation_date = date('Y-m-d');
             $siteObj->trusted = serialize(false);
             $siteObj->save();
         }
         $this->_saveHistory($trustRoot, Model_History::DENIED);
         return $this->_sendResponse($server, $request->answer(false));
     }
 }