Jump to content

FrontendUser: login, logout and register users / members


pwFoo

Recommended Posts

Quote

The FrontendUser module is just based on form api, inputfields, hooks. PW native features. So if you know PW you know how to extend the module.

For someone just coming in from the Wordpress world it is tempting to look for a module/plugin that does everything out-of-the-box to avoid having to learn about the form API, hooks, PW native features, etc.

If I have to know all that before I get anything usable, I might as well skip your FrontendUser module + two required helper modules that may or may not be compatible with the latest PW version and just use those PW native features to put my own solution together.

  • Like 2
Link to comment
Share on other sites

I too had used wordpress a long long time ago, and even wrote a few plugins for the 2.x versions since there was nothing out of the box available for my needs. I dumped it because that square peg was being force-fit into the round "one size fits all" hole with each passing version at the cost of security. And more and more plugins were coming on board that didn't work, had no support, wanted payments, and embedded hidden ads without your knowledge.

I'm glad I came across ProcessWire because I can solve my needs any way I see fit; that proverbial skinned cat. As an example, I wrote my own front-end user management system simply because ProcessWire makes it easy to do so, and it does exactly what I want, and ProcessWire doesn't impose restrictions.

You don't have to write your own, however, as there are quite a few user management modules/code snippets available to you in this forum, but you are certainly welcome to do so. This community would welcome your contribution, and gladly assist you with its development.

One other option is to hire someone to develop your module(s) to your specifications (See the Jobs forum).

  • Like 1
Link to comment
Share on other sites

On 3/10/2017 at 2:55 PM, fbg13 said:

@modifiedcontent Works the same as everywhere else, you have a form, form gets submitted, you process it (do what you need with the values submitted).

I showed you how to save the values in a page, the same way you can create a user.


<?php
// $input->post->username same as $_POST["username"]
if($input->post->submit) {
    $u = new User();
    $u->name = $input->post->username;
    $u->email = $input->post->email;
    $u->pass = $input->post->password;
    $u->registrationDate = time();
    $u->addRole("member");
    $u->save();
}

 

I am about to ask a big, stupid question... having gone through 50 pages of user, login, registration stuff.  I can easily create a form - or use formbuilder - to create a simple registration form for a couple levels of users (roles = subscribers, contributors) and I can easily send those entries to a page structure like

 Pages  

 --- Users

------Subscribers

       -- Bill Smith, etc. 

------Contributors

       -- John Jones, etc.

This creates a directory of pages, assigned roles, and page access based on role, but this doesn't put those people into: ACCESS > USERS > 

My user data lives in Admin > Access > Users -- not in the document tree.  If I want to have user accounts, doesn't Bill Smith, in the example above, have to be in both locations? Or, at least Admin > Access > Users?  This is a conceptual problem, not a code problem... as a new user of PW,  I don't know where my logged in users are supposed to live -- and if I use a form, how to get them there.

 

Link to comment
Share on other sites

Your users actually live in page tree: Admin => Access => Users => User

So you can just create your users like that. Instead of $p = new Page(), just use $u = new User(); and you are good to go. No need to define template and parent in that case also, if I remember correctly.

PW also has possibilities to use different templates than user for users. That is usable if you really need different fields for different kind of users or you need them to live on other place at pagetree. More information about that from here: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users

  • Like 2
Link to comment
Share on other sites

9 hours ago, apeisa said:

Your users actually live in page tree: Admin => Access => Users => User

So you can just create your users like that. Instead of $p = new Page(), just use $u = new User(); and you are good to go. No need to define template and parent in that case also, if I remember correctly.

PW also has possibilities to use different templates than user for users. That is usable if you really need different fields for different kind of users or you need them to live on other place at pagetree. More information about that from here: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users

I read through the multiple parents post. All my users basically enter the same 6 fields. They get assigned one of two roles depending upon whether they are just subscribing to content, or contributing content.  I tried creating a user registration form... got it to create (albeit missing data, no follow up page, and ugly) to access > users ...  but I'd need it to also notify the admin that a new user is waiting. 

Link to comment
Share on other sites

@hollyvalero FrontendUser should be stable with older PW modules. I think some users here use it with prod websites too. It should work with PW 3, but there seems to be a problem with a password inputfield change ("Not yet validInvalidToo shortToo commonWeakOkGoodExcellent"). Additional css / js is needed to fix it.

 After seaching the blog I think this update causes the issue with the
https://processwire.com/blog/posts/upgrades-optimizations-pw-3.0.22/#major-enhancements-to-our-password-field

If I'm right the module should work fine / stable with PW <3.0.22 / <2.8.22. Newer version needs a workaround like @jmartsch mentioned earlier.

 

Link to comment
Share on other sites

13 minutes ago, pwFoo said:

@hollyvalero FrontendUser should be stable with older PW modules. I think some users here use it with prod websites too. It should work with PW 3, but there seems to be a problem with a password inputfield change ("Not yet validInvalidToo shortToo commonWeakOkGoodExcellent"). Additional css / js is needed to fix it.

 After seaching the blog I think this update causes the issue with the
https://processwire.com/blog/posts/upgrades-optimizations-pw-3.0.22/#major-enhancements-to-our-password-field

If I'm right the module should work fine / stable with PW <3.0.22 / <2.8.22. Newer version needs a workaround like @jmartsch mentioned earlier.

 

I'm running the latest version of PW, but if the only problem is the PW nag?  I think I'll export the site profile, load it to a second spot and try front end user... with the added js/css for the field validation and see if it works.  If it does, then we're all set.  I also looked at the subscribers module ... that too seemed to be in alpha :-D ...  I'll try Front End User first.

Link to comment
Share on other sites

28 minutes ago, adrian said:

You could hook into Pages::added, check to make sure the page has the user template and then create your own logic to notify the admin - eg send an email.

uh, yeah.. that. Maybe someday. I am still in the beansprout/newbie phase.

Link to comment
Share on other sites

  • 3 weeks later...

Hi, I have a problem and I am seeking for advice.

I have users complaining of the way the login system works, the funny thing is that I am not able to duplicate the error. All I know is from the logs "Error: Call to a member function render() on null (line 137 of /home/consultazienda/public_html/site/assets/cache/FileCompiler/site/modules/FrontendUser/FrontendUser/FrontendUser.module)"

What happens is the user logs-in, gets a 404 page, some of them panic..., then goes back and the user has logged-in.

this is the code I see at :137

136	public function ___render() {
137		return $this->form->render();
138	}

I've many times to log-in with all the user-roles and never see this happening. Any idea where I could check? I know this a poor information post, but I dont know where to bang my head. Thanks

PW 3.0.50 - FU 0.9.3

Link to comment
Share on other sites

  • 1 month later...

Hi!
Does anyboy know, how i translate the "register" - Button?
This doesn´t solve the problem:

    $buttonFieldreg = $fuRegister->form->get("fhSubmit3");
    $buttonFieldreg->label = "registrieren";

I also tried ->name and ->value - same result

Beyond this i would like to know, if there is a possibility to change the language of this parts ( siehe screenshot ).

Many thanks!!

 

Bildschirmfoto 2017-05-14 um 20.26.20.png

Link to comment
Share on other sites

  • 4 weeks later...

This module was working fine until a month ago, then suddenly it stopped working in the desired manner. The login happens from pages other than the home page. But when someone tries to  login from the homepage, it just does not happen. I have been careful about the $redirectDestination and below is the code I am using, any suggestions will be extremely helpful.

 

    <? if($user->isGuest()) {
                 $fu = $modules->get("FrontendUser");
                 $fu->login(array('username', 'password', 'persist'));
                 if($page->path != "/"){
                    $redirectDestination = "/";
                }
                else {
                    $redirectDestination = "/blog/";
                }
            ?>
        <div class="new_login" id="new_login"><?  $fu->process($redirectDestination); echo $fu->render(); ?></div>
            <?    }
            else{ ?>
                <h4 style="padding-left:3em;text-transform:uppercase; -webkit-margin-after:0em; ">Welcome <?echo $user->name; ?></h4>
                <h5 style="padding-left:3.4em; -webkit-margin-before:0em;"><a href='/thank-you/' style="text-decoration:none; text-transform:uppercase;color:#bdbec0;">Logout?</a></h5>
            </div> 
            <? }    ?>
            </div>

 

You can see the working site at http://umbra.lightcube.in

Edited by kongondo
code blocks
Link to comment
Share on other sites

  • 7 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...