Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Error when trying to login with a user after configuring module with composer #119

Closed
BrunMartins opened this issue Apr 16, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@BrunMartins
Copy link

BrunMartins commented Apr 16, 2020

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
@stevebauman
Copy link
Member

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?

stevebauman added a commit to DirectoryTree/LdapRecord that referenced this issue Apr 16, 2020
@stevebauman
Copy link
Member

Fixed, release coming shortly, thanks!

@stevebauman stevebauman added the bug Something isn't working label Apr 16, 2020
@BrunMartins
Copy link
Author

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

@stevebauman
Copy link
Member

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! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants