Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Skordy on January 25, 2018, 08:39:33 PM

Title: Custom Login/Register to External Header
Post by: Skordy on January 25, 2018, 08:39:33 PM
EDIT: !! I just realized I posted this in the wrong section >.> Can someone move this to the Integration forum, please? I'm sorry :(

Hello,

I know this has been asked a million times, and trust me, I have read through ALL of them, yet to no success.

I am trying to create a login/register form in the header of my site located at mysite.com and the forums at mysite.com/forum

Currently, I am having an issue just getting the login to work, I will tackle the registration next, which I will return to this thread if I have troubles with that. Below is my coding of the header for the login/registration section. It "works" sort of, as when I log in, it brings me to the forum and gives me an error stating "Your session timed out while posting. Please go back and try again."

Any help would be greatly appreciated, as I've exhausted my brain power trying to figure this out on my own, which is why I'm resorting to help. :P

Here is my coding structure directly regarding to the login portion. It all exists in one file. Additionally, I have tried this both with local cookies turned off/on AND Subdomain independent cookies off/on. Neither worked.


Top of the file
<!-- Forum Connect -->
<?php
require_once('./forum/SSI.php');
$_SESSION['login_url']='/'.$_SERVER['PHP_SELF'];
$_SESSION['logout_url']='/'.$_SERVER['PHP_SELF'];
$_SESSSION['user_id'] = $ID_MEMBER;
$_SESSION['username'] = $user_info['username'];
$_SESSION['email'] = $user_info['email'];
$_SESSION['admin'] = $user_info['is_admin'] ? 0;
?>


Header section containing login/register and Welcome/Logout (Which by the way, if I log into the forums, the welcome/logout work flawlessly.)
<!-- header -->
<div class="nav navbar-right">
            <?php
            
if ($context['user']['is_guest'])
            {
            
echo'
              <ul>
                <li class="hidden-xs-down"><a href="#" data-toggle="modal" data-target="#modal-login">Login</a></li>
                <li class="hidden-xs-down"><a href="#" data-toggle="modal" data-target="#modal-register">Register</a></li>
              </ul>'
;
            }
            else
            {
              
ssi_welcome();
            ssi_logout();
            }
            
?>

          </div>


And finally, the login Modal.
<!-- Login Modal -->
  <div class="modal fade" id="modal-login">
    <div class="modal-dialog modal-sm" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title"><i class="fa fa-sign-in"></i> Login to your account</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        </div>
        <div class="modal-body p-a-20">
          <form action="<?=$scripturl; ?>?action=login2" method="post" accept-charset="<?=$context['character_set']; ?>">
            <div class="form-group input-icon-left m-b-10">
              <i class="fa fa-user"></i>
              <input type="text" name="user" value="<?=$user_info['username']; ?>" class="form-control form-control-secondary" placeholder="Username">
            </div>
            <div class="form-group input-icon-left m-b-15">
              <i class="fa fa-lock"></i>
              <input type="password" name="passwrd" class="form-control form-control-secondary" placeholder="Password">
            </div>
            <input type="hidden" name="cookielength" value="-1" />
          <input type="submit" value="Login" name="login" class="btn btn-primary btn-block m-t-10">
          </form>
        </div>
      </div>
    </div>
  </div>
Title: Re: Custom Login/Register to External Header
Post by: Kindred on January 25, 2018, 11:46:05 PM
Why not just use ssi_login();?
Title: Re: Custom Login/Register to External Header
Post by: Skordy on January 26, 2018, 01:08:04 AM
Quite simply, ssi_login(); is a pain to style, considering I've already done all the styling for other forms for the site, I'd like them to be uniform.
Title: Re: Custom Login/Register to External Header
Post by: Kindred on January 26, 2018, 11:59:09 AM
you realize that you can style SSI functions by using something other than the "echo" argument?
Title: Re: Custom Login/Register to External Header
Post by: Skordy on January 26, 2018, 04:56:13 PM
I was not aware, please share? Only way I found on how to do it was creating a whole new style sheet. Additionally, I'd like to be able to put font-awesome icons to signify the box, rather than using a "Username" label.
Title: Re: Custom Login/Register to External Header
Post by: Skordy on January 29, 2018, 12:22:12 AM
How would one go about using ssi_login as you suggested Kindred? I've read the docs over and over, and can't quite get it. I assume it's probably close to how the ssi_boardNews functions are used, but I just can't nail the login portion down.
Title: Re: Custom Login/Register to External Header
Post by: Kindred on January 29, 2018, 04:28:54 PM
function ssi_login($redirect_to = '', $output_method = 'echo')

so....


require_once('SSI.php');

$my_login=ssi_login('','array');



you should then be able to call the various data points using the $my_login array...


but, looking at the actual code, it looks like anything but echo automatically bumps the attempt out, which is strange. It's a contradiction of every other ssi function....




So, the solution?

copy the entire ssi_login function to the bottom of SSI.php and re-name it something like ssi_my_login
then just use your OWN HTML and CSS to define the login form.


// Shows a login box.
function ssi_my_login($redirect_to = '', $output_method = 'echo')
{
global $scripturl, $txt, $user_info, $context, $modSettings;

if ($redirect_to != '')
$_SESSION['login_url'] = $redirect_to;

if ($output_method != 'echo' || !$user_info['is_guest'])
return $user_info['is_guest'];

echo '
<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '">
<div class="login-form">
<div><label for="user">', $txt['username'], ':</label>&nbsp;<input type="text" id="user" name="user" size="9" value="', $user_info['username'], '" class="input_text" /></div>
<div><label for="passwrd">', $txt['password'], ':</label>&nbsp;<input type="password" name="passwrd" id="passwrd" size="9" class="input_password" /></div>
<div><input type="hidden" name="cookielength" value="-1" /><input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" /><input type="submit" value="', $txt['login'], '" class="button_submit" /></div>
</div>
</form>';

}
Title: Re: Custom Login/Register to External Header
Post by: Skordy on January 30, 2018, 12:26:56 AM
You sir, are a genius. That worked perfectly. And opened me up to a WHOLLLLLLE lot more customization. Thank you!