How to make a custom server page for smart fox bits

Everything about the SmartFoxBits UI Components for SmartFoxServer 2X. Post your questions, suggestions and bug reports.

Moderators: Lapo, Bax

Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

How to make a custom server page for smart fox bits

Postby Sfulk » 06 Jul 2012, 17:12

There is really no documentation on how to create a custom server page for access validation, so I have no idea how to do it. The only thing I could find on it was on the Smartfoxbits documentation:

customLoginPage
public customLoginPage:String
(read,write)

The custom server-side page url for access credentials validation.
If this property is set, before attempting the SmartFoxServer login, the LoginBox will send the entered username and password to the provided url for validation.
Two parameters are passed to the custom server-side page via POST: name (the entered username) and pass (the entered password). The page must return res=OK if the credentials are valid or res=KO if the credentials are invalid.
Example:

To set the server-side page for custom login in MXML:

<sfb:LoginBox customLoginPage="http://localhost/sfsLogin.php" />

To set the server-side page for custom login in ActionScript:

loginBox.customLoginPage = "http://localhost/sfsLogin.php"

Component metadata:

Bindable
"customURLChanged"
Inspectable
category:
"General"
defaultValue:
""
name:
"Custom server page for access validation"
Attachments
help.png
(175.46 KiB) Not downloaded yet
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: How to make a custom server page for smart fox bits

Postby rjgtav » 06 Jul 2012, 19:57

Hi.

If I'm understanding it right, that custom page for access validation is a regular PHP file which checks the credentials received from the flash client as POST and then, after checking these credentials against a database, returns a res=OK in case the credentials were correct or a res=KO if they were wrong.
You can find lots of examples using PHP for checking credentials against a database on the web.

You can also check this chapter of the SmartFoxServer1X documentation, which has a simple example of how to create a PHP file which returns a res=OK or res=KO (it doesn't include database integration)
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

Re: How to make a custom server page for smart fox bits

Postby Sfulk » 07 Jul 2012, 23:50

Thanks for the help.
Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

Re: How to make a custom server page for smart fox bits

Postby Sfulk » 08 Jul 2012, 00:18

Do you know why the php script from the documentation wont work with the avatar chat example from smartfoxserver 2x. I looked through the code and don't see any reason why its not working correctly with Avatarchat. Its saying that the login credentials are invalid, when they are indeed valid.

Code: Select all

<?php
    // A Simple List of allowed users
    // You could substitute this code with a database connection
    $allowedUsers =  array ("Admin" => "test",
                            "test" => "test",
                            "Moderator" => "test");
   
    // The response variable
    $res = "res=KO";


    // Check incoming data
    if ($_POST['name'] != "" && $_POST['pass'] != "")

    {
        foreach($allowedUsers as $name => $password)
        {
            if ($_POST['name'] == $name && $_POST['pass'] == $password)

            {
                // Ok, user found
                $res = "res=OK";
                break;
            }
        }
    }
   
    print $res;
?>
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: How to make a custom server page for smart fox bits

Postby rjgtav » 08 Jul 2012, 11:40

I never actually tried the PHP file which is in the documentation page... If you return always res=OK, does it actually work correctly on the client side?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

Re: How to make a custom server page for smart fox bits

Postby Sfulk » 08 Jul 2012, 15:42

I tried setting it so that either way so if the login credentials are wrong or right it should still allow me access. It still says login Credentials are invalid, I dont understand why. :x
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: How to make a custom server page for smart fox bits

Postby rjgtav » 08 Jul 2012, 19:07

Please post the PHP code you're using
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

Re: How to make a custom server page for smart fox bits

Postby Sfulk » 08 Jul 2012, 21:19

Code: Select all

<?php
    // A Simple List of allowed users
    // You could substitute this code with a database connection
    $allowedUsers =  array ("Admin" => "test",
                            "test" => "test",
                            "Moderator" => "test");
   
    // The response variable
    $res = "res=KO";


    // Check incoming data
    if ($_POST['name'] != "" && $_POST['pass'] != "")

    {
        foreach($allowedUsers as $name => $password)
        {
            if ($_POST['name'] = $name && $_POST['pass'] = $password)

            {
                // Ok, user found
                $res = "res=OK";
                break;
            }
        }
    }
   
    print $res;
?>


I changed the one that says $res = "res=KO" I tried changing to OK so that way even if the login credentials didnt match the ones in the array it should still let me in but it wont.
User avatar
Bax
Site Admin
Posts: 4385
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: How to make a custom server page for smart fox bits

Postby Bax » 12 Jul 2012, 07:45

Have you tried calling your php page from a browser instead of the Flash client? It should simply display res=OK. If not, then something is wrong with your code.
As a side note, we really don't recommend the "server side page" approach to access validation.
It would be much better to use a SFS Extension and a custom login procedure as described in the documentation.
Paolo Bax
The SmartFoxServer Team
Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

Re: How to make a custom server page for smart fox bits

Postby Sfulk » 12 Jul 2012, 23:04

Bax wrote:Have you tried calling your php page from a browser instead of the Flash client? It should simply display res=OK. If not, then something is wrong with your code.
As a side note, we really don't recommend the "server side page" approach to access validation.
It would be much better to use a SFS Extension and a custom login procedure as described in the documentation.


Yes, I tried calling the php file from a browser it displayed res=OK. I still did not have any luck so I ended up figuring out how to use a SFS extension and custom login last night. The smart fox server 2x documentation is a little too vague in some areas, but may I ask why no one here recommends using the custom server page for login?
User avatar
Bax
Site Admin
Posts: 4385
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: How to make a custom server page for smart fox bits

Postby Bax » 13 Jul 2012, 10:23

Sfulk wrote:may I ask why no one here recommends using the custom server page for login?

Why using an external system, which requires you to setup a specific php web page on a separate server, when you can do everything (an much more securely) inside SFS? Also take into account that often a login system also returns other data to the application. With the internal approach you can retrieve any data from your database and transmit it to the client.
Paolo Bax
The SmartFoxServer Team

Return to “SmartFoxBits for SFS 2X”

Who is online

Users browsing this forum: No registered users and 1 guest