This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

handle existing join+login page

In New to UserSpice? · Started by yuma on 2017-01-04 5:46 pm · 31242 views · 13 replies

Hi mudmin,

how do i replace an existing user management script that handles a page which already has its graphic design, that has both JOIN and LOGIN forms on it, with UserSpice?


yuma
The simplest thing to me would be to just use our login/join logic. In other words, you don't need to use our actual login.php form, but if you use your own form,just have it use the php that we use to do the actual logging in. Then each page just needs the init file and the securePage function.
Cool !I hope this is what I think it is. A custom register and login page? If yes how do we handle the google and Facebook login feature on d custom form .
Dealing with google/fb might be the easiest part of it because we do those with their own includes. So let's take a look.

Let's say you have

mydomain.com
mydomain.com/youroldfiles
mydomain.com/users (The bulk of the userspice files)

Let's say you have your login page (just for reference at)
mydomain.com/youroldfiles/yourlogin.php

If you open OUR login.php file and go to lines 117-124, you'll see that just above our actual login form, we have
<?php
if($settings->glogin==1 && !$user->isLoggedIn()){
require_once $abs_us_root.$us_url_root.'users/includes/google_oauth_login.php';
}
if($settings->fblogin==1 && !$user->isLoggedIn()){
require_once $abs_us_root.$us_url_root.'users/includes/facebook_oauth.php';
}
?>

That is all of our fb/google logic being included. So you could put that on your own login form in one of two ways...
1. Change the require once statements to "back out" of your folder and go over to the UserSpice folder.
require_once '../users/includes/google_oauth_login.php';

2. Put in the full url
require_once 'http://mydomain.com/users/includes/google_oauth_login.php';

I hope that helps.
Working well! I tried to take it to the next level . I used ajax tabs for login ,register and forgot password. I hope to achieve page navigation without reloading . (I hope this is added in US5) it all worked well until when user type wrong password ,email etc. I get redirected to the main join.php and login.php
I'm terrible at Ajax so I'm probably not much help.
What if I want to combine login.php with join.php?

I copied join.php logic to login.php and added _join.php view to the login.php. Next I changed $form_action ='join.php' to $form_action = 'login.php', so when I click register button I'm not sended away to join.php anymore.

Now here I'm stuck with some problems. If I now try to login OR register, I get Token doesn\'t match! message, after I click on login or register button.

I have tried to delete this line '<input type="hidden" value="<?=Token::generate();?>" name="csrf">' from login.php AND/OR from _join.php. I have tryed to rename tokens (from name="csrf" to name="csrf2") with no success. I have tried to comment out previous line of code and commented out the php logic that throws this error. But either way, the forms aren't working, or is only working one of them (either register or login).

@mudmin: can I somehow send you an PM?
Sure. I sent you an email asking you to pastebin your attempt at it and I will take a look.
Pastebin for login.php and _join.php

Site is online at oblak.ersim.si

Thanks!
I'm making some progress on this, but I'm going to be gone for the day, so it will be a bit till I can get back to you.
Ok. Looks like I figured it out. login.php and join.php created token when I combined join+login page. I just removed one token and everithing works fine now. It would be great if you could include login+join page in future release, so others can use that option too. I think it makes sense.

Regards, Jakob
I've spent a good bit of time trying to get those forms to play nicely together and I just can't get it to work. I'm open to any user submitted ideas. The OAUTH logins already work that way. They don't care whether you have an account already or not as far as the front end user sees.
Files on pastebin: login.php
_join.php

It is not thoroughly tested, but it works.
Thx JUG for your code, here is an ideea:)
I use switch to handle form action like this:
- in register form
<input type="hidden" name="action" value="register" />
- in login form
<input type="hdden" name="action" value="login" />
and then in php code
<pre>
  $action = $_POST['action'];
    switch ($action) {
       case 'login' :
// Login code
break;
case 'register' :
// Register code
break;
}
</pre>