Jump to content

gebeer

Members
  • Posts

    1,391
  • Joined

  • Last visited

  • Days Won

    39

Everything posted by gebeer

  1. Thanks! I did try to edit the first post, but not in full editor mode. Now I know
  2. I can't mark the topic as solved. Maybe because it has been moved?
  3. @kongondo Thanks for moving it. Unfortunately I was just about to post at the same time and things got messed up so I'm overwriting this post. Finally my hook module is working. Big thanks to Soma again! Here's the final code: <?php class CleanupUserPages extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Cleanup User Data', 'version' => 0.1, 'summary' => 'Trashes all pages that where created by a user after user has been deleted', 'singular' => true, 'permanent' => false, 'permission' => 'user-admin', 'autoload' => true, ); } public function init() { $this->pages->addHookBefore("delete", $this, "hookDeleteUsers"); } public function hookDeleteUsers($event){ $page = $event->arguments("page"); if ($page->id && $page->template->name === "user") { $userPages = wire("pages")->find("created_users_id={$page->id}"); foreach ($userPages as $userPage) { wire("pages")->trash($userPage); } $this->message("All pages of user {$page->name} deleted"); } } } ?> I first had problems accessing the page template. The $page object returned by $event->arguments("page") works different from the standard $page object in templates. It took me a while to find that I have to use $page->template->name === "user". exit(var_dump($page)) was helpful.
  4. For your password change functionality you could use something like this <?php $out = ''; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'password-form'); // create password inputs from the built in PW password field $field = $modules->get("InputfieldPassword"); $field->label = "My new Password"; $field->attr("id+name","pass"); $form->append($field); // submit button! $submit = $modules->get("InputfieldSubmit"); $submit->label = " "; $submit->attr("value","Save Changes"); $submit->attr("id+name","submit"); $form->append($submit); // form was submitted so we process the form if($input->post->submit) { // user submitted the form, process it and check for errors $form->processInput($input->post); if ($form->id == "password-form") { //only process input from password form in case you have more forms in your dashboard //here you could do some validation logic but I don't think it is necessary if you only have password fields //to do validation and print out errors for the password field you would do something like $pass = $form->get("pass"); $_pass = $form->get("_pass"); if ($pass != $_pass) { $pass->error("passwords do not match"); } if($form->getErrors()) { // the form is processed and populated // but contains errors $out .= $form->render(); } else { //save new password $pass = $form->get("pass")->value; if ($pass != '') { $user->of(false); $user->pass = $pass; $user->save(); $user->of(true); } $out .= "Your changes have been saved."; $out .= $form->render(); } } } else { // render out form without processing $out .= $form->render(); } echo $out; ?> Note: don't sanitize passwords as that might change them and then user can't login.
  5. OK, my hookDeleteUsers function now reads public function hookDeleteUsers($event){ exit("hallo"); $userpage = $event->arguments("page"); if($userpage->id){ $userPages = wire("pages")->find("created_users_id={$userpage->id}"); foreach ($userPages as $userPage) { wire("pages")->trash($userPage); } $this->message("All pages of user {$userpage->name} deleted"); } } But I don't get a "hallo" on delete and all user's pages are still there. So I guess the hook doesn't get called.
  6. Based on Somas input, my CleanupUserPages.module now contains: <?php class CleanupUserPages extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Cleanup User Data', 'version' => 0.1, 'summary' => 'Trashes all pages that where created by a user after user has been deleted', 'singular' => true, 'permanent' => false, 'permission' => 'user-admin', 'autoload' => true, ); } public function init() { $this->users->addHookBefore("delete", $this, "hookDeleteUsers"); } public function hookDeleteUsers($event){ $userpage = $event->arguments("page"); if($userpage->id){ $userPages = $pages->get("created_users_id={$userpage->id}"); $this->pages->trash($userPages); $this->message("pages deleted"); } } } ?> I have installed the module. But when I delete a user, nothing happens. To test if the module gets called, I added var_dump($userpages); return; right after $userpage = $event->arguments("page"); But still nothing happens. It seems like the module code is not being executed at all. Does $this->users->addHookBefore make sense or do I need to define the hook in some other way?
  7. Thank you kongondo, this is working great!
  8. Hi, I'm trying to setup a page field with a custom selector. Intention is to show only pages of the currently logged in user in the select drop down. Here's what I tried in the field setup: I also tried But I guess this doesn't make a lot of sense because when the page is created and has not been saved yet, the $page->createdUser isn't there yet. I always get an empty select It seems like the page field is not aware of the $user object. Is there any way how I could filter the pages by created_users_id, maybe through a hook on that field?
  9. Thanks again Soma, for your help. Your explanations again are really clear to understand. Based on what I know now, I will try and put the module together. @admins: I should have posted this in the modules forum. You're welcome to move it over there.
  10. Thanks Martijn. I just followed a link to Captain Hook on https://processwire.com/api/hooks/. When I browse http://processwire.com/api/hooks/captain-hook/ the site is working. Whom can I notify and inform about this issue? Github issues?
  11. Hello, I'm trying to learn more about hooks and visited Captain Hook. That page is currently not loading any styles and scripts. My console says: Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/css/anchor.css" Loading mixed (insecure) display content on a secure page "http://somatonic.github.com/Captain-Hook/hook.png" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/jquery.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/quicksilver.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/main.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/jquery.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/quicksilver.js" Blocked loading mixed active content "http://somatonic.github.com/Captain-Hook/js/main.js"
  12. Now I'm aware of lightning.pw, too. Awesome!
  13. I t does have a title field in the template. Just renamed The Label there to "Login Name".
  14. OK, bummer. Blame on me not checking the source and stealing your time. Can I buy you a beer/soda/coffee? I'm using same menu code in a different project where no problems with menu rendering appeared so far. Actually I took the code from here. Found it: I had commented out a part in the rendering function that prevented displaying pages with children. Slapping myself hard now. Credits for solving this go to Soma.
  15. The profile page itself shows fine. But there should also be a menu item "Profiles" visible in the top menu bar next to "Home". when logged in as frontend user. That is my problem. I thought, too, that it wouldn't matter to have 2 different templates or only one. That was just the only difference that I noticed when comparing your settings to mine.
  16. my custom login definitely logs user in. You can see it on my def site which I pmed you details to.
  17. Thanks a ton! Only difference to my setup is that your login is through the default pw login page while mine is through the frontend.
  18. These are the access settings now for my Profiles page with template userprofiles The Profiles page still doesn't show in the menu, although it says in the settings: No - Pages may NOT not appear in searches/lists unless the user has access to view them My logged in user has role guest and frontend. Role frontend has these permissions: Sorry, I still can't see why the menu item would not be visible.
  19. I'll try harder first and get back here if I don't succeed. Thank you again for your help.
  20. That approach totally makes sense to me and fits my project requirements very well, especially since I also want to keep frontend users out from the admin area. My Profile page has guest view permissions removed. Only frontend user role is allowed to view it. But still it does NOT show up when frontend user is logged in. And I don't know why. You can see my role and template setup in my first post. So I guess something must still be wrong with my role/template access setup. Still lost on this one.
  21. Thank you Soma, for taking your time and explaining things that precisely. This really helped me to get a better understanding of the whole role and permissions concept. I will alter my frontend role like you suggested and add checks for $user->isLoggedin() && $user->hasRole("frontend") in my templates. If I get you correctly on the navigation render: It is expected behaviour that the Profile page does NOT show, right? So I need to render an extra users menu with links to their profile page and whatever else they need? Pls confirm. Thank you.
  22. Hi all, I'm struggling in putting together a process module. I want to trash all pages that belong to a specific user after the user has been deleted. I found one related thread by onjegolders where he is doing things the other way around. In my case I need a process module that hooks after user delete. And I would like to use the wire/modules/Process/ProcessPageTrash.module. It is my first time creating a pw process module. I have read through the basics of creating modules including the wiki article and looked at the code of ProcessPageTrash.module. But I'm having a hard time putting things together. This is what I've got so far: class ProcessCleanupUserPages extends Process { public static function getModuleInfo() { return array( 'title' => 'Cleanup User Data', 'version' => 0.1, 'summary' => 'Deletes all pages that where created by a user after user has been deleted', 'singular' => true, 'permanent' => false, 'permission' => 'user-admin', 'requires' => 'ProcessPageTrash', 'autoload' => "process=ProcessPageList", // What to add here - autoload only on user list page ); } public function init() { $this->users->addHookAfter('delete', $this, '___execute()'); // is this correct? } public function ___execute() { //get user ID $userID = $this->id or $event->id // How to get the user ID? //get all pages that were created by the deleted user $userPages = $pages->get("created_users_id={$userID}"); // syntax for trash pages - call module ProcessPageTrash on $userPages } protected function render() { // print out message to admin after pages are successfully trashed } } ?> I added comments with "???" where I don't know exactly what to do. Any help would be much appreciated. Thank you.
  23. The problem happened to be related to old session files that I transferred when moving to the new server. Once I deleted all session files in assets/sessions on the new server, PW picks up the $config->httpHosts array and the error message in the backend disappears.
×
×
  • Create New...