Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Login driver.....
  • Hi all,

    A quick question regarding client's login drivers. Using simpleauth the client has created a base class for login and a view page to display the login (username and password).

    However, I am quite confused whether to create a separate login driver or use the same one and edit the base controller and add the new routes (such as the login route used by the client) in order to create a new login page. Also, regarding the new login page would I have to create a new nested view folder or just use the existing one.


    I am running the site on localhost and trying to create a separate login page to enable the client to access mysql db snapshot on a click of a button (I have a db copy running on toad mysql)


    app / config

    'package_paths'  => array(
    PKGPATH,
    ),

    config / auth.php

    return array (
    'driver'  => 'Simpleauth',
    'verify_multiple_logins'  => false,
    'salt'  => 'put_your_salt_here',
    'iterations'  => 10000,
    )

    app / controller (base class for login driver)
    * Controller for all pages requiring logged-in access.
    *
    * Redirects to login page if not logged-in.
    abstract class Controller_Protected extends Controller
    {
    public function before()
    {
    parent::before();

    if (!Session::get( ' login ' )) {
       Response::redirect( ' /entry/login ' );
    }
    }
    }

    The login page is in a nested view folder called entry under app/views.

    Thank you
  • HarroHarro
    Accepted Answer
    The login driver is a class, it is totally unrelated to a page?
  • Seems like I need to have another read of the docs. I will get back to you once I clarify my concepts.

    Thank you 
  • Hi Harro,

    After further reading I have clarified some areas that I was having trouble grasping.

    However, I am now confused as to what driver my client is using since the config.php under fuel/app is directing to PKGPATH (packages directory). Now in the packages directory the client has the simpleauth drivers (simpleauth.php, simplegroup.php, simpleacl.php) and ormauth drivers (ormauth.php, ormgroup.php, ormacl.php). Also, in the auth.php file in config/auth.php the login driver being loaded is 'Simpleauth'. So, I am assuming the client is using the simpleauth driver in the auth package.

    I need a separate login page so would that mean creating a custom driver class and configuring it in auth.php (e.g. below) 

    return array(
    'driver' => 'Simpleauth', 'custom',
    );


    Thanks in advance
  • HarroHarro
    Accepted Answer
    I am still puzzled to what you want to achieve.

    Fuel has an authentication package called Auth. It comes with two systems, Simpleauth, which uses a users table and simple config files files for groups and rights, and Ormauth, which uses the ORM and a relational database design for users/groups/rights.

    On your login page you would have a user and a password field, that would POST the two to your login controller method. That would call Auth::login() to perform the login against the configured user table.

    Why would you need a separate (other?) login page, and why would you need a custom driver class? To do what, functionally?
  • Thank you for the succinct explanation.

    The client has a login page and yes, it does POST username and password to the login controller method. However, the current login page is not only live but also enables the user to access and modify data to enter into the database. The new feature that the client requires is a completely separate login page with a new username and password (I have create a test table in mysql database on my local machine). Once, logged in the client wants to be able to access quarterly snapshots of the data behind the live site e.g. authors name, book titles etc at the click of a button.

    So, I wanted to ask whether to use Simpleauth system or the Ormauth since the client is the only user that should be able to access the second login page. Also, I don't know if I have mentioned this but I am working on a test version of the live site on my local machine and not directly on the live version.

    Thanks and apologies in advance
  • HarroHarro
    Accepted Answer
    Normally you would do that with roles (or groups), and determine that what which user can access what within the application. 

    So you could create a group "snapshot" and members of that group have access to the snapshot data, and another group called "live" who's members gave access to the live data? 

    If it has to be through two different login pages, you can still route those URI's to the same login controller, and then use the URI to determine which view to use (for a different look-and-feel if needed). After login you store the URI (or some other flag) in the session to record which login page was used, and use that session variable in the app to determine the rights...

    If you really need to completely separate login systems (so a user can have accounts in both), you can go one step further with the previous idea, and use the URI to switch user tables, something like:

    if ( $uri == '/snapshot/login' )
    {
        \Config::load('simpleauth', true);
        \Config::set('simpleauth.table_name', 'snapshot_users');
    }

    if ( \Auth::login($user, $pass) )
    {
        ....
    }

    If your snapshot and live data (and their users) are in two different databases, define those databases in your db config file, call them "live" and "snapshot" (for example), and set "live" as default.

    You can then make the login switch databases using

    if ( $uri == '/snapshot/login' )
    {
        \Config::load('simpleauth', true);
        \Config::set('simpleauth.db_connection', 'snapshot');
    }

  • Thank you very much for replying.

    I am extremely sorry for taking your time and going through all this confusion but I seem to have completely missed a subdirectory in the app/controller :( 

    All I had to do was create another sub controller and create a login page for downloading snapshots. I have successfully created the login page and I am now looking to create a controller for snapshots and allocate appropriate routing.




  • HarroHarro
    Accepted Answer
    No problem, that is what a support forum is for.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion