quota = $this->quotaInBytes; } else { $this->quota = intval($quota); } $this->usernameIsEmail = false; $this->connectToLDAPServer(); } protected function createAccount(string $email, string $username, string $password, string $pw2, string $name, int $quota, string $authmail, ?string $referrerCode = null) { $baseDn = getenv('LDAP_USERS_BASE_DN'); $userDn = "username=$username," . $baseDn; $userClusterID = getenv('CLUSTER_ID'); $answer = new \stdClass(); try { $user =[ 'mailAddress' => $email, 'username' => $username, 'usernameWithoutDomain' => $username, 'userPassword' => $password, 'displayName' => $name, 'quota' => $quota, 'mailAlternate' => $authmail, 'recoveryMailAddress' => $authmail, 'active'=> 'TRUE', 'mailActive' => 'TRUE', 'userClusterID' => $userClusterID, 'objectClass' => User::$objectClasses ]; $userEntry = new User($user); $userEntry->setDn($userDn); $userEntry->save(); } catch (Exception $e) { error_log('Error creating user ' . $e->getMessage()); $answer->success= false; $answer->type = 'error_creating_account'; return $answer; } $answer = $this->postCreationActions($email, $username, $authmail, strval($quota), 'v2'); return $answer; } private function getLDAPConfig() : array { $ldapHosts = getenv('LDAP_HOSTS'); $ldapHosts = explode(",", $ldapHosts); $ldapPort = getenv('LDAP_PORT'); $ldapAdminDn = getenv('LDAP_ADMIN_DN'); $ldapAdminPassword = getenv('LDAP_ADMIN_PASSWORD'); $baseDn = getenv('LDAP_USERS_BASE_DN'); return [ 'hosts' => $ldapHosts, 'port' => $ldapPort, 'base_dn' => $baseDn, 'username' => $ldapAdminDn, 'password' => $ldapAdminPassword ]; } private function connectToLDAPServer() : void { $config = $this->getLDAPConfig(); $this->conn = new Connection( $config ); Container::addConnection($this->conn); } }