GithubHelp home page GithubHelp logo

Comments (34)

andrew13 avatar andrew13 commented on August 16, 2024

If you are only going to use email you need to specify email only. Example:

Confide::logAttempt( array('email' => $user['email'], 'password' => $user['password']), true, array('email') )

Side note: I did this as it would be done in php 5.3, your example in php 5.4 would look like:

Confide::logAttempt( ['email' => $user['email'], 'password' => $user['password']], true, array('email') )

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

@andrew13 : I am passing an array as the first parameter, it is returning true for the logAttempt meaning the database call and check passed, unless without passing the $identity_columns would change the session behavior

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

When did you last do a composer update? You should be required to pass in username and email unless you specify only email.

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

@andrew13 : just now and also, according to master, it's optional: https://github.com/Zizaco/confide/blob/master/src/Zizaco/Confide/Confide.php#L95

The validation part works perfectly fine, is the fact that if you authenticate 2 users in a row , the Confide::user() doesn't get updated accordingly

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

Not exactly, both username and email will be checked for in the $credentials array. Username is checked for first, followed by email.

if($i == 0)
{
    $user_model = $user_model->where($column,'=',$credentials[$column]);
}
else
{
    $user_model = $user_model->orWhere($column,'=',$credentials[$column]);
}

Which, in your example, the sql will result in
where username = null
OR
where email = $user['email']

Since the column username is not defined in the $credentials array, when the loop attempts to find it it will spit out a notice and return null. So you could ignore it but it isn't safe to do so.

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

weird..how come it returns true for me, let me double check my code, will update this thread

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

I haven't been able to confirm your bug, but let's keep working on it until we find the solution. Maybe there's a bug in there somewhere.

When you do

Confide::logAttempt(['email' => $user['email'], 'password' => $user['password']]);
Confide::user(); //What does this return?
Confide::logout();
Confide::logAttempt(['email' => $user['email'], 'password' => $user['password']]);
Confide::user(); //this returns null

What does it return?

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

perhaps I need to note that I am doing this inside phpunit environment. I am not sure if that changes anything or not.
I am working on it, will update soon

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

ok, I tried it and Confide::user() returns null
this is my logAttempt
if (Confide::logAttempt(['email' => $input['email'], 'password' => $input['password']], true, ['email'])){

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

This does actually bring up a good point. We could have it so it checks the array index and if it exists do the where, if not don't. This would avoid the check against null. Added a pull request for this case.

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

It still doesnt explain why Confide::user() returns null after 2 logAttempts though, I havent tried it in a browser environment, I am in phpunit

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

No it doesn't, but just made me think of it. I'll be testing in 5.4 w/ database sessions momentarily. Waiting for my vm to update.

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

ah, thanks for checking this up @andrew13

from confide.

andrew13 avatar andrew13 commented on August 16, 2024
ok, I tried it and Confide::user() returns null
this is my logAttempt
if (Confide::logAttempt(['email' => $input['email'], 'password' => $input['password']], true, ['email'])){

So it gives you null both times? or just the second?

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

@hyusetiawan You're welcome

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

@andrew13 : the second, the first time works just fine

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

Great, I'll let you know what I find out.

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

So I did this through a controller:

        Confide::logAttempt( ['email'=>'[email protected]','password'=>'admin'], true, ['email'] );
        var_dump(Confide::user());
            Confide::logout();
            Confide::logAttempt( ['email'=>'[email protected]','password'=>'admin'], true, ['email'] );
        var_dump(Confide::user());
        die();

Ended up with both logged in:

object(User)[392]
  protected 'table' => string 'users' (length=5)
  protected 'hidden' => 
    array (size=1)
      0 => string 'password' (length=8)
  public 'autoHashPasswordAttributes' => boolean true
  public 'validationErrors' => 
    object(Illuminate\Support\MessageBag)[393]
      protected 'messages' => 
        array (size=0)
          empty
      protected 'format' => string '<span class="help-inline">:message</span>' (length=41)
  public 'autoHydrateEntityFromInput' => boolean false
  public 'forceEntityHydrationFromInput' => boolean false
  public 'autoPurgeRedundantAttributes' => boolean false
  protected 'purgeFilters' => 
    array (size=0)
      empty
  protected 'purgeFiltersInitialized' => boolean false
  protected 'connection' => null
  protected 'primaryKey' => string 'id' (length=2)
  protected 'perPage' => int 15
  public 'incrementing' => boolean true
  public 'timestamps' => boolean true
  protected 'attributes' => 
    array (size=8)
      'id' => string '1' (length=1)
      'username' => string 'admin' (length=5)
      'email' => string '[email protected]' (length=14)
      'password' => string '$2y$08$wcSSvuDQsLF7p6WyHkPSF.QRbaqkE/a9Ro4f/taWP6Cu8GIYran8y' (length=60)
      'confirmation_code' => string 'fae75df69e37b9d66cb955004fe3c4a7' (length=32)
      'confirmed' => string '1' (length=1)
      'created_at' => string '2013-03-18 00:59:08' (length=19)
      'updated_at' => string '2013-03-18 00:59:08' (length=19)
  protected 'original' => 
    array (size=8)
      'id' => string '1' (length=1)
      'username' => string 'admin' (length=5)
      'email' => string '[email protected]' (length=14)
      'password' => string '$2y$08$wcSSvuDQsLF7p6WyHkPSF.QRbaqkE/a9Ro4f/taWP6Cu8GIYran8y' (length=60)
      'confirmation_code' => string 'fae75df69e37b9d66cb955004fe3c4a7' (length=32)
      'confirmed' => string '1' (length=1)
      'created_at' => string '2013-03-18 00:59:08' (length=19)
      'updated_at' => string '2013-03-18 00:59:08' (length=19)
  protected 'relations' => 
    array (size=0)
      empty
  protected 'fillable' => 
    array (size=0)
      empty
  protected 'guarded' => 
    array (size=0)
      empty
  protected 'dates' => 
    array (size=0)
      empty
  protected 'with' => 
    array (size=0)
      empty
  public 'exists' => boolean true
object(User)[391]
  protected 'table' => string 'users' (length=5)
  protected 'hidden' => 
    array (size=1)
      0 => string 'password' (length=8)
  public 'autoHashPasswordAttributes' => boolean true
  public 'validationErrors' => 
    object(Illuminate\Support\MessageBag)[406]
      protected 'messages' => 
        array (size=0)
          empty
      protected 'format' => string '<span class="help-inline">:message</span>' (length=41)
  public 'autoHydrateEntityFromInput' => boolean false
  public 'forceEntityHydrationFromInput' => boolean false
  public 'autoPurgeRedundantAttributes' => boolean false
  protected 'purgeFilters' => 
    array (size=0)
      empty
  protected 'purgeFiltersInitialized' => boolean false
  protected 'connection' => null
  protected 'primaryKey' => string 'id' (length=2)
  protected 'perPage' => int 15
  public 'incrementing' => boolean true
  public 'timestamps' => boolean true
  protected 'attributes' => 
    array (size=8)
      'id' => string '1' (length=1)
      'username' => string 'admin' (length=5)
      'email' => string '[email protected]' (length=14)
      'password' => string '$2y$08$wcSSvuDQsLF7p6WyHkPSF.QRbaqkE/a9Ro4f/taWP6Cu8GIYran8y' (length=60)
      'confirmation_code' => string 'fae75df69e37b9d66cb955004fe3c4a7' (length=32)
      'confirmed' => string '1' (length=1)
      'created_at' => string '2013-03-18 00:59:08' (length=19)
      'updated_at' => string '2013-03-18 00:59:08' (length=19)
  protected 'original' => 
    array (size=8)
      'id' => string '1' (length=1)
      'username' => string 'admin' (length=5)
      'email' => string '[email protected]' (length=14)
      'password' => string '$2y$08$wcSSvuDQsLF7p6WyHkPSF.QRbaqkE/a9Ro4f/taWP6Cu8GIYran8y' (length=60)
      'confirmation_code' => string 'fae75df69e37b9d66cb955004fe3c4a7' (length=32)
      'confirmed' => string '1' (length=1)
      'created_at' => string '2013-03-18 00:59:08' (length=19)
      'updated_at' => string '2013-03-18 00:59:08' (length=19)
  protected 'relations' => 
    array (size=0)
      empty
  protected 'fillable' => 
    array (size=0)
      empty
  protected 'guarded' => 
    array (size=0)
      empty
  protected 'dates' => 
    array (size=0)
      empty
  protected 'with' => 
    array (size=0)
      empty
  public 'exists' => boolean true

Granted it's through a controller not through phpunit. I don't have a test handy to test a double login at the moment.

Do you get any errors?

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

i dont get any errors, it's just the second time it returns a null, how does it look when the second one is a different user?

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

Ah, then it's null. We're getting somewhere now. :)

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

ok so im not crazy, at least not yet :D

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

Nevermind, had a typo in the password. Both users are returned. :(

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

darn, does that mean I can't test on phpunit if I want to switch between users?

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

that doesn't seem correct. Can you verify that the database information is being removed?
Later this week I'll be setting up test cased for my Starter Site project and that'll include logging in as user and admin. I'll be able to tell you then. (https://github.com/andrew13/Laravel-4-Bootstrap-Starter-Site)

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

Try Session::flush(); after the logout and see what happens.

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

@andrew13 Session::flush not working, and I also notice that my session table is empty, does that have anything to do with it?

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

Possibly, your session data table should store your user info while logged in.

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

I think I figured out why, please clarify this is a Laravel bug actually.

  1. when I call logout it goes here: https://github.com/laravel/framework/blob/master/src/Illuminate/Auth/Guard.php#L268 and it sets $this->loggedOut = true;
  2. Notice that in attempt(), it doesn't set loggedOut back to false. https://github.com/laravel/framework/blob/master/src/Illuminate/Auth/Guard.php#L186
  3. when I call Confide::user() which in turn calls user() in Guard.php, it checks whether it's loggedOut if it is, it will return nothing. https://github.com/laravel/framework/blob/master/src/Illuminate/Auth/Guard.php#L101

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

Hmm, interesting. That logic makes sense to me.

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

I have confirmed that adding $this->loggedIn = true after the user is logged in fixes my problem, should I report this?

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

You should add the fix to the repository and create a pull request: https://github.com/laravel/laravel/tree/develop

If you don't want to or don't know how I can for you.

from confide.

hyusetiawan avatar hyusetiawan commented on August 16, 2024

@andrew13 I think I did a pull request (my first time) laravel/framework#692. I will close this issue, thanks for your help andrew13

from confide.

andrew13 avatar andrew13 commented on August 16, 2024

Your welcome and good luck with development!

from confide.

jgamao avatar jgamao commented on August 16, 2024

how to make new confide:migration to make a new table in my database and use it for the signup page in my application?

from confide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.