Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Warden
  • A user database authentication & authorization package for FuelPHP. Handles user login and logout, acl, as well as secure password hashing. I coded this up cause i needed a whole different type of authentication from the fuel core auth package + the lack of docs & examples for the auth acl. It's still in dev and needs to be tested abit more. https://github.com/dre1080/warden
  • Hello together :-) can someone tell me how i can use the "profilable" feature? I created the table with some own colums like: 'title', 'first_name', 'last_name', 'city', 'country', 'refid'. I added it in the Model_Profile too ... My problem is, when I create an user with Model_User I can't use something like this: $user->title = 'Mr.'; It throws an exception: "Property "title" not found for Warden\Model_User." I've to use the Mode_Profile, but when I try to it: $profile->save()
    and get an error that the id fields can't be null ... How I make the releation between the two tables 'users' and 'profiles'? Many thanks in advance :-) Greets
  • You have to extend it in your APPPATH models: class Model_Profile extends \Warden\Model_Profile
    {
    protected static $_properties = array(
    'id',
    'user_id',
    // Your extra fields
    'title', 'first_name', 'last_name', 'city' ....
    );
    } Then you use it like: $user->profile->title = 'Mr.'; If you use the profile directly you have to assign it to a user before it can be saved: $profile->user = $user; See the FuelPHP Orm docs.
  • Andrew Wayne wrote on Sunday 13th of November 2011:
    I'm not getting any errors using your code, must be something else in your environment, try do a Warden::logout(true) then logging in again

    Could you provide a SQL dump, I think it might have something to do with my database and permissions...
  • Andrew Wayne wrote on Tuesday 1st of November 2011:
    I realize this should be explained better in the docs i'll add a better example for this.
    In your warden config file in the omniauthable section you should have in_use => true,
    then depending on your settings in the config files, you need to add a controller class Controller_Auth extends Controller_OmniAuth {}
    and add auth to your routes. The same way you would use Fuel NinjAuth package https://github.com/philsturgeon/fuel-ninjauth but you should already have a services table in your database, the example schema is in 'config/install.sql' or you can use oil to add the table to your db with 'php oil r warden --omniauthable' there's an example view file included in 'views/register.php'

    Thank you so very much for taking the time to spell that out... i think that should be all i needed :). Will try it and f/up later... for the assessment! Thx again, Andrew.
  • Added the routes in my config/routes.php file.
    Created the class controller to my classes/controllers/auth.php as stated by you and Ninjauth example. going to:
    http://mysite.com/auth/session/facebook yields...

    ErrorException [ Error ]: Class 'Warden\Strategy' not found
    PKGPATH/warden/classes/warden/omniauth/strategy/oauth2.php @ line 25 20 * @subpackage OmniAuth
    21 *
    22 * @author Phil Sturgeon, Modified by Andrew Wayne
    23 */
    24class OmniAuth_Strategy_OAuth2 extends Strategy
    25{
    26 public $provider;
    27
    28 public function authenticate()
    29 {
    30 // Load the provider


    [gulp!] I'm sure i didn't add something... not sure what tho - as i tried going to the same via different providers in the following: http://mysite.com/auth/session/twitter as well, and tho i *did* expect a twitter consumer / app key issue... it's not even getting that far... Bill
  • this was actually a typo which caused this error, fixed it now thanks.. In 'warden/classes/warden/omniauth/strategy/oauth2.php' you need to change line 24, the class 'OmniAuth_Strategy_OAuth2' should actually extend 'OmniAuth_Strategy' not 'Strategy' so line 24 should be: class OmniAuth_Strategy_OAuth2 extends OmniAuth_Strategy You can see it here https://github.com/dre1080/warden/commit/be60a49dd2919be81228e6238f6d63a1a6e760d5
  • Andrew Wayne wrote on Thursday 3rd of November 2011:
    this was actually a typo which caused this error, fixed it now thanks.. In 'warden/classes/warden/omniauth/strategy/oauth2.php' you need to change line 24, the class 'OmniAuth_Strategy_OAuth2' should actually extend 'OmniAuth_Strategy' not 'Strategy' so line 24 should be: class OmniAuth_Strategy_OAuth2 extends OmniAuth_Strategy You can see it here https://github.com/dre1080/warden/commit/be60a49dd2919be81228e6238f6d63a1a6e760d5
    Good catch! Here's the next barrier... ErrorException [ Error ]: Class 'OAuth2\Exception' not found
    PKGPATH/fuel-oauth2/classes/exception.php @ line 12 7 * @author Update to draft v10 by Edison Wong <hswong3i@pantarei-design.com>.
    8 */
    9
    10namespace OAuth2;
    11
    12class Exception extends Exception {
    13
    14 /**
    15 * The result from the API server that represents the exception information.
    16 */
    17 protected $result; Hmmm...
  • Hey all. I've been trying to test out Warden and have installed and configured it successfully via oil. However, when I try to add a feature (user tracking for example) I get SQL errors saying the table 'users' already exists. Here's what I've done... Step 1:
    php oil r warden -p
    

    Result:
    Warden installed successfully!
    

    Step 2:
    php oil r warden -c
    

    Result:
    Setting up Warden config...
    Error - SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists with query: "CREATE TABLE `users`...
    

    I've tried dropping the tables and "redoing" the installation, but nothing has worked. I'm stumped at this point. Gonna take a look at the warden.php tasks file to see if there is something there. Anyone else have any thoughts?
  • hey, this no longer works with the latest fuelphp and was actually fixed in the warden dev branch: https://github.com/dre1080/warden/tree/1.2/dev
    download this version instead and run:
    php oil r warden help
    

    Some commands with the new version: # Brand new install of Warden with profiles and lockable
    php oil r warden -p -l
    

    # Uninstall all traces of Warden (Drops tables and deletes Warden config file)
    php oil r warden:uninstall
    

    # Add feature(s) to existing Warden installation
    php oil r warden:feature -c
    
  • That one's actually a bug with the fuel-oauth2 package I think.. On line 12 the class is extending from global php Exception class but not taking the namespace into account. So line 12 of that file should actually be: class Exception extends \Exception { Notice the backslash
  • Andrew Wayne wrote on Thursday 3rd of November 2011:
    That one's actually a bug with the fuel-oauth2 package I think.. On line 12 the class is extending from global php Exception class but not taking the namespace into account. So line 12 of that file should actually be: class Exception extends \Exception { Notice the backslash

    Funny thing is i added the \ before i responded here and tho it got beyond that error, it yet found another... i'll put that here as well... that's why i reeled back cuz i thought by adding that \ to the global \Exception class that i was buggerin' it all up :). Post - adding the \ in front of the Exception... yields the following (*sigh*): ErrorException [ Error ]: Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]])
    PKGPATH/fuel-oauth2/classes/exception.php @ line 46 41 else
    42 {
    43 $message = 'Unknown Error.';
    44 }
    45
    46 parent::__construct($message, $code);
    47 }
    48
    49 /**
    50 * To make debugging easier.
    51 * with this as the raw error: <br />
    <b>Fatal error</b>: Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]]) in <b>C:\xampp\htdocs\projects\fuelapp\fuel\fuel\packages\fuel-oauth2\classes\exception.php</b> on line <b>46</b><br /> I know it's not yours, just figuring if we get it all working and submit a git update=>commit that'd be good schtuff for all. if you're on skype @wortell (is my nickname) let me know and i'd love to work with you and get a final .git up where it's turnkey with yours... (shrug), not trying to make more work for you - but would *love* to use your package... as it's the only one out there that incorp's all 3 options in a seamless use. Bill
  • Its no problem.. Unfortunately not on Skype.. What's the file trace for the error?
    And what's your php version? I was never getting this error. I think the problem is what's being passed into line 46.. Maybe try change that to: parent::__construct((string)$message, (int)$code); Or parent::__construct((string)$message); Have a feeling it might be your php version..
  • Tried both changes and both get beyond that point - but left with this doozy... OAuth2\Exception [ Error ]: R
    PKGPATH/fuel-oauth2/classes/provider.php @ line 70 65 $this->name = strtolower(substr(get_class($this), strlen('OAuth2\\Provider_')));
    66 }
    67
    68 if ( ! $this->client_id = \Arr::get($options, 'id'))
    69 {
    70 throw new Exception('Required option not provided: id');
    71 }
    72
    73 $this->client_secret = \Arr::get($options, 'secret');
    74 $this->scope = \Arr::get($options, 'scope');
    75 Backtrace PKGPATH/fuel-oauth2/classes/provider.php @ line 29
    PKGPATH/warden/classes/warden/omniauth/strategy/oauth2.php @ line 31
    PKGPATH/warden/classes/warden/controller/omniauth.php @ line 37
    COREPATH/classes/request.php @ line 443
    DOCROOT/index.php @ line 39 included file trace this time :) Bill
  • What provider are you trying to use? Facebook?
    Seems like you haven't included the client_id, in warden config, omniauthable => providers => facebook => id
  • Andrew Wayne wrote on Thursday 3rd of November 2011:
    What provider are you trying to use? Facebook?
    Seems like you haven't included the client_id, in warden config, omniauthable => providers => facebook => id

    First of all, i wanna thank you for your time, Andrew (+1 x 100) :P. Secondly, yes, i was trying the facebook provider and you're right it was still blank... didn't realize at first glance this was the 'wall'. I'll try the twitter account... just easier to create twitter apps, than fb... fuel-oauth uses twitter as well as yours... 'warden' overrides the fuel-oauth's? Bill
  • lol no problem, glad to help.. No warden doesn't override the fuel-oauth's, it only uses a modified fuel-ninjauth internally and already included so you don't have to do things like: $provider = OAuth2_Provider::factory('twitter', array(
    'client_id' => 'your-client-id',
    'client_secret' => 'your-client-secret',
    ));
    ......etc. and what you'll see in the fuel-oauth's readme.
    It handles this for you through the config and the help of fuel-ninjauth internally.
  • (no need to read this yet... i'll be back to update... - 5:26PM EST)
    (came back to edit this at 5:32PM EST) Well, it got stuck here... i tried putting a \ in front of the curl_init on line 49 - to reach the global namespace, but to no avail - you know you're *too* deep into namespaces when you try that sorta stuff... So if you get this...


    ErrorException [ Error ]: Call to undefined function OAuth\curl_init()
    PKGPATH/fuel-oauth/classes/oauth.php @ line 49 44 // The transfer must always be returned
    45 $options[CURLOPT_RETURNTRANSFER] = TRUE;
    46
    47
    48 // Open a new remote connection
    49 $remote = curl_init($url);
    50
    51 // Set connection options
    52 if ( ! curl_setopt_array($remote, $options))
    53 {
    54 throw new Exception('Failed to set CURL options, check CURL documentation: :url',


    Quietly - turn around, take a walk, cuz you've been at the computer too long...
    Then return calmly and... uncomment the curl extension in your 'freakin' PHP.ini file, then restart Apache. DOH! This happened, cuz i recently up'd my php to 5.3.8 = and didn't apparently do a good job comparing my older/newer php.ini files. (doh) Fixed that! Now i just get that freaky ssl cert issue which i know has 100% NOTHING to do with warden *OR* fuel-oauth... I'll have to now recall how to fix that blessed thing! Bill (thanks again for being avail. Andrew! truly!)
  • I think you don't have the php curl extension installed, thats why php isn't recognizing the curl functions or curl constants
    check your php.ini or try phpinfo() to see if curl is installed
  • Andrew Wayne wrote on Thursday 3rd of November 2011:
    I think you don't have the php curl extension installed, thats why php isn't recognizing the curl functions or curl constants
    check your php.ini or try phpinfo() to see if curl is installed

    you were 100% correct and i think i solved it and editted it before you got your response in ... but yeah, sorry, you got it on the nose... now onto the "cert stuff" for doing it on the localhost... (yuck!) always hate that part. Bill
  • Thanks AWayne. Hadn't even thought about issues with Fuel 1.2. Downloaded the dev branch of Warden and everything is up and running!
  • It works! Thanks a lot ... :-) EDIT: I've another problem now :-( If I use Warden::authenticate_user() and $remember is false the Warden::check() says false, but the authenticate said true ... If I set $remember to true, then the check returns true ... And Waren::current_user() returns in both situations false. What I do wrong?!
      public function action_index() {
        $val = Login::validate_form('form_login');
        Debug::dump(Warden::check());
        
        if (Input::method() == 'POST') {
          if ($val->run()) {
            $email = trim($val->validated('logEmail'));
                      
            if (Login::is_confirmed($email)) {
              $password = trim($val->validated('logPassword'));
              $remember = !is_null($val->validated('logRemember')) ? true : false;
              
              Debug::dump(Warden::authenticate_user($email, $password, $remember));
            }
            else {
              Session::set_flash('notice', 'You are not registred, please register first!');
            }
          }
          else {
            Session::set_flash('notice', $val->errors());
          }
        }
        
        $this->template->title    = "Login";
        $this->template->content  = View::forge('user/index')
             ->set('val',         $val, false);
      }
    

    Thanks!
  • are you using the latest version?
    try check your logs for a Warden error, it might not have saved the user
  • Okay, it comes back from twitter... and all seems well, and i've got the views/auth/register.php file in my app/ folder respectively - taking it from the sample views/register.php from warden/ package. However, at the bottom of the omniauth.php file it's coughin on some object issue... I tried to spit out the compact() result before it and all seems well, did a var_dump and the variables are 'set' and such, but for the life of me i cannot see why i cannot get beyond that point... ErrorException [ Error ]: Call to undefined method stdClass::body() DOCROOT/index.php @ line 57 52}
    53
    54// This will add the execution time and memory usage to the output.
    55// Comment this out if you don't use it.
    56$bm = Profiler::app_total();
    57$response->body(
    58 str_replace(
    59 array('{exec_time}', '{mem_usage}'),
    60 array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
    61 $response->body()
    62 )
    Backtrace COREPATH/bootstrap.php @ line 33
    Prior Non-Fatal Errors Runtime Notice: Creating default object from empty value in PKGPATH/warden/classes/warden/controller/omniauth.php @ line 102
    97 }
    98
    99
    100 display:
    101
    102 $this->response->body = \View::forge('register', array(
    103 'user' => (object)compact('username', 'full_name', 'email', 'password')
    104 ), false);
    105 }
    106}
    (gulp!) Bill
    (the 'warden' P.I.T.A.)
  • are you using profiles? I think it might be the view file, in register.php on line 10, try change: <?php echo Form::input('full_name', $user->profile->full_name); ?> to: <?php echo Form::input('full_name', $user->full_name); ?>
  • Yes I do ... The Log says that I should authenticate() and not authenticate_user(), but it changed nothing. The following Warning is also in the Log:
    Warning - 2011-11-30 10:51:56 --> Fuel\Core\Fuel::init - The configured locale en_US is not installed on your system.
    

Howdy, Stranger!

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

In this Discussion