Skip to content
Snippets Groups Projects
Commit fb9387a5 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #848 from greezybacon/feature/ldap-auto-register


ldap: Attempt auto client registration for all backends

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents e54259e0 15df0d97
No related branches found
No related tags found
No related merge requests found
......@@ -86,6 +86,34 @@ class ClientCreateRequest {
function getInfo() {
return $this->info;
}
function attemptAutoRegister() {
global $cfg;
if (!$cfg)
return false;
// Attempt to automatically register
$this_form = UserForm::getUserForm()->getForm($this->getInfo());
$bk = $this->getBackend();
$defaults = array(
'timezone_id' => $cfg->getDefaultTimezoneId(),
'dst' => $cfg->observeDaylightSaving(),
'username' => $this->getUsername(),
);
if ($bk->supportsInteractiveAuthentication())
// User can only be authenticated against this backend
$defaults['backend'] = $bk::$id;
if ($this_form->isValid(function($f) { return !$f->get('private'); })
&& ($U = User::fromVars($this_form->getClean()))
&& ($acct = ClientAccount::createForUser($U, $defaults))
// Confirm and save the account
&& $acct->confirm()
// Login, since `tickets.php` will not attempt SSO
&& ($cl = new ClientSession(new EndUser($U)))
&& ($bk->login($cl, $bk)))
return $cl;
}
}
/**
......
......@@ -38,6 +38,11 @@ if ($_POST && isset($_POST['luser'])) {
$_POST['lpasswd'], $errors))) {
if ($user instanceof ClientCreateRequest) {
if ($cfg && $cfg->isClientRegistrationEnabled()) {
// Attempt to automatically register
if ($user->attemptAutoRegister())
Http::redirect('tickets.php');
// Auto-registration failed. Show the user the info we have
$inc = 'register.inc.php';
$user_form = UserForm::getUserForm()->getForm($user->getInfo());
}
......@@ -87,23 +92,7 @@ elseif ($user = UserAuthenticationBackend::processSignOn($errors, false)) {
elseif ($user instanceof ClientCreateRequest) {
if ($cfg && $cfg->isClientRegistrationEnabled()) {
// Attempt to automatically register
$user_form = UserForm::getUserForm()->getForm($user->getInfo());
$bk = $user->getBackend();
$defaults = array(
'timezone_id' => $cfg->getDefaultTimezoneId(),
'dst' => $cfg->observeDaylightSaving(),
'username' => $user->getUsername(),
);
if ($bk->supportsInteractiveAuthentication())
$defaults['backend'] = $bk::$id;
if ($user_form->isValid(function($f) { return !$f->get('private'); })
&& ($U = User::fromVars($user_form->getClean()))
&& ($acct = ClientAccount::createForUser($U, $defaults))
// Confirm and save the account
&& $acct->confirm()
// Login, since `tickets.php` will not attempt SSO
&& ($cl = new ClientSession(new EndUser($U)))
&& ($bk->login($cl, $bk)))
if ($user->attemptAutoRegister())
Http::redirect('tickets.php');
// Unable to auto-register. Fill in what we have and let the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment