Adldap2 / Adldap2-Laravel

LDAP Authentication & Management for Laravel
MIT License
910 stars 184 forks source link

Duplicate Key #164

Closed warlord0 closed 8 years ago

warlord0 commented 8 years ago

As I'm using spatie/laravel-permission I can't remove the column email so I've simply followed the quick-smart.md with the exception of adding a new column username rather than removing/renaming the email column. Using the following migration:

    public function up()
    {
        Schema::table('users', function (Blueprint $table) {           
            $table->dropUnique('users_email_unique');
            $table->string('username', 50)->unique()->after('name');

        });
    }

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {           
            $table->dropUnique('users_username_unique');
            $table->dropColumn('username');
            $table->unique('email');

        });
    }

Now I manage to authenticate and it logs me in, as if the user doesn't exist it gets created and I can continue. But the next time I logon it fails at updating the table. with:

Integrity constraint violation: 1062 Duplicate entry 'warlord' for key 'users_username_unique' (SQL: insert into users (username, password, email, name, updated_at, created_at) values (warlord, XXXXXXXXXXXXXXXXXXXXXXXX warlord@donk.uk, warlord, 2016-09-01 07:31:51, 2016-09-01 07:31:51))

adldap_auth.php

'username_attribute' => ['username' => 'samaccountname'],
'sync_attributes' => [
    'email' => 'mail',
    'username' => 'samaccountname',
    'name' => 'samaccountname',
],
'select_attributes' => [
    'samaccountname',
    'mail'
],
stevebauman commented 8 years ago

Hi @warlord0, this is strange.

It seems like your pre-existing model isn't being located during authentication, so a new model is created.

Can you try editing the source file here:

https://github.com/Adldap2/Adldap2-Laravel/blob/master/src/Traits/ImportsUsers.php#L41-L42

And right after the highlighted lines, add dd($model); and post the result?

warlord0 commented 8 years ago

Hmm, well that simply returned null so I added a couple more:

dd($key, $username, $model);

and got back:

"username"

null

null
warlord0 commented 8 years ago

Been playing some more. No idea what I did wrong, but moved onto a Laravel 5.3 project did the same things required and it worked. :o