Jump to content

eangulo

Members
  • Content Count

    13
  • Joined

  • Last visited

Community Reputation

15 Good

About eangulo

  • Rank
    Jr. Member

Profile Information

  • Gender
    Male
  • Location
    Montreal

Recent Profile Visitors

583 profile views
  1. Yes, of course, my bad Thank you @Robin S !
  2. Thank you @adrian my code is more beautiful now !
  3. Hello, I passed through a lot of documentation about selectors and a few post in the forum but and I did not find my answer so I'll try here :). Question: Is there a way to find pages that have a certain field attached to his template ? Use case: // Site structure Products Computers Computer #1 (has field cached_details) Computer #2 (has field cached_details) Electronics Test #1 Pet Supplies Test #2 (has field cached_details but is empty) // If I want to get all children of page "products" that contains the field "cached_details" I would do something like this // $products => PageArray $results = $products->children("has_field=cached_details"); // or this $results = $products->children("cached_details!=null"); // Expected: $results would contains [Computer #1, Computer #2, Test #2] // Instead I have to do this $results = new PageArray(); foreach($products->children as $child) { if ($child->hasField("cached_details") === true) { $results->add($child); } } Thank you in advance guys :),
  4. Thank you @adrian for this module and I fully agree with you that this is a much better way to do it, but I was looking for an explanation for this behaviour to explain it to my team. Thank you guys,
  5. Hi @dragan, Yes that's a very good advice, I always do this kind of manipulation in a local environnement. Maybe I'm comparing to much Processwire with others CMS/CMF. Maybe the "caches" table that contains the system registry entries should never be cleared manually. (caches table system registry) Modules.info Modules.site/modules/ (This is the one causing the Fatal PHP error, after "caches" table is manually cleared and the system is not generating it automatically) Modules.wire/modules/ ... and so on If @ryan design it that way, I understand :). But I think it would be nice, if the rebuild caches table's content script can generate the content for this one too "Modules.site/modules/". Thank you,
  6. Hello everyone, Usually in many CMS database tables prefixed or suffixed with "cache" can be manually cleared without a problem because the system will populate them on the "next page request". Actually in Processwire I am expecting this behaviour: [On PW 3.x] Manually clear table "caches" in database Go to "client" side (not in the admin panel) All references to my "/site/modules" in my template files does not work : wire("modules")->get(""), $modules->get("") and modules()->get("") PHP error: Fatal error: Uncaught TypeError: Return value... My _init.php file are not able to find the references to my /site/modules/ The client side not working because this PHP fatal error. If I go to the admin panel "Admin -> Modules" and I trigger the action "Check for New Modules" in the top-right corner in the page, it populates the caches table with the required information and them the client side works. It is normal? Or I am doing something wrong ? A solution could be to manually call the script that the button "Check for New Modules" calls, but I want to know if I am doing something wrong here. Thank you in advance guys !
  7. Hello, Usually in many CMS database tables prefixed or suffixed with "cache" can be cleared without a problem because the system will populate them on the "next page request". Actually in Processwire I am expecting this behaviour: [PW 3.x] Manually clear table "caches" in database Go to "client" side (not in the admin panel) All references to my "/site/modules" in my template files does not work : wire("modules")->get(""), $modules->get("") and modules()->get("") PHP error: Fatal error: Uncaught TypeError: Return value... The client side not working because this PHP fatal error. If I go to the admin panel "Admin -> Modules" and I submit the button "Check for New Modules" in the top-right corner in the page, it populates the caches table with the required information and them the client side works. It is normal? Or I am doing something wrong ? I was thinking to manually call the script that the button "Check for New Modules" calls, but I want to know if I am doing something wrong here. Thank you guys !
  8. Hi guys, I want to share what I found working on my custom front-end email login: Even if no user were found for the submit email, Processwire should check for login because the login throttle api will be triggered and it will prevent multiple login tries. If the $session->login() is only called when the email owner is found, then the login throttle api will not be triggered and that tells requesters that a user with the email they try to login exists or not in your DB. /** * Login a user with the given name and password * * @param string $email * @param string $password * * @return bool|string * */ public static function signIn(string $email, string $password) { $signedIn = false; if(!empty($email) && !empty($password)) { // taken from ProcessLogin->execute(); if($email = wire("sanitizer")->email($email)) { $emailUser = wire("users")->get("email=$email"); $name = ""; if($emailUser->id) { $name = $emailUser->get("name"); } $password = substr($password, 0, 128); try { /** * even if the user is not found, try a login with a empty username * because the Processwire Login throttle API will be triggered and * prevent multiple login tries on the same email */ $result = wire("session")->login($name, $password); if($result instanceof User) { $signedIn = true; } } catch(\Exception $exception) { return $exception->getMessage(); } } } return $signedIn; } Look at pw_login_throttle_api_nessage.png for the message it will return if many tries are made. Thanks hope this help.
  9. Processwire never stop to impress me! I love it ! Thank you @Robin S for your explications and your time!
  10. Hi Robin thanks for your answer, Actually my module is on autoload mode (below my module GeneralTools.info.php): <?php /** * GeneralTools.info.php * * Return information about this module. * */ $info = array( // Your module's title 'title' => "General Tools", // A 1 sentence description of what your module does 'summary' => "General helper functions.", // Module version number: use 1 for 0.0.1 or 100 for 1.0.0, and so on 'version' => 100, // Icon to accompany this module (optional), uses font-awesome icon names, minus the "fa-" part 'icon' => 'cogs', // URL to more info: change to your full modules.processwire.com URL (if available), or something else if you prefer 'href' => '', 'autoload' => true, 'singular' => false, 'requires' => "ProcessWire>=3.0", ); The after hook "InputfieldEmail::processInput" is triggered well because when I submit the User add/edit form I can see the error message "Email already in use" set by the hook, that part work fine, the problem is that even if the form contains errors (this one ---> $field->error("Email already in use") it update the values. I expect that when I set the field error the form will display the error and the it will not update User values because an error is displayed and the it must be resolved. Have you a idea why the form is not waiting until the error "$field->error("Email already in use")" is resolve before updating User values? Thank you so much :).
  11. Hello, I'm trying to make users email unique and for this I try the following code: Can someone tell me why the form still saving values even if the form display the email error "Email already in use" ? I need to block form submission until the user enter a valid email. <?php namespace ProcessWire; /** * * ProcessWire 3.x * */ class GeneralTools extends WireData implements Module { public function init() { // Ensure Uniqueness of Emails across site $this->pages->addHookAfter("InputfieldEmail::processInput", $this, "validEmail"); } /** * Ensure Uniqueness of Emails across site * * @param \ProcessWire\HookEvent $event * */ public function validEmail(HookEvent $event) { $field = $event->object; if($field->name == 'email') { // for test: always display field error $field->error("Email already in use"); } } } Thanks Guys :D!
  12. eangulo

    Custom Login

    Hello! If this can help someone, this is how I build my login form: // Sign In controller <?php namespace ProcessWire; /** * Class SignIn * * @package ProcessWire */ class SignIn { /** * Render * * @return string * */ public function render(): string { $input = wire("input"); $template = $this->getSignInTemplate(); if($input->post("login_submit")) { // taken from ProcessLogin->execute(); $name = wire('sanitizer')->pageName($input->post("login_name")); $pass = substr($input->post("login_pass"), 0, 128); if(wire('session')->login($name, $pass)) { // Successful login wire("session")->redirect(""); } else { // Login failed $template->set("error", "login failed!"); $template->set("sign_in_form", $this->signInForm()); } } else { // set template variables $template->set("sign_in_form", $this->signInForm()); } return $template->render(); } /** * @return string */ protected function signInForm() { $input = wire("input"); $modules = wire("modules"); // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name", 'sign-in-form'); $f = $modules->get('InputfieldText'); $f->set('label', "Username"); // Login form: username field label $f->attr('id+name', 'login_name'); $f->attr('class', 'Name'); $f->attr('value', $input->post("login_name")); $f->collapsed = Inputfield::collapsedNever; $form->add($f); $f = $modules->get('InputfieldText'); $f->set('label', "Password"); // Login form: password field label $f->attr('id+name', 'login_pass'); $f->attr('type', 'password'); $f->attr('class', 'Pass'); $f->collapsed = Inputfield::collapsedNever; $form->add($f); $f = $modules->get('InputfieldSubmit'); $f->attr('name', 'login_submit'); $f->attr('value', "Sign in"); // Login form: submit login button $form->add($f); return $form->render(); } /** * Get Sign In template * * @return \TemplateEngine * */ protected function getSignInTemplate(): \TemplateEngine { return wire("factory")->load("/components/sign-in"); } } Thanks :).
  13. (sorry for my English) I believe that PW can handle a product project with a very large number of items. As @horst said I think that the most important part is to try to reduce the number of product fields (less tables to deal with). If this can help, I read and did a few tests with Elastic Search and the PW module elastic-search. This is what I learn: Elastic Search should only be used as a search engine solution and not as a project database. Do not use Elastic Search if the product information is changed regularly to avoid the headache data management between PW, Elastic Search and some third-party system. Elastic Search gives a lot of tools to improve the reverence of search results. I never had the chance to try the FieldtypeCache module but I think is not that simple to control which items should be founded on a search. A Queue system and the elastic-search module hooks (create, update and delete) can help a lot with the synchronization of data coming from an external DB. This is a really interesting topic thanks for sharing your experiences.
×
×
  • Create New...