Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-06-29 14:40:22

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Connect user after create account on front end, possible ?

Hi

I have a request from a client on connecting user to front end upon account creation, and i dont know is this doable on textpattern.

The work should be like this : Create account on front end (using mem_self_register ) upon completion connect the user to his account to let him see protected area on front end. (i have cbe_front_auth installed for connecting and managing private area)

Can someone give me advices on how to do that ?

Thanks in advance.

Offline

#2 2021-06-29 15:47:29

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: Connect user after create account on front end, possible ?

So are you looking to effectively auto-log-in after account creation? That’s doable with a plugin and some mem_form hackery.

I have all that somewhere if that’s what you’re after. I could dig it out.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2021-06-29 15:53:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: Connect user after create account on front end, possible ?

Just for anyone’s interest, to auto-login requires a bit of JavaScript.

Textpattern expects two fields to be present to log you in: p_userid and p_password. So in your login/registration form (cbe_frontauth, mem_self_register, …) you just add some script to copy the user-supplied username and password into two hidden fields called p_userid and p_password. Txp then sees those fields and can log them in straight away.

I can’t remember if it’s as straightforward as that. You might have to initiate a call to doAuth() or cURL() to example.com/textpattern, passing those two parameters in the POST payload via the thanks_form. It’s been a while since I’ve done it.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2021-06-30 08:00:15

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: Connect user after create account on front end, possible ?

Hi Stef

Thanks for guidance, i will check and give you feedback.

Cheers.

Offline

#5 2021-06-30 14:33:55

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: Connect user after create account on front end, possible ?

Hi

First test code (grabbed from cbe_front_ath) and tested on local wampserver (the login only):

<form method="post">
              <input type="hidden" name="p_userid" value="test" />
              <input type="hidden" name="p_password" value="test" />
              <input type="submit" value="ok"/>
            </form>

            <txp:php>

              global $txp_user ;

              include_once( 'C:\wamp64\www\textpattern-4.7.3\textpattern\lib\txplib_admin.php' ) ;

              $p_userid = gps('p_userid');
              $p_password = gps('p_password');

              if ($p_userid !== '')
              {
                $log_name = txp_validate( $p_userid, $p_password );

                $hash  = md5(uniqid(mt_rand(), TRUE));
                $nonce = md5($p_userid.pack('H*',$hash));
                $pub_path = preg_replace('|//$|','/', rhu.'/') ;
                $p_stay='';

                echo "USER :".$p_userid." | "."Logname : ".$log_name;

                if ($log_name !== false)
                {
                  safe_update( 'txp_users'
                    , "nonce = '".doSlash($nonce)."'"
                    , "name = '".doSlash($p_userid)."'"
                    ) ;

                    setcookie( 'txp_login_public'
                    , substr(md5($nonce), -10).$p_userid
                    , ($p_stay ? time()+3600*24*30 : 0)
                    , $pub_path
                    ) ;
                }
              }
            </txp:php>

Cheers.

Offline

#6 2021-06-30 15:17:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: Connect user after create account on front end, possible ?

Interesting. To save work, you may like to include_once txpath.'include/txp_auth.php'; and simply call doTxpValidate(). That should see the incoming POST vars and handle all the cookie setting and authentication handling for you.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2021-07-01 08:46:31

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: Connect user after create account on front end, possible ?

Hi Stef

The new code using your advice.

<form method="post">
              <input type="hidden" name="p_userid" value="test" />
              <input type="hidden" name="p_password" value="test" />
              <input type="submit" value="ok"/>
            </form>

            <txp:php>

              global $txp_user ;

              include_once( 'C:\wamp64\www\textpattern-4.7.3\textpattern\lib\txplib_admin.php' ) ;

              include_once( 'C:\wamp64\www\textpattern-4.7.3\textpattern\include\txp_auth.php' ) ;

              // echo txpath.'\lib\txplib_admin.php';

              $p_userid = gps('p_userid');
              $p_password = gps('p_password');

              if ($p_userid !== '')
              {
                doTxpValidate();
              }
            </txp:php>

Cheers.

Offline

#8 2021-07-06 10:31:10

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: Connect user after create account on front end, possible ?

Hi

I notice that to see the logged user you need to reload the page, did i miss something or textpattern is reloading the page twice ?

Cheers.

Offline

#9 2021-07-06 10:35:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: Connect user after create account on front end, possible ?

You should probably redirect to a back-end page (if appropriate) which you can always then bounce to the front-end, or (better, perhaps) refresh the current public page after you’ve called doTxpValidate() which will then do the ‘refresh’ for you.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB