Ldaprecord-laravel: Type Error when trying to login with a user after configuring module with composer

Created on 16 Apr 2020  路  4Comments  路  Source: DirectoryTree/LdapRecord-Laravel

Describe the bug
This is possibly an isolated issue.

Earlier today I tried to configure LdapRecord-Laravel.
As soon as I tried to login with a user a TypeError exception was thrown with the following text:
_Argument 1 passed to LdapRecord\Models\Model::serializeDate() must implement interface DateTimeInterface, null given, called in C:\Users\bruno.martins\source\repos\outono\vendor\directorytree\ldaprecord\src\Models\Concerns\HasAttributes.php on line 105_

Se screenshot below
image

To fix this I dug arround a bit and found that some of the user attributes, like _'lockouttime'_ and _'lastlogoff_ were set to "0", and when put throught the _$this->asDateTime()_ were being returned as null.

Following my discovery I added a simple check, see below:

No fix:

protected function addDateAttributesToArray(array $attributes)
    {
        foreach ($this->getDates() as $attribute => $type) {
            if (!isset($attributes[$attribute]) || $attributes[$attribute] === 0) {
                continue;
            }

            $date = $this->serializeDate(
                $this->asDateTime($type, $attributes[$attribute])
            );

            $attributes[$attribute] = Arr::wrap($date);
        }

        return $attributes;
    }

Fix:

protected function addDateAttributesToArray(array $attributes)
    {
        foreach ($this->getDates() as $attribute => $type) {

            if (!isset($attributes[$attribute])) {
                continue;
            }

            $attributeAsDateTime = $this->asDateTime($type, $attributes[$attribute]);

            if ($attributeAsDateTime === null) {
                continue;
            }

            $date = $this->serializeDate(
                $attributeAsDateTime
            );

            $attributes[$attribute] = Arr::wrap($date);
        }

        return $attributes;
    }

After this, I could login with a user and use the app, again, I do not know if this is an isolated issue or not, If it's not, I am more than happy to file a merge request and tweak the code for a fix.

Thanks!

To Reproduce
Steps to reproduce the behavior:

  1. Create a new laravel project
  2. Add this module
  3. Configure according to the configuration documentation
  4. Try Logging in

Expected behavior
The user is logged in and created in the database

Environment (please complete the following information):

  • LDAP Server Type: ActiveDirectory
  • PHP Version: 7.4
  • Laravel Version: 7.x
bug

All 4 comments

Hi @BrunMartins, this was just reported here as well: #117

I'm fixing this now -- however I'm trying to determine what timestamp values you both may have for the whencreated and whenchanged LDAP properties which is causing the failure of conversion?

Fixed, release coming shortly, thanks!

Sorry, I only saw your email a moment ago, glad it is fixed!

No worries @BrunMartins! @brinkonaut supplied me with the value I needed to determine the cause. Appreciate the reply!

I'm creating a new release in a couple minutes -- run composer update and you'll be good to go! 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jagDanJu picture jagDanJu  路  8Comments

murrant picture murrant  路  5Comments

kruiz122893 picture kruiz122893  路  5Comments

siegherr picture siegherr  路  6Comments

abiffe picture abiffe  路  3Comments