-
Posts
24 -
Joined
-
Last visited
Contact Methods
-
Website URL
http://bluebx.com
Profile Information
-
Gender
Not Telling
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Jim Yost's Achievements
Jr. Member (3/6)
3
Reputation
-
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
-
<?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; } }
-
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
-
Perfect, thanks.
-
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
-
Make session_start() in Session overridable from a module
Jim Yost replied to Jim Yost's topic in Wishlist & Roadmap
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 -
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
-
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
-
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
-
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
-
I have the same issue. See my Youtube Video: WinXP, Firefox 3.6.13
-
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
-
I agree, it is a little frustrating when you are adding more than one field in a row.
-
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
-
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