{"action":"created","issue":{"url":"https://api.github.com/repos/Adldap2/Adldap2/issues/330","repository_url":"https://api.github.com/repos/Adldap2/Adldap2","labels_url":"https://api.github.com/repos/Adldap2/Adldap2/issues/330/labels{/name}","comments_url":"https://api.github.com/repos/Adldap2/Adldap2/issues/330/comments","events_url":"https://api.github.com/repos/Adldap2/Adldap2/issues/330/events","html_url":"https://github.com/Adldap2/Adldap2/issues/330","id":181122427,"number":330,"title":"How to create a user?","user":{"login":"dico","id":4407183,"avatar_url":"https://avatars.githubusercontent.com/u/4407183?v=3","gravatar_id":"","url":"https://api.github.com/users/dico","html_url":"https://github.com/dico","followers_url":"https://api.github.com/users/dico/followers","following_url":"https://api.github.com/users/dico/following{/other_user}","gists_url":"https://api.github.com/users/dico/gists{/gist_id}","starred_url":"https://api.github.com/users/dico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dico/subscriptions","organizations_url":"https://api.github.com/users/dico/orgs","repos_url":"https://api.github.com/users/dico/repos","events_url":"https://api.github.com/users/dico/events{/privacy}","received_events_url":"https://api.github.com/users/dico/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-05T10:56:06Z","updated_at":"2016-10-06T01:08:45Z","closed_at":null,"body":"Hi. I'm trying to create a new user with Adldap2, but i'm struggling a bit. I'm testing with one of the example codes:\r\n\r\n```\r\n$user = $this->provider->make()->user();\r\n\r\n$user->setCommonName('Daisy Duck');\r\n$user->setDisplayName('Daisy Duck');\r\n$user->setFirstName('Daisy');\r\n$user->setLastName('Duck');\r\n$user->setTitle('Girlfriend of Donald Duck');\r\n$user->setDepartment('Andeby');\r\n$user->setInfo('Daisy was introduced in the short film Mr. Duck Steps Out (1940)');\r\n$user->setInitials('DD');\r\n$user->setPhysicalDeliveryOfficeName('Clubhouse office');\r\n$user->setTelephoneNumber('12345678');\r\n$user->setCompany('Mickey Mouse Clubhouse');\r\n$user->setPassword('Monday123');\r\n$user->setStreetAddress('Duckburg 123');\r\n$user->setPostalCode('1234');\r\n\r\n$dn = $user->getDnBuilder();\r\n\r\n$dn->addCn($user->getCommonName());\r\n$dn->addOu('Testusers');\r\n$dn->addDc('login');\r\n$dn->addDc('domain');\r\n$dn->addDc('local');\r\n\r\n// Returns 'cn=John Doe,ou=Accounting,dc=corp,dc=acme,dc=org'\r\necho $dn->get();\r\n\r\n// The DistinguishedName object also contains the __toString() magic method\r\n// so you can also just echo the object itself\r\necho $dn;\r\n$user->setDn($dn);\r\n$user->save();\r\n\r\nif ($user->create()) {\r\n\techo \"User was created\";\r\n} else {\r\n\techo \"Issue creating user\";\r\n}\r\n```\r\n\r\nThis gives me an error in the apache log:\r\n`[Wed Oct 05 12:46:49.598522 2016] [:error] [pid 24344] [client 172.27.10.101:54592] PHP Warning:  ldap_add(): Unknown attribute in the data in /var/www/intranett.dev.mydomain.local/vendor/adldap2/adldap2/src/Connections/Ldap.php on line 261`\r\n\r\nBut it looks like the user is created successfully in AD.\r\n\r\nI also have some other questions like:\r\n- Where do I set the username/logon-name? Is there a doc/list of the attributes, or do I have to browse the source?\r\n- Why is the user disabled when I create the user? Can I set the user as enabled when I create it?\r\n\r\n(Update: Using adldap2 v6.1.8)"},"comment":{"url":"https://api.github.com/repos/Adldap2/Adldap2/issues/comments/251842447","html_url":"https://github.com/Adldap2/Adldap2/issues/330#issuecomment-251842447","issue_url":"https://api.github.com/repos/Adldap2/Adldap2/issues/330","id":251842447,"user":{"login":"stevebauman","id":6421846,"avatar_url":"https://avatars.githubusercontent.com/u/6421846?v=3","gravatar_id":"","url":"https://api.github.com/users/stevebauman","html_url":"https://github.com/stevebauman","followers_url":"https://api.github.com/users/stevebauman/followers","following_url":"https://api.github.com/users/stevebauman/following{/other_user}","gists_url":"https://api.github.com/users/stevebauman/gists{/gist_id}","starred_url":"https://api.github.com/users/stevebauman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevebauman/subscriptions","organizations_url":"https://api.github.com/users/stevebauman/orgs","repos_url":"https://api.github.com/users/stevebauman/repos","events_url":"https://api.github.com/users/stevebauman/events{/privacy}","received_events_url":"https://api.github.com/users/stevebauman/received_events","type":"User","site_admin":false},"created_at":"2016-10-06T01:08:45Z","updated_at":"2016-10-06T01:08:45Z","body":"Hi @dico,\r\n\r\nYou're saving the user, and then creating the user. The save method already performs the create for you. This is mentioned in the docs:\r\n\r\nhttps://github.com/Adldap2/Adldap2/blob/master/docs/models.md#saving\r\n\r\n```php\r\n// You already saved the user here:\r\n$user->save();\r\n\r\nif ($user->create()) { // Now you're creating the user\r\n    echo \"User was created\";\r\n} else {\r\n    echo \"Issue creating user\";\r\n}\r\n```\r\n\r\n> Where do I set the username/logon-name? Is there a doc/list of the attributes, or do I have to browse the source?\r\n\r\nYou're looking for the `setAccountName()` method:\r\n\r\n```php\r\n$user->setAccountName('jdoe');\r\n```\r\n\r\n> Why is the user disabled when I create the user? Can I set the user as enabled when I create it?\r\n\r\nYou need to set the users `userAccountControl`. By default, all users are disabled. This isn't caused by Adldap, this is by default in Active Directory. If you're not sure how to utilize AD's account control, it might be worth a quick google search since there's a lot of options I can't explain here.\r\n\r\nBut here's an example of enabling a user using an [AccountControl](https://github.com/Adldap2/Adldap2/blob/master/src/Objects/AccountControl.php) object:\r\n\r\n```php\r\n$ac= new \\Adldap\\Objects\\AccountControl();\r\n\r\n$ac->accountIsNormal();\r\n\r\n$user->setUserAccountControl($ac);\r\n```"}}
{"actor":{"display_login":"stevebauman"}}