Jump to content

Jim Yost

Members
  • Posts

    24
  • Joined

  • Last visited

Everything posted by Jim Yost

  1. Thanks WillyC, that is exactly what I was looking for! The module still needs work with ldap settings (specifically TLS and other connection types that LDAP works with). I just needed it to show my company how flexible ProcessWire is . Oliver, let me get a formal module together that supports more complete features of LDAP before you grab it (though you are welcome to do so). I started one for looking up users, groups, and pulling information as well and will end up tieing the two together. -J
  2. <?php class LdapAuth extends WireData implements Module, ConfigurableModule { public static function getModuleInfo() { return array( "title" => "LDAP Authentication", "version" => 100, "summary" => "Allows uses to be authenticated via LDAP", "permanent" => false, "singular" => true, "autoload" => true ); } public function init() { $this->session->addHookAfter('login', $this, 'login'); } public function ___login($event) { if ($event->return) return; // they are already in $name = $event->arguments[0]; $pass = $event->arguments[1]; $conn = ldap_connect($this->data['host']); if ($conn) { $bind = @ldap_bind($conn, "$name@{$this->data['accountDomainName']}", $pass); if ($bind) { // success // check if they area lready a user in PW $user = wire('users')->get("name=$name"); if (!$user instanceof NullPage) { // update login info $user->pass = $pass; $user->save(); $user = wire('session')->login($name, $pass); $event->return = $user; return; } else { // create a new user $guest = wire('users')->getGuestUser(); $user = new User(); $user->parent = $guest->parent; $user->name = $name; $user->pass = $pass; $user->addRole("guest"); $user->save(); $user = wire('session')->login($name, $pass); $event->return = $user; return; } } else { // fail $event->return = null; return; } } else { // could not connect throw new Exception("Could not connect to LDAP"); } } static public function getModuleConfigInputfields(array $data) { $inputfields = new InputfieldWrapper(); $field = Wire::getFuel('modules')->get('InputfieldText'); $field->attr('name', 'host'); $field->label = 'Host'; if (isset($data['host'])) $field->attr('value', $data['host']); $field->description = 'The LDAP server hostname'; $inputfields->append($field); $field = Wire::getFuel('modules')->get('InputfieldText'); $field->attr('name', 'accountDomainName'); $field->label = 'Account Domain Name'; if (isset($data['accountDomainName'])) $field->attr('value', $data['accountDomainName']); $field->description = 'The LDAP server domain'; $inputfields->append($field); $field = Wire::getFuel('modules')->get('InputfieldText'); $field->attr('name', 'accountDomainNameShort'); $field->label = 'LDAP server domain (short)'; if (isset($data['accountDomainNameShort'])) $field->attr('value', $data['accountDomainNameShort']); $field->description = 'The LDAP server hostname'; $inputfields->append($field); $field = Wire::getFuel('modules')->get('InputfieldText'); $field->attr('name', 'baseDn'); $field->label = 'Base DN'; if (isset($data['baseDn'])) $field->attr('value', $data['baseDn']); $field->description = 'The LDAP server DN'; $inputfields->append($field); $field = Wire::getFuel('modules')->get('InputfieldCheckbox'); $field->attr('name', 'startTls'); $field->label = 'Use TLS'; $field->attr('value', 1); if (isset($data['startTls'])) { if ($data['startTls']) $field->attr('checked', true); } $field->description = 'Check this option to enable TLS security'; $inputfields->append($field); return $inputfields; } }
  3. Howdy! Just created a module for authenticating via LDAP. It works great for our implementation of LDAP, however I'm sure it may need additional work. Looking for some feedback if there are better ways to implement this or clean up my code a bit. File attached. -Jim
  4. Hey Ryan, Is there a way we can use getArray() so that it pulls all data from a page object rather than what is currently loaded into the object? For instance, exporting results to a CSV. I don't want to auto-join every field in my template just to get getArray to have everything already. I currently work around this by doing a foreach($page as $value) {} and then I can pull all the data with getArray() (Since now all field data is loaded). I don't mind doing the foreach before getArray(), however it was just very confusing at first when I didn't get an array with all of my values, only what was currently loaded. -Jim
  5. Hey Ryan, That works well for me, I was just thinking it would be nice to package it all up into a single module and not worry about putting code elsewhere. I also realize this is an extremely rare situation so it's not a big deal for now. -Jim
  6. What I'd like to be able to do is override the session_start() call in the __construct() of Session so I can use another method. Umm, why the heck would I want to do that? I've been using Zend Framework for a while now and love how portable my classes are. I've been using it with ProcessWire a good bit and everything works well except for Sessions. Many of my classes are custom forms with validators, filters and custom decorators. I've been able to plug them into PW very easily. The issue is when some fields use session, Zend expects a Zend_Session::start(), Zend_Session is just a wrapper for the normal php $_SESSION. If Zend_Session::start() is called after session_start(), it throws an exception. Many Zend Frameowork classes use Zend_Session unfortunately. Currently I have just updated the Session.php class in PW and replaced @session_start(); with Zend_Session::start(); Ideally a hookable call to a new ___sessionStart() method would work well in my opinion. The __construct() method would call the ___sessionStart() or overridden in a module to hook that event and call Zend_Session::start() instead of session_start(). Since Zend_Session is a wrapper of $_SESSION just like PW's Session class, they get along perfectly except for that small startup issue. I've been able to log into processwire and use all features without issue. -Jim
  7. Thanks Ryan, I tried adding the $config->loginPageID = $pages->get("/it/login/")->id; to my controller and it didn't help. I was still re-directed to the /processwire/login/ I believe that PW redirects before it even gives control to the template or controller. I only want the /it/login/ to show for the /it/ branch of templates. This isn't a big deal for now, I currently have /it/ guest accessible and it will redirect to /it/login/ if the user isn't logged in or /it/dashboard/ if the user is logged in. -Jim
  8. Hey Ryan, Is it possible to update ProcessTemplate.module to allow us to specify a login url as a third option? Right now option 1 = show 404, option 2 = show the processwire/login page. Option 3: Select a page or type in url? -Jim
  9. Ryan, Still no luck. I also have a hard time moving a child to a higher branch level. This has always been there, I just haven't mentioned it before. Another video. Firefox 3.6.13 (WinXP) -Jim
  10. I have the same issue. See my Youtube Video: WinXP, Firefox 3.6.13
  11. Hi neotoxic, I'm not 100% sure on what you are trying to accomplish, but this may help. You have a template file with four sections in it. You also have four fields in that template. If you create four sub-pages of the same page template and loop through them, you can easily populate the four sections in the first template. I'll try to illustrate this a bit. Create a template named section. Give it the four fields (title, image, description, url). Create a Page called Main Section. and give set it to the section template. Add four sub-pages to the Main Section and give them the same template. In your template php file, try this code: <?php $count = 1; foreach($page->children() as $child) { echo "Section " . $count. "<br />"; echo $child->title . "<br />"; echo $child->url . "<br />"; } This may shed some light on the uses of ProcessWire. Sub-pages can easily be treated as a single page - you can just use those sub pages as basic information. I can explain further if you need. -Jim
  12. I agree, it is a little frustrating when you are adding more than one field in a row.
  13. Hi, I am trying to return 3 random images from an image field using getRandom(3). It appears to be returning all 6 results. I do have only 6 images uploaded to the field. <?php $images = $page->images->getRandom(3); foreach($images as $image) { $thumbnail = $image->size(118,112); echo "<a href='{$image->url}'><img class='photo' src='{$thumbnail->url}' alt='{$image->description}' /></a>"; } I initially thought it was a problem with WireArray, however the following works as expected. <?php $test_pages = $pages->get("/")->children->getRandom(3); foreach($test_pages as $test) { echo $test->name . "<br />"; } Any ideas? -Jim
  14. Ryan, When developing a module, is there any way for a requirements check before the module can be installed? Or perhaps a way to disable the install button if the module requires a certain version of php, or a certain module installed? For instance, maybe my module requires calls to the W32api which is only available when installed on a Windows machine. I don't want it installed when running on PHP (that would be misleading). -Jim
  15. Yeah, I realized that the Pagination Module works for search results and it displays an entire list of pages as well as the page #'s. He just want's to see the page #'s.
  16. Hey Sevarf2, I believe you could do something like this: Create a new Role (Access->roles) for "registered_users" and assign it to a user. In your template, I believe you can do something like: <?php if ($user->hasRole("registered_users")) { echo "custom price"; }
  17. Yay! You don't know how many time's I've clicked on that by accident...
  18. Ryan, The above would not work for what he wants?
  19. Hi Martin, Welcome to the forums! To answer your question, you may want to take a look here to get a general idea of the Pagination module: http://processwire.com/api/modules/markup-pager-nav/ That should be a good place to start. You will also want to think about using a different selector to get the sibling pages instead of a general list of pages. Maybe you want to sort them by page name, etc. <?php $results = $page->siblings("sort=name"); echo $results->render(); Instead of the code in the example: <?php $results = $pages->find("id>1, limit=10, sort=title"); echo $results->render(); I actually haven't used this myself yet, but hopefully this will give you a good place to start! Good Luck! -Jim
  20. Hey Ryan, I have updated my CSS to use what you have to start and it works well. I mainly use site templates built by external designers for my work, so many times it's easier to just render forms like the designer's examples and have them work and function great. This way I don't have to spend a ton of time updating their css, js, etc. What I would like to do is be able to override the wrapper class within a template rather than creating a new module to override the wrapper. Maybe something like: (from your module...I have just changed it a bit so it's not a contact form anymore) <?php // get the collection of inputs that can populate this page's fields $inputfields = $page->getInputfields(); // set values for fields and add them to the form. foreach($inputfields as $inputfield) { if ($inputfield->name == 'title') continue; // populate values if ($page->name != 'create') { $inputfield_name = $inputfield->name; $inputfield->value = $this->page->$inputfield_name; } // *****Maybe some markup here?***** $inputfield->markup("./markup/{$inputfield->type}"); if(in_array($inputfield->name, $required_fields)) $inputfield->required = true; $form->add($inputfield); } Just a thought -Jim
  21. Hey Ryan, Your module works great! How would I go about overriding the default markup created by each InputField? Obviously without messing up the admin template. Is this currently possible? -Jim
  22. Hi Ryan, How do you recommend I store data in ProcessWire? To keep it simple for example, I'd like to collect results from a Contact Form and store them in PW. If I had to do it, I would create a hidden "Contact Form Results" page. Whenever someone submits the contact form, I would generate a new child page to the "Contact Form Results" Page with the information I've collected. I would then create a template with the fields I need so they are browse-able from the admin interface. Does this seem like a good way to collect the data? It seems like once it's collected, it would be simple to use PW's API to create reports and do anything else I needed to with that data. -Jim
  23. Hey Ryan, I tested out what you posted and it works great. I did have to fix some typo's (<form tag, and {$user->name}). I will need to update a few things to get it to do what I want, but your demo explains all the parts I needed. Thanks!! It would have taken me a lot longer to do something like this in Drupal or manually. ProcessWire makes it much quicker! -Jim
×
×
  • Create New...