public function executeDelete(sfWebRequest $request) { $request->checkCSRFProtection(); $this->forward404Unless($sfGuardUser = sfGuardUserPeer::retrieveByPk($request->getParameter('id')), sprintf('Object sfGuardUser does not exist (%s).', $request->getParameter('id'))); $sfGuardUser->delete(); $this->redirect('sfguarduser/index'); }
public function getOtherUser($user_id) { $id = $this->getOther($user_id); if ($id != false) { return sfGuardUserPeer::retrieveByPk($id); } else { return false; } }
protected function doCall() { $this->context = $this->getContext(true); $admin = sfGuardUserPeer::retrieveByPk(1); $this->context->getUser()->signIn($admin); ob_start(); $this->context->getController()->dispatch(); $html = ob_get_clean(); }
/** * Get the associated sfGuardUser object * * @param PropelPDO Optional Connection object. * @return sfGuardUser The associated sfGuardUser object. * @throws PropelException */ public function getsfGuardUser(PropelPDO $con = null) { if ($this->asfGuardUser === null && $this->user_id !== null) { $this->asfGuardUser = sfGuardUserPeer::retrieveByPk($this->user_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->asfGuardUser->addsfGuardUserPermissions($this); */ } return $this->asfGuardUser; }
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(6, new lime_output_color()); $data = array('hello' => 'value1', 'hello2' => 123); $encoded = afAuthenticDatamaker::encode($data); $t->is(afAuthenticDatamaker::decode($encoded), $data); $encoded = afAuthenticDatamaker::encode($data, 1); $t->is(afAuthenticDatamaker::decode($encoded), null); $t->is(afAuthenticDatamaker::decode('wrongInput'), null); $t->is(afAuthenticDatamaker::decode(null), null); $t->is(afAuthenticDatamaker::decode(''), null); sfConfig::set('app_appFlower_siteSecret', 'CHANGE_ME'); $apikey = afApikeySecurityFilter::getApiKey(sfGuardUserPeer::retrieveByPk(1)); $t->is($apikey, 'RPQgOL2Pwgj06P4mkWHnip2iZMc~admin');
public function getGuardUser() { if (!$this->user && ($id = $this->getAttribute('user_id', null, 'sfGuardSecurityUser'))) { $this->user = sfGuardUserPeer::retrieveByPk($id); if (!$this->user) { // the user does not exist anymore in the database $this->signOut(); throw new sfException('The user does not exist anymore in the database.'); } } return $this->user; }
/** * Get the associated sfGuardUser object * * @param PropelPDO Optional Connection object. * @return sfGuardUser The associated sfGuardUser object. * @throws PropelException */ public function getsfGuardUserRelatedByCheckBy(PropelPDO $con = null) { if ($this->asfGuardUserRelatedByCheckBy === null && ($this->check_by !== "" && $this->check_by !== null)) { $this->asfGuardUserRelatedByCheckBy = sfGuardUserPeer::retrieveByPk($this->check_by); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->asfGuardUserRelatedByCheckBy->addLogssRelatedByCheckBy($this); */ } return $this->asfGuardUserRelatedByCheckBy; }
public function executeConfirmRegistrationEmail() { // TODO: Remove this? // -> This is all in user/register now $this->user = sfGuardUserPeer::retrieveByPk($this->getRequest()->getAttribute('user_id')); $this->forward404Unless($this->user, 'user not found, cannot send confirmation registration email'); $conn = new Swift_Connection_SMTP(sfConfig::get('mod_sfswiftmailer_smtp_host')); // Need auth for SMTP $conn->setUsername(sfConfig::get('mod_sfswiftmailer_smtp_user')); $conn->setPassword(sfConfig::get('mod_sfswiftmailer_smtp_pass')); $mailer = new Swift($conn); // Get our message bodies $htmlBody = $this->getPresentationFor('messages', 'confirmRegistrationHtml'); $textBody = $this->getPresentationFor('messages', 'confirmRegistrationText'); //Create a message $message = new Swift_Message("Thank you for joining the Cothink community. Please confirm your email address to complete registration."); //Add some "parts" $message->attach(new Swift_Message_Part($textBody)); $message->attach(new Swift_Message_Part($htmlBody, "text/html")); // Send out our mailer $mailer->send($message, $this->user->getUsername(), '*****@*****.**'); $mailer->disconnect(); return sfView::SUCCESS; }
public function executeJsonGridInfo(sfWebRequest $request) { $isAjax = $request->isXmlHttpRequest(); if (!$isAjax) { return $this->redirect('@homepage'); } $this->sfGuardUser = sfGuardUserPeer::retrieveByPk($request->getParameter('id')); $user_info = $this->sfGuardUser->toArray(); // Get profile. $profile = $this->sfGuardUser->getProfile(); $profile_info = $profile->toArray(); //user groups $groups = $this->sfGuardUser->getGroups(); $group_ids = array(); foreach ($groups as $group) { $group_ids[] = $group->getId(); } //user permissions $id = $request->getParameter('id'); $c = new Criteria(); $c->add(EtvaPermissionUserPeer::USER_ID, $id, Criteria::EQUAL); //$c->addJoin(EtvaPermissionPeer::ID, EtvaPermissionUserPeer::ETVAPERM_ID); $perms = EtvaPermissionUserPeer::doSelect($c); //error_log(print_r($perms, true)); $permission_ids = array(); foreach ($perms as $p) { $permission_ids[] = $p->getEtvaPermission()->getId(); } error_log(print_r($permission_ids, true)); // $permissions = $this->sfGuardUser->getPermissions(); // $permission_ids = array(); // foreach($permissions as $permission) // $permission_ids[] = $permission->getId(); $user_service_list = array(); $etva_user_service = EtvaUserServiceQuery::create()->filterByUserId($id)->useEtvaServiceQuery("EtvaService", "INNER JOIN")->endUse()->find(); foreach ($etva_user_service as $uservice) { array_push($user_service_list, array('service_id' => $uservice->getServiceId(), 'extra' => $uservice->getExtra())); } $elements = array_merge($user_info, $profile_info, array('sf_guard_user_group_list' => $group_ids), array('sf_guard_user_permission_list' => $permission_ids), array('user_service_list' => $user_service_list)); $final = array('success' => true, 'data' => $elements); $result = json_encode($final); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); }
public function hasGroup($group, $user_id) { $user = sfGuardUserPeer::retrieveByPk($user_id); // $user is sfGuardUser ID sfContext::getInstance()->getLogger()->info('checking for group [' . $this->getUuid() . '-' . $group . '] for user [' . $user . ']'); if ($user->hasGroup($this->getUuid() . '-' . $group)) { sfContext::getInstance()->getLogger()->info('found, in group'); return true; } sfContext::getInstance()->getLogger()->info('not found, not in group'); return false; }
public function getUser() { return sfGuardUserPeer::retrieveByPk($this->getUserId())->getProfile(); }
/** * Add client into new build * @param web request $request */ public function executeBuild($request) { $sf_user = $this->getUser(); $sf_guard_user = $sf_user->getGuardUser(); $sf_user_id = $sf_guard_user->getId(); $sf_user_profile = $sf_guard_user->getProfile(); $sf_user_fullname = $sf_user_profile->getFullname(); $sf_user_name = $sf_guard_user->getUsername(); $branch_id = $sf_user->getUserBranch()->getId(); $client_id = $request->getParameter('id'); $client_details = ProfilePeer::retrieveByPK($client_id); $client_user_id = $client_details->getUserId(); // if ($client_user_id) { // $branch_id = ProfilePeer::getClientBranch($client_user_id)->getBranchId(); // } // $temp[$sf_user_id] = $sf_user_fullname; $leaders = ProfilePeer::getBranchUsers($branch_id, sfGuardGroupPeer::BRANCH_OFFICE_STAFF); $this->leader = $leaders; foreach ($leaders as $leader) { $temp[$leader->getUserId()] = $leader->getFullname(); } $this->leader_id = $temp; $this->defult_leader = 0; $this->client_id = 0; $this->form = new pmProjectsForm(); if ($request->isMethod('post')) { $form_data = $request->getParameter('pm_projects'); $client_branch_id = BranchUsersPeer::getUserBranchId($client_user_id); $form_data['created_by_id'] = $sf_user_id; $form_data['created_by_name'] = $sf_user_name; $form_data['created_by_email'] = $sf_user_profile->getEmail(); $form_data['branch_id'] = $client_branch_id; $form_data['client_id'] = $client_user_id; $leader_id = $this->getRequestParameter('leader_id'); if ($leader_id) { $form_data['leader_id'] = $leader_id; $project_manager = sfGuardUserPeer::retrieveByPk($leader_id); $manager_profile = $project_manager->getProfile(); $form_data['leader_name'] = $manager_profile->getFullname(); $form_data['leader_email'] = $manager_profile->getEmail(); } $this->form->bind($form_data); if ($this->form->isValid()) { $pm_projects = $this->form->save(); $new_project_id = $pm_projects->getId(); $new_project_name = $pm_projects->getName(); // add build default file groups $build_default_files = array(1 => 'Plan and Specs', 2 => 'Images', 3 => 'Variation', 4 => 'Others', 5 => 'Tender'); if ($build_default_files) { foreach ($build_default_files as $file) { $newfilelist = new pmProjectObjects(); $newfilelist->setModule('resources list'); $newfilelist->setProjectId($new_project_id); $newfilelist->setName($file); $newfilelist->setCreatedById($sf_user_id); $newfilelist->setCreatedByName($sf_user_fullname); $newfilelist->save(); } } // add new project entry into form table $project_form = new pmForms(); $project_form->setProjectId($new_project_id); $project_form->setName($new_project_name); $project_form->setCreatedById($user_id); $project_form->save(); // add new client into new build $project_clients = new pmProjectUsers(); $project_clients->setProjectId($new_project_id); $project_clients->setUserId($client_user_id); $project_clients->setCreatedAt(date('Y-m-d H:i:s')); $project_clients->save(); $project_leader = new pmProjectUsers(); $project_leader->setProjectId($new_project_id); $project_leader->setUserId($leader_id); $project_leader->setCreatedAt(date('Y-m-d H:i:s')); $project_leader->save(); $modification_message = 'Add Client to new Build, Build Name: ' . $new_project_name . ' Id: ' . $new_project_id; $this->saveHistory($modification_message, $client_user_id); $this->getUser()->setFlash('notice', '"' . $new_project_name . '" has been created successfully'); $this->redirect('build/show?id=' . $new_project_id . '&project_id=' . $new_project_id); } $this->setTemplate('build'); } }
public function executeEdit(sfWebRequest $request) { $this->hasDeepUpdates = false; $c = new Criteria(); $c->add(PropuestaPeer::IS_ACTIVE, true); $this->propuestasCount = PropuestaPeer::doCount($c); $this->isCanonicalVootaUser = SfVoUtil::isCanonicalVootaUser($this->getUser()->getGuardUser()); if ($this->getUser()->isAuthenticated()) { $this->lastReview = SfReviewManager::getLastReviewByUserId($this->getUser()->getGuardUser()->getId()); $this->lastReviewOnReview = SfReviewManager::getLastReviewOnReviewByUserId($this->getUser()->getGuardUser()->getId()); } $this->redirectUnless($this->getUser()->isAuthenticated(), "@sf_guard_signin"); $formData = sfGuardUserPeer::retrieveByPk($this->getUser()->getGuardUser()->getId()); if (!SfVoUtil::isEmail($formData->getUsername())) { $formData->setUsername(''); } $this->profileEditForm = new ProfileEditForm($formData); $this->politico = false; $politicos = $this->getUser()->getGuardUser()->getPoliticos(); if ($politicos && count($politicos) != 0) { $this->politico = $politicos[0]; unset($this->profileEditForm['nombre'], $this->profileEditForm['apellidos']); } $imagenOri = $formData->getProfile()->getImagen(); $criteria = new Criteria(); $criteria->add(SfReviewPeer::IS_ACTIVE, true); $criteria->add(SfReviewPeer::SF_GUARD_USER_ID, $this->getUser()->getGuardUser()->getId()); $this->numReviews = SfReviewPeer::doCount($criteria); if ($request->isMethod('post')) { $this->profileEditForm->bind($request->getParameter('profile'), $request->getFiles('profile')); if ($this->profileEditForm->isValid()) { /*if ($this->politico){ $cacheManager = $this->getContext()->getViewCacheManager(); if ($cacheManager != null) { $politico = $this->getRoute()->getObject(); $cacheManager->remove("politico/show?id=".$politico->getVanity().""); } }*/ $profile = $request->getParameter('profile'); $this->hasDeepUpdates = $profile['presentacion'] != $formData->getProfile()->getPresentacion(); if ($this->profileEditForm->getValue('imagen_delete') != "") { // Si se elimina la imagen, hay que recargar el formulario para que se refresque $formData->getProfile()->setImagen(""); //$formData->getProfile()->save(); $this->profileEditForm->setImageSrc(""); $this->profileEditForm->resetImageWidget(); //$this->profileEditForm = new ProfileEditForm( $formData ); } else { $imageOri = $this->profileEditForm->getObject()->getProfile()->getImagen(); $imagen = $this->profileEditForm->getValue('imagen'); $this->profileEditForm->save(); if ($imagen) { $arr = array_reverse(explode(".", $imagen->getOriginalName())); $ext = strtolower($arr[0]); if (!$ext || $ext == "") { $ext = "png"; } $imageName = $this->profileEditForm->getValue('nombre') ? $this->profileEditForm->getValue('nombre') : $arr[1]; if ($this->profileEditForm->getValue('apellidos') != '') { $imageName .= "-" . $this->profileEditForm->getValue('apellidos'); } $imageName .= "-" . sprintf("%04d", rand(0, 999)); $imageName .= ".{$ext}"; $imagen->save(sfConfig::get('sf_upload_dir') . '/usuarios/' . $imageName); $this->profileEditForm->getObject()->getProfile()->setImagen($imageName); $this->profileEditForm->setImageSrc($imageName); $this->profileEditForm->resetImageWidget(); $this->hasDeepUpdates = true; } else { $this->profileEditForm->getObject()->getProfile()->setImagen($imagenOri); $this->profileEditForm->setImageSrc($imagenOri); } } if ($profile['passwordNew'] != '') { // Check old password if ($this->getUser()->checkPassword($profile['passwordOld'])) { $this->getUser()->setPassword($profile['passwordNew']); } else { $this->getUser()->setFlash('notice_type', 'error', false); $this->getUser()->setFlash('notice', sfVoForm::getMissingPasswordMessage(), false); return; } } $this->getUser()->setFlash('notice_type', 'notice', false); $this->getUser()->setFlash('notice', sfVoForm::getFormSavesMessage(), false); $this->profileEditForm->save(); $profile = $this->profileEditForm->getObject()->getProfile(); $profile->save(); $aText = utf8_decode($this->profileEditForm->getValue('presentacion')); $aText = strip_tags(substr($aText, 0, 280)); $aText = utf8_encode($aText); $profile->setPresentacion($aText); $profile->save(); if ($profile->isColumnModified(SfGuardUserProfileI18nPeer::PRESENTACION)) { $this->hasDeepUpdates = true; } $this->presentacionValue = $aText; } else { $this->getUser()->setFlash('notice_type', 'error', false); $this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false); } } if (!$this->presentacionValue) { $this->presentacionValue = $politicos = $this->getUser()->getGuardUser()->getProfile()->getPresentacion(); } }