Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Warden
  • Looking at you're code that means it returned true for authentication, it returned nothing before because your username and password combination was wrong and authentication returned false, you have nothing after your 'if' statement to make it show that a wrong username/password was given.. This isn't a warden issue, just an issue with your code.. You should read through the fuelphp docs first
  • Andrew Wayne wrote on Thursday 10th of November 2011:
    Looking at you're code that means it returned true for authentication, it returned nothing before because your username and password combination was wrong and authentication returned false, you have nothing after your 'if' statement to make it show that a wrong username/password was given.. This isn't a warden issue, just an issue with your code.. You should read through the fuelphp docs first
    I have a else statement I just didn't include it to reduce the amount of lines in the post... I tried removing all of the validation stuff and using the Input class but still no look.
  • Ok so I removed the Redirect inside the Warden::authenticate if statement and did a simple print statement to check to see whether it was working. It was, so I then did some digging and checked the sign in attempts (sign_in_count - field) in the database itself and found that the number wasn't increasing. I then decided to try the password... and found that with a incorrect password the sign_in_count was incrementing but when I print_r Warden::check() I still get nothing?
  • Any advice? Anyone?
  • Aran Wilkinson wrote on Thursday 10th of November 2011:
    Ok so I removed the Redirect inside the Warden::authenticate if statement and did a simple print statement to check to see whether it was working. It was, so I then did some digging and checked the sign in attempts (sign_in_count - field) in the database itself and found that the number wasn't increasing. I then decided to try the password... and found that with a incorrect password the sign_in_count was incrementing but when I print_r Warden::check() I still get nothing?

    Yes that's how its supposed to work when the lockable feature is active.
    As for Warden::check(), what do you mean by getting nothing? Warden::check() always returns true or false. Use a var_dump not print_r, print_r doesn't give real values for booleans.
  • I tried var_dump() and I got this... This is what happens after Warden::authenticate executes and gets caught by the if() statement... Logged in! <--- print_r
    bool(false) <--- var_dump(Warden::check())
    bool(false) <--- var_dump(Warden::current_user())
    Array ( [authenticity_token] => MkZ2Lm4vNThxbDdlYXJFVDFHbVNvVS9wVVdqT3Q3OGQ6MTMyMTA0NDczNQzz ) <-- print_r(Session::get())
  • Its working as expected, there's nothing wrong.
    print_r will always return 1 for true boolean values and nothing if the value is false.
    to test this do print_r(false) <-- returns nothing, and print_r(true) <-- returns 1.
    As you can see var_dump returned false which means you are not logged in. So everything is working correctly.
  • So why cant I find out details like the current user and role rights?
  • You can only find out those details if there is a successsful authentication, ie. how will you find a current user if there isn't one
  • Yeah but I got a successful authentication surely because Warden::authenticate executed as expected and went into the if statement as expected and set a session auth token... Surely now I got a successful authentication so I can access the users details?
  • Something must have gone wrong during the authentication and the auth tokeen wasn't saved to the database or the account is locked. What version of warden are you using?
    Check your database, is there an authentication_token? Is there an unlock_token set?
  • There is a auth token set but no unlock_token? Unlock_token = null... I may start again and reinstall it all... Using latest version from Github.
  • Do the auth tokens match? The session and db token? Can you post the full code in your controller action
  • Andrew Wayne wrote on Saturday 12th of November 2011:
    Do the auth tokens match? The session and db token? Can you post the full code in your controller action

    Yup they are identical... Note this is not production code, its been put together for testing... public function action_login()
    {
    if (Warden::check()) {
    echo "Logged In";
    } $this->auto_render = false;
    $data = array(); $data = "Admin Login - 87.7 Bailrigg FM"; if (Input::method() === 'POST') {
    try {
    if (Warden::authenticate(Input::post('username'), Input::post('password')))
    {
    print("Logged in!");
    var_dump(Warden::check());
    $current_user = Warden::current_user();
    print_r($current_user);
    print_r(Session::get());
    // Response::redirect('common/check');
    }
    } catch(Exception $e) {
    throw new Exception("Error: " . $e);
    }
    }
    // Authenticate user // else
    // {
    // Session::set_flash('error', 'Incorrect username or password.');
    //
    // Response::redirect('login');
    // }
    $this->response->body = View::forge("admin/login", $data);
    }
  • Hi!
    i followed installation steps, all right, but ... how can i use Warden? shall i create a 'common controller' with a function like:
    public function before()
    {
    if (!Warden::check())
    {
    Response::redirect('..../register');
    }
    }
    and extend all my controller with those 'Controller_Common'? I'm lost...
  • Use it like you would any Auth package, you can place the code wherever you would like, have a look at the 'classes/warden.php' file for additional methods. For example the code you've written above would disallow access to users who are not logged in so use it depending on your needs. View the README for usage examples http://github.com/dre1080/warden
  • Is this a package or a module? When I run the oil refine tools, it is looking for the Warden module and says it doesn't exist.
  • This is a package and the oil task has only been tested with the latest oil package, what version of fuelphp are you running?
  • Wow, quick response, thank you. I am running rc1.1 Fresh from the master branch. One other thing is that the fresh install of the warden package gives an error in the bootstrap it is looking for CryptLib rather than "cryptlib" in all lower case. I fixed that by just changing it in the bootstrap. I've not really had a chance to play with this yet and stumbled on it thankfully. I was getting ready to start working on an auth package that had the features I needed for a healthcare app I am working on and this seems like it will work.
  • yea im fixing this issue with the next commit, there's an issue with namespaces and directory names in windows and unix systems
    thanks
  • 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
  • Andrew Wayne wrote on Monday 31st of October 2011:
    yea im fixing this issue with the next commit, there's an issue with namespaces and directory names in windows and unix systems
    thanks

    Wow, am i feelin' like the 'el stupido' :)... been *SO* into FuelPHP lately and now you go ahead and create this uber auth class - which incorp's the fuel-oauth[2], shiznit... and now i'm feeling stupid as to how to actually - Uh... implement it... i got the files copied etc... and i see the code examples... but shouldn't i just be able to go to: http://mysite.com/auth/register ???
    or...
    http://mysite.com/auth/login ???? I get the proverbial 404's... as if it has no clue what i'm talking about... For some reason (i'm sure - again - i am missing something), Wayne, I'm missing something... do i go ahead and create the views for this? Just hoping for a *bump* into the right direction... thanks...
  • 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'
  • 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

    So you can return users details? ... :-/ Hmmmm

Howdy, Stranger!

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

In this Discussion