Custom login script

Nnirvi

Member
Hi!

I need some customization to xenForo's login. Once the user has entered his credentials, a script would match two custom fields of his profile with two rows in a custom table within the xenForo database. If both match, user gets in. If not, user doesn't get in.

I have a PHP script which basically does this, I just don't know how can I insert it into xenForo's login. Where do I start?
 
Actually, you can setup a hidden login form on the page then use javascript to submit it:

PHP:
Code:
echo "<div style='display:none;'>";
echo "<div id="username">$userLogin</div>";
echo "<div id="pass">$userPass</div>";
echo "</div>";

HTML:
Code:
<form action="login/login" method="post" id="pageLogin" style="display:none;">
    <input type="text" name="login" value="" id="ctrl_pageLogin_login" class="textCtrl" required="required" />
    <input type="password" value="" name="password" class="textCtrl" id="ctrl_pageLogin_password" required="required" />
    <input type="checkbox" name="remember" value="1" id="ctrl_pageLogin_remember" style="margin-right:4px;" checked />Stay logged in
    <input type="submit" style="display:block;" class="submitButton newButton" id="login" value="Login"/>
    <input type="hidden" name="cookie_check" value="1" />
    <input type="hidden" name="_xfToken" value="" />
    <input type="hidden" name="redirect" value="/community/find-new/threads?recent=1" />
</form>

Javascript:
Code:
document.getElementById('ctrl_pageLogin_password').value = document.getElementById('pass').innerHTML;
document.getElementById('ctrl_pageLogin_login').value = document.getElementById('username').innerHTML;
document.getElementById('login').click();
 
I assume that if I change that function, future updates would break the functionality? How do I keep that from happening?

Any possible caveats in the JS approach?
 
Ok, found the function and read a good tutorial on how to build an add-on. At the moment it looks like this:

Code:
<?php

class validointi_ControllerPublic_validointi extends XFCP_validointi_ControllerPublic_validointi
{

    public function actionLogin()
    {
        echo "No heippa taas maailma. Loggauduit juuri sisään.";
    }

}

Now, this should be ok, I followed the tutorial to the letter where applicable. How could I test this? It doesn't print anything but I guess it's not supposed to. At this point I just want to see that it's working.
 
I'm starting to get a hang of this, the script runs now. Whatever I type into that actionLogin overwrites the default actionLogin function, right?
 
Sorry for the spam, making progress here tho, this is pretty cool stuff :) So, now I can execute stuff inside that function, for example sleep(10); worked fine. Alas, echo doesn't work anywhere. I'd need some way to debug the function - to make it print variables somewhere. Any ideas?
 
I've never really taken the time to learn how to write PHP correctly inside XenForo, all of my mods (including the one above) are running on PHP files outside XenForo. Makes it simpler, I only have to worry about my PHP/HTML/Javascript not working.

Sorry I can't be of more help at this point.
 
Ok, thanks anyways. I just noticed that this thread should be in development discussion, sorry.

Anyone else have an idea?
 
Here's a few things to look into, but I don't know if it'll help:
- Many of the XenForo controllers have a "viewParams" variable in the PHP file that list variables that are accessible to the templates. For example, the XenForo file that shows the "Alerts" page has the "$alerts" variable in the viewParams on the PHP file.

If you can get it working that far, variables accessible to a template can be shown by simply putting {$variableName} in the template for the page you're working on. You can even do {xen:helper dump, $variableName} to see the full contents of the variable. That's especially useful if you need to see what's inside an array variable.

Some useful reading:
http://xenforo.com/community/threads/1-0-0-b1-finding-variables-available-to-templates.6071/

Hope that gets ya going in the right direction. :)
 
I'm working on a login script so it isn't a page as such. Would it be feasible to define a variable, let's say a string "Hello world" within the actionLogin function and then render it in some template?
 
That's the direction I was thinking, maybe you can setup the PHP file to hook into a page node?

The page nodes can use template syntax in their HTML, I'd assume that's the direction you have to go.
 
I've already done a similar experiment where an external PHP feeds stuff into a xenForo template and it worked fine. This is a bit different because the modified actionLogin function should do the same. I've made a working plugin that extends the function, at this point it does nothing, it just includes the same stuff as the default actionLogin (by the way, does this overwrite the function or add to it?). I can't hook this file to a template the same way as the previous test as it would try to run the whole actionLogin inside a template.
 
I used the code hidden form and javascript and it works perfectly for what I need.

But there is something else I need in addition: I need a way to register people in Xen Foro from my external app. Any ideas on how to do that? Same approach?
 
Back
Top Bottom