Dean Posted May 30, 2020 Share Posted May 30, 2020 After setting up a new user template using this guide: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users, the pages are created fine but I can't log in as the newly created user. I did notice that my new template doesn't have a 'name' field like the users in admin/access/users. Is this the field that is checked when logging in? Here is my code that I am using to create the page when someone registers: $np = new Page(); // create new page object $np->template = $templates->get("user-hunt"); $np->parent = $pages->get("/members/"); // Match up the sanitized inputs we just got with the template fields $np->of(false); $np->name = $hunt_name; $np->title = $hunt_name; $np->member_hunt_name = $hunt_name; $np->member_hunt_contact_name = $contactname; $np->member_hunt_position = $position; $np->member_hunt_address = $address; $np->member_hunt_postcode = $postcode; $np->member_hunt_telephone = $telephone; $np->member_hunt_country = $country; $np->email = $email_address; $np->pass = $password; // Save the page $np->save(); $np->of(true); Also, when it creates the page, it's putting the title as the created date/time for some reason. ? Link to comment Share on other sites More sharing options...
Dean Posted May 31, 2020 Author Share Posted May 31, 2020 I've realised the issue is that when the user page is created, if I filled out the form as dave@gmail.com, the page is create as dave-gmail.com. And so I need to log in as dave-gmail.com, not dave@gmail.com. So I'm guessing I need to set the user page title as the person's name when I'm creating it? Let me know what you think @Jan Romero ? Link to comment Share on other sites More sharing options...
rick Posted May 31, 2020 Share Posted May 31, 2020 (edited) Nevermind Edited May 31, 2020 by rick Link to comment Share on other sites More sharing options...
Jan Romero Posted May 31, 2020 Share Posted May 31, 2020 Are you not using the LoginRegister module anymore? I believe it has a feature that allows users to login with their email address. If you’re using the module, but you’re just doing your own registration, you might need to give the new user one or more roles for them to work with LoginRegister. In the module readme it says users are created with the “login-register” role. It’s curious that the page title is not what you explicitly set in the code you’ve shown. No idea why that happens. Since you’re creating a user, you should probably use $np = new User() instead of $np = new Page(), but I’m not sure if it makes any difference at that point. Link to comment Share on other sites More sharing options...
Dean Posted May 31, 2020 Author Share Posted May 31, 2020 Thanks @Jan Romero, I decided to abandon the LoginRegsiter module as I needed to send emails when people logged in and other stuff and I thought it would be easier to start from scratch rather than try to amend something I hadn't written. After reading lots of other forum posts, my code has changed to this now: if($input->post->hunt_name) { // sanitize input field values $user = $sanitizer->userName($input->post->hunt_name); $email = $sanitizer->email($input->post->email_address); $password = $input->post->password; // create user $registerUser = createUser($user, $email, $password); $registerUser->of(false); $registerUser->member_hunt_name = $hunt_name; $registerUser->member_hunt_contact_name = $contactname; $registerUser->member_hunt_position = $position; $registerUser->member_hunt_address = $address; $registerUser->member_hunt_postcode = $postcode; $registerUser->member_hunt_telephone = $telephone; $registerUser->member_hunt_country = $country; // save $registerUser->save(); $registerUser->of(true); } function createUser($user, $email, $password) { // create user $u = new User(); // set template and parent $u->template = $templates->get("user-hunt"); $u->parent = $pages->get("/members/hunts/"); // set name $u->name = $user; // set email $u->email = $email; //set password $u->pass = $password; // assign role $u->addRole("hunt"); // save new member $u->save(); return $u; } This is creating a page in /members as 0.78273300-1590946171. ? Link to comment Share on other sites More sharing options...
Dean Posted May 31, 2020 Author Share Posted May 31, 2020 I've noticed that if I go into PW admin and manually update the name field to something sensible, I can then log in with that name. So the setting of the name after clicking 'Send checked to pages' in the form entries page is my issue now I think. Link to comment Share on other sites More sharing options...
Jan Romero Posted May 31, 2020 Share Posted May 31, 2020 Mh, I dunno, looks fine to me, although you could eliminate one of the two save() calls and it’s unclear where the variables after the call to createUser() come from. I’m going to guess the problem is somewhere else. Have you confirmed that the POST data arrives and makes it through sanitation as expected? Are you using any other modules that may be involved in this process? Do the misbehaving fields have any validation or default value settings? Is “0.78273300-1590946171” the user’s title or its name or both? I see you’re not setting the title in your latest snippet, but if it’s just the title that shouldn’t interfere with the login. Link to comment Share on other sites More sharing options...
Dean Posted May 31, 2020 Author Share Posted May 31, 2020 44 minutes ago, Jan Romero said: it’s unclear where the variables after the call to createUser() come from Sorry, I just left that part of the code out. They are being grabbed from the form and run through the sanitizer. I'm using only the form builder module (with stripe payment). All the data for the user is populated correctly. The page title is set correctly as the name that is entered on the form. The URL and the settings > name are the only things that are wrong. See these images: Link to comment Share on other sites More sharing options...
Jan Romero Posted June 2, 2020 Share Posted June 2, 2020 Might be something to do with FormBuilder then. Is that how FormBuilder generates temporary page names or something? Unfortunately I don’t have FormBuilder, but if your license is still fresh you might want to run this by the FormBuilder support forum. The way your code looks, I suppose you don’t want FormBuilder to handle submitted requests at all, since you’re rolling everything yourself. So perhaps you want to use its “Submit to another URL” option. 1 Link to comment Share on other sites More sharing options...
Dean Posted June 2, 2020 Author Share Posted June 2, 2020 Actually, it was my fault. I hadn't matched the title to the relevant form field in My Form > Actions > Save to ProcessWire Pages > Page Fields to Form Fields. While we're discussing this, is there a way to trigger an email when sending the form entry to a page. I'd like to be able to tell the user their log in name and password and tell them they can log in now. Link to comment Share on other sites More sharing options...
Jan Romero Posted June 2, 2020 Share Posted June 2, 2020 Sure, you can just put this in there: $m = new WireMail(); $m->to($email); $m->from('noreply@yoursite.cz'); $m->subject("Welcome to my cool website, {$user}!"); $m->body("Holá {$user}, welcome to the site."); $m->send(); Depending on the volume of sign ups you expect, you may want to do something more robust, though. 1 Link to comment Share on other sites More sharing options...
Dean Posted June 3, 2020 Author Share Posted June 3, 2020 This is magical @Jan Romero. When you say 'put this in there', where is 'there'? ? Link to comment Share on other sites More sharing options...
Jan Romero Posted June 3, 2020 Share Posted June 3, 2020 @Dean After the creation of the user. So for example after $registerUser->save(); $registerUser->of(true); Link to comment Share on other sites More sharing options...
Dean Posted June 3, 2020 Author Share Posted June 3, 2020 Thanks @Jan Romero, but this isn't in my code, it's part of the Form Builder. Can I hook into the 'Send checked to pages' function somehow maybe? Link to comment Share on other sites More sharing options...
Jan Romero Posted June 3, 2020 Share Posted June 3, 2020 Guess you’ll want to hook FormBuilderProcessor::savePageDone if FormBuilder hasn’t changed since the beta versions. #24 is the latest one I could dig up, personally. That’s from 2014. But like I said, these are questions for the FormBuilder forum. 1 Link to comment Share on other sites More sharing options...
Dean Posted June 4, 2020 Author Share Posted June 4, 2020 Thank you @Jan Romero. I have since started posted in the Formbuilder forum. This is an old post. ? I shall have a read of https://processwire.com/store/form-builder/hooks/. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now