Coder Social home page Coder Social logo

Comments (10)

brunogaspar avatar brunogaspar commented on May 18, 2024

Is your ApplicationServiceProvider being added after the Sentinel service provider?

I did a quick test and the hasher i set seems to be set properly before and after i try to log a user in via login or authenticate methods.

from sentinel.

spaceemotion avatar spaceemotion commented on May 18, 2024

Yes, my service provider is after the SentinelServiceProvider:

    'providers' => array(
        // ...

        /*
         * Additional providers
         */
        'Cartalyst\Sentinel\Laravel\SentinelServiceProvider',
        'Barryvdh\Debugbar\ServiceProvider',

        /*
         * Application Service Providers
         */
        'Appp\Providers\AppServiceProvider', //<-- that one

    ),

My boot method currently looks like this (using dd to check if it reaches that code):

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        Sentinel::setHasher(new CallbackHasher(
            function($value)
            {
                return Hash::make($value);
            },

            function($value, $hashedValue)
            {
                dd([$value, $hashedValue]);
            }
        ));
    }

from sentinel.

suwardany avatar suwardany commented on May 18, 2024

Seems to be working fine here using your exact same setup, and it does dump on authenticate

from sentinel.

spaceemotion avatar spaceemotion commented on May 18, 2024

This is my controller's method code; maybe I am doing something wrong here even:

    public function postLogin(Request $request)
    {
        $credentials = $request->only('email', 'password');

        try {
            // Authenticate with our credentials, if it succeeds continue to the home screen
            if (Sentinel::authenticate($credentials, $request->has('remember'))) {
                return redirect()->intended(route('home'));
            }

        } catch(NotActivatedException $ex) {
            return redirect('/auth/activate');
        }

        // ... otherwise return to the login page
        return redirect('/auth/login')
            ->withInput($request->only('email', 'remember'))
            ->withErrors([
                'email' => 'Invalid credentials / No user found',
            ]);
    }

I am also wondering why the system would let me log in with an email, but not with a username. I already changed the Users $loginNames to ['email', 'username'];. Very strange…

from sentinel.

suwardany avatar suwardany commented on May 18, 2024

Copied that over and defined the route and it's working as well.

image

from sentinel.

spaceemotion avatar spaceemotion commented on May 18, 2024

Okay, so I did some more testing and it seems like the closure for the "sentinel.hasher" in the SentinelServiceProvider gets definitely called before my Sentinel::setHasher() method. But when I do a dd in my controller method it somehow was set to the NativeHasher once again.

I just tried to move the setHasher method to my register() function in the ServiceProvider and that time the Sentinel one was called after my custom one (I haven't changed the order of my providers).

Digging further I found out that the SentinelBootstrapper gets executed after my service provider, and creates a sentinel instance with the default hasher.

Is there a way to work around this? It really is weird that it seems to work on the setup everyone else but mine.

from sentinel.

suwardany avatar suwardany commented on May 18, 2024

@spaceemotion are you using the correct alias?

from sentinel.

suwardany avatar suwardany commented on May 18, 2024

The SentinelBootstrapper is only triggered by the Native facade, apparently that is being used on your application which is wrong.

Laravel applications should be using the Laravel facade, Cartalyst\Sentinel\Laravel\Facades\Sentinel

from sentinel.

spaceemotion avatar spaceemotion commented on May 18, 2024

Oh crap, didn't think about that. Yes I indeed used the 'Native' one, well - thanks for the hint!

That still doesn't fix the username issue. Logging in through an email works, but when using a username the system still gives off an error (as explained above). I checked the query object that gets executed and it seems like Sentinel tries to get an email with the given username. Is there a way to decide which field to use on which occasion (if the name contains '@', then use 'email', otherwise 'username')?

from sentinel.

suwardany avatar suwardany commented on May 18, 2024

You can pass in login instead of explicitly stating email or username, that will work for both fields if they're defined on the loginNames array.

from sentinel.

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.