Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
MongoAuth - an auth package based on SimpleAuth
  • I needed mongo integration in an app I'm working on, and decided to throw together a simple "use case" mongo auth driver for FuelPHP based on SimpleAuth. Anyone is free to use the code: https://github.com/subliminal/mongoauth As it says at the bottom of the README, I haven't tested all of the methods yet, so there are likely problems. At this pointed, I've only tested the create_user and login functionality, both of which work. As an aside, I'm also working on a mongo session driver. Unfortunately, the Mongo DB driver for Fuel doesn't implement findandmodify so the code for that will have to wait (session storage in mongo it isn't safe without some degree of ACID compliance).
  • subliminal, I'm using your Mongo Auth package and it is great. I am having one issue. When I use $auth->get_user_array(); It gives me the following error stack: ErrorException [ Notice ]: Undefined index: group
    PKGPATH/mongoauth/classes/auth/login/mongoauth.php @ line 538 ErrorException [ Notice ]: Undefined index: additional_fields
    PKGPATH/auth/classes/auth/login/driver.php @ line 110 ErrorException [ Warning ]: array_merge(): Argument #1 is not an array
    PKGPATH/auth/classes/auth/login/driver.php @ line 110 ErrorException [ Warning ]: Invalid argument supplied for foreach()
    PKGPATH/auth/classes/auth/login/driver.php @ line 111
  • Mike Huntington wrote on Friday 30th of March 2012:
    subliminal, I'm using your Mongo Auth package and it is great. I am having one issue. When I use $auth->get_user_array(); It gives me the following error stack: ErrorException [ Notice ]: Undefined index: group
    PKGPATH/mongoauth/classes/auth/login/mongoauth.php @ line 538 ErrorException [ Notice ]: Undefined index: additional_fields
    PKGPATH/auth/classes/auth/login/driver.php @ line 110 ErrorException [ Warning ]: array_merge(): Argument #1 is not an array
    PKGPATH/auth/classes/auth/login/driver.php @ line 110 ErrorException [ Warning ]: Invalid argument supplied for foreach()
    PKGPATH/auth/classes/auth/login/driver.php @ line 111

    Whoops! I never user the auth drivers final functions so I forgot to test them :). The newest commit should fix it. Unfortunately because get_user_array is final, I can't override it. As such your return array is going to have a key/value pair of "screen_name" => null. Hopefully I can talk the core team into moving the screen_name field from the auth driver, and let the implementation drivers take care of it.
  • Hi i write this if you think can help you is full mongodbauth drivers based on simpleauth
    "acl, group, login divers". and is have some config options. https://github.com/daniel3d/mongodbauth it work whit username and email and you can config which collection to use and what fields you want to get back.
  • Looks like the packages are similar, however a couple of comments: 1) Your driver serializes the profile_fields data. The original SimpleAuth driver does this because it assumes a *SQL back-end. IMHO, SimpleAuth should be extended to avoid this with your particular setup. In the case of the Mongo driver, there's no reason to serialize data since its schema-less. 2) You don't actually need to include the auth driver.php files since they are already distributed with FuelPHP.
  • Thanks subliminal i remove serializes.
    But how i can avoid two query when i use email and username because when i try to use $mongodb->where(array(
    'username' => $username_or_email
    ))->or_where(array(
    'email' => $username_or_email
    ))->get('users'); i cannot get it work.
  • Daniel Yovchev wrote on Monday 19th of March 2012:
    Thanks subliminal i remove serializes.
    But how i can avoid two query when i use email and username because when i try to use $mongodb->where(array(
    'username' => $username_or_email
    ))->or_where(array(
    'email' => $username_or_email
    ))->get('users') i cannot get it work.

    That should work:
    $mongodb
        ->where(
            array(
                'username' => $username_or_email
            ),
        ->or_where(
            array(
                'email' => $username_or_email
            )
        ->get_one('users');
    

    Are you getting an error or is it not returning a user? Also, use get_one whenever you only want a single result. This way mongo stops searching the index once a document that matches the query is found.
  • No i don't get error just no results i try $query = $mongodb
    ->where(array(
    'username' => $username_or_email
    ))
    ->or_where(array(
    //'email' => $username_or_email
    ))
    ->get_one('users');
    when i comment the email i get the user.
    Then i try to comment the "//'username' => $username_or_email"
    and uncomment the "email" and i get the user.
    But when i try whit user and email i don't get results.
  • Daniel Yovchev wrote on Monday 19th of March 2012:
    No i don't get error just no results i try $query = $mongodb
    ->where(array(
    'username' => $username_or_email
    ))
    ->or_where(array(
    //'email' => $username_or_email
    ))
    ->get_one('users');
    when i comment the email i get the user.
    Then i try to comment the "//'username' => $username_or_email"
    and uncomment the "email" and i get the user.
    But when i try whit user and email i don't get results.

    First thing I'd do, is login to the mongo shell and run the query to make sure username and email are filled out for the user you are trying to grab. Assuming everything looks good, go into the mongodb/db.php and var dump everything before the $documents = (line 641) and see if something isn't working.
  • what query to build in mongo shell i try whit db.users.find({'username': 'Username', 'email': 'Emailaddress'})
    and i get the user back i var_dump the result of get_one() on line 658 in .../mongodb/db.php and i get back null
    when i use email and username when i comment one of them i get the user. what to var_dump to cheek for error...
    thanks

Howdy, Stranger!

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

In this Discussion