News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Re: How do I log into SMF from my application?

Started by cache, April 12, 2021, 08:15:10 AM

Previous topic - Next topic

cache

So glad you started this thread, OP. I've been hunting high and low for what I thought would be easy, discovering semi-helpful snippets along the way, but no definitive answer. It may be there somewhere, but it's the old classic "if you don't know how to specify exactly what you're searching for, it's easy to miss it".

BTW I hope I haven't offended anyone by that opening para. I'm not blaming anyone for the data being hard to find.

My hope is to be able to keep the login and logout within my own pages, so a user can login - to both my SMF forum and my non-SMF pages - but without being confronted by the SMF boards page, which is normally what a successful login redirects to if I use ssi_login().

I haven't got very far, but so far my thoughts are:
it should be possible to script a form to collect and POST the username/pwd credentials, but not sure how to deal with the hidden field;
I'll need my script to eat the entire HTML returned after a successful login, and replace it with my own.

It would be nice to think that this could be done nice and transparently with a bit of Ajax.

Do I seem to be on the right lines? Is there something I've missed which does this already?


cache

Quote from: Kindred on April 12, 2021, 08:41:24 AM
function ssi_login($redirect_to = '', $output_method = 'echo')

Ah yes, that's a major step forward (which I should have spotted), so thank you for pointing me to it.

Not a complete solution. I really want to redirect members back to the page they were on when they discovered a need to log in, not a separate standard page from which they'll have to renavigate their own way back. Which is why the ajax idea is so appealing.

Kindred

you can redirect back to the previous page.

In the code, record the page that they are on into a variable
then call ssi_login using the recorded variable as the argument.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

cache

Quote from: Kindred on April 12, 2021, 10:24:11 AM
you can redirect back to the previous page.
Er, yes, that would work. Thanks again.

At the risk of sounding churlish my real problem is having to use the table layout provided with ssi_login(), when I want a nice inline username/password form like the SMF site has at the top. If CSS can force table rows into a single line I'm not aware of it.

CoderLanie, didn't really understand your last post. Are you needing to double authenticate (with SMF and your own website)?

Aleksi "Lex" Kilpinen

Quote from: cache on April 12, 2021, 02:16:03 PM
Quote from: Kindred on April 12, 2021, 10:24:11 AM
you can redirect back to the previous page.
Er, yes, that would work. Thanks again.

At the risk of sounding churlish my real problem is having to use the table layout provided with ssi_login(), when I want a nice inline username/password form like the SMF site has at the top. If CSS can force table rows into a single line I'm not aware of it.
It would be better if you opened your own topic if you wish to continue. We try to keep separate issues separate, makes topics easier to follow for everyone.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

cache

Point taken, and I certainly don't want to hijack a thread, but the original heading "How do I log into SMF from my application?" is exactly the question I came here to find an answer to. I now recognise it's possible the OP and I have different needs though.

Kindred

#6
Topic split....

Quote from: cache on April 12, 2021, 02:16:03 PM
Quote from: Kindred on April 12, 2021, 10:24:11 AM
you can redirect back to the previous page.
Er, yes, that would work. Thanks again.

At the risk of sounding churlish my real problem is having to use the table layout provided with ssi_login(), when I want a nice inline username/password form like the SMF site has at the top. If CSS can force table rows into a single line I'm not aware of it.

Oh, well, that's simple as well...

something like this...



$cur_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

require_once('path/to/SSI.php');
global $context,  $txt;

if (!$context['user']['is_guest'])
ssi_welcome();
else {
ssi_login($cur_link, 'block');

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

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

cache

Ah, light dawns. Pretty sure I can make that work. Thank you so much for your time, Kindred, much appreciated.

Advertisement: